|
@@ -11,6 +11,7 @@ import uuid
|
|
from apps.web.models.auths import (
|
|
from apps.web.models.auths import (
|
|
SigninForm,
|
|
SigninForm,
|
|
SignupForm,
|
|
SignupForm,
|
|
|
|
+ ProfileImageUrlForm,
|
|
UpdatePasswordForm,
|
|
UpdatePasswordForm,
|
|
UserResponse,
|
|
UserResponse,
|
|
SigninResponse,
|
|
SigninResponse,
|
|
@@ -40,14 +41,36 @@ async def get_session_user(user=Depends(get_current_user)):
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+############################
|
|
|
|
+# Update Profile Image Url
|
|
|
|
+############################
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@router.post("/update/profile", response_model=UserResponse)
|
|
|
|
+async def update_profile_image_url(
|
|
|
|
+ form_data: ProfileImageUrlForm, session_user=Depends(get_current_user)
|
|
|
|
+):
|
|
|
|
+ if session_user:
|
|
|
|
+ user = Users.update_user_profile_image_url_by_id(
|
|
|
|
+ session_user.id, form_data.profile_image_url
|
|
|
|
+ )
|
|
|
|
+ if user:
|
|
|
|
+ return user
|
|
|
|
+ else:
|
|
|
|
+ raise HTTPException(400, detail=ERROR_MESSAGES.DEFAULT())
|
|
|
|
+ else:
|
|
|
|
+ raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
|
|
|
+
|
|
|
|
+
|
|
############################
|
|
############################
|
|
# Update Password
|
|
# Update Password
|
|
############################
|
|
############################
|
|
|
|
|
|
|
|
|
|
@router.post("/update/password", response_model=bool)
|
|
@router.post("/update/password", response_model=bool)
|
|
-async def update_password(form_data: UpdatePasswordForm,
|
|
|
|
- session_user=Depends(get_current_user)):
|
|
|
|
|
|
+async def update_password(
|
|
|
|
+ form_data: UpdatePasswordForm, session_user=Depends(get_current_user)
|
|
|
|
+):
|
|
if session_user:
|
|
if session_user:
|
|
user = Auths.authenticate_user(session_user.email, form_data.password)
|
|
user = Auths.authenticate_user(session_user.email, form_data.password)
|
|
|
|
|
|
@@ -93,18 +116,19 @@ async def signin(form_data: SigninForm):
|
|
async def signup(request: Request, form_data: SignupForm):
|
|
async def signup(request: Request, form_data: SignupForm):
|
|
if not request.app.state.ENABLE_SIGNUP:
|
|
if not request.app.state.ENABLE_SIGNUP:
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
|
-
|
|
|
|
|
|
+
|
|
if not validate_email_format(form_data.email.lower()):
|
|
if not validate_email_format(form_data.email.lower()):
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_EMAIL_FORMAT)
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_EMAIL_FORMAT)
|
|
-
|
|
|
|
|
|
+
|
|
if Users.get_user_by_email(form_data.email.lower()):
|
|
if Users.get_user_by_email(form_data.email.lower()):
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.EMAIL_TAKEN)
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.EMAIL_TAKEN)
|
|
-
|
|
|
|
|
|
+
|
|
try:
|
|
try:
|
|
role = "admin" if Users.get_num_users() == 0 else "pending"
|
|
role = "admin" if Users.get_num_users() == 0 else "pending"
|
|
hashed = get_password_hash(form_data.password)
|
|
hashed = get_password_hash(form_data.password)
|
|
- user = Auths.insert_new_auth(form_data.email.lower(),
|
|
|
|
- hashed, form_data.name, role)
|
|
|
|
|
|
+ user = Auths.insert_new_auth(
|
|
|
|
+ form_data.email.lower(), hashed, form_data.name, role
|
|
|
|
+ )
|
|
|
|
|
|
if user:
|
|
if user:
|
|
token = create_token(data={"email": user.email})
|
|
token = create_token(data={"email": user.email})
|
|
@@ -120,11 +144,10 @@ async def signup(request: Request, form_data: SignupForm):
|
|
"profile_image_url": user.profile_image_url,
|
|
"profile_image_url": user.profile_image_url,
|
|
}
|
|
}
|
|
else:
|
|
else:
|
|
- raise HTTPException(
|
|
|
|
- 500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
|
|
|
|
|
|
+ raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR)
|
|
except Exception as err:
|
|
except Exception as err:
|
|
- raise HTTPException(500,
|
|
|
|
- detail=ERROR_MESSAGES.DEFAULT(err))
|
|
|
|
|
|
+ raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err))
|
|
|
|
+
|
|
|
|
|
|
############################
|
|
############################
|
|
# ToggleSignUp
|
|
# ToggleSignUp
|