refactor(chalice): optimised forget password
This commit is contained in:
parent
7878f10a8b
commit
4922adf5c9
2 changed files with 13 additions and 6 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import logging
|
||||
|
||||
from fastapi import BackgroundTasks
|
||||
|
||||
import schemas
|
||||
from chalicelib.core import users
|
||||
from chalicelib.utils import email_helper, captcha, helper, smtp
|
||||
|
|
@ -7,7 +9,7 @@ from chalicelib.utils import email_helper, captcha, helper, smtp
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def reset(data: schemas.ForgetPasswordPayloadSchema):
|
||||
def reset(data: schemas.ForgetPasswordPayloadSchema, background_tasks: BackgroundTasks):
|
||||
logger.info(f"forget password request for: {data.email}")
|
||||
if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response):
|
||||
return {"errors": ["Invalid captcha."]}
|
||||
|
|
@ -16,7 +18,9 @@ def reset(data: schemas.ForgetPasswordPayloadSchema):
|
|||
a_users = users.get_by_email_only(data.email)
|
||||
if a_users:
|
||||
invitation_link = users.generate_new_invitation(user_id=a_users["userId"])
|
||||
email_helper.send_forgot_password(recipient=data.email, invitation_link=invitation_link)
|
||||
background_tasks.add_task(email_helper.send_forgot_password,
|
||||
recipient=data.email,
|
||||
invitation_link=invitation_link)
|
||||
else:
|
||||
logger.warning(f"!!!invalid email address [{data.email}]")
|
||||
return {"data": {"state": "A reset link will be sent if this email exists in our system."}}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Union
|
||||
|
||||
from decouple import config
|
||||
from fastapi import Depends, Body
|
||||
from fastapi import Depends, Body, BackgroundTasks
|
||||
|
||||
import schemas
|
||||
from chalicelib.core import log_tool_rollbar, sourcemaps, events, sessions_assignments, projects, \
|
||||
|
|
@ -448,7 +448,7 @@ def edit_gdpr(projectId: int, data: schemas.GdprSchema = Body(...),
|
|||
|
||||
|
||||
@public_app.post('/password/reset-link', tags=["reset password"])
|
||||
def reset_password_handler(data: schemas.ForgetPasswordPayloadSchema = Body(...)):
|
||||
def reset_password_handler(background_tasks: BackgroundTasks, data: schemas.ForgetPasswordPayloadSchema = Body(...)):
|
||||
if len(data.email) < 5:
|
||||
return {"errors": ["please provide a valid email address"]}
|
||||
return reset_password.reset(data=data)
|
||||
|
|
@ -872,16 +872,19 @@ async def check_recording_status(project_id: int):
|
|||
def health_check():
|
||||
return {}
|
||||
|
||||
|
||||
# tags
|
||||
|
||||
@app.post('/{projectId}/tags', tags=["tags"])
|
||||
def tags_create(projectId: int, data: schemas.TagCreate = Body(), context: schemas.CurrentContext = Depends(OR_context)):
|
||||
def tags_create(projectId: int, data: schemas.TagCreate = Body(),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
data = tags.create_tag(project_id=projectId, data=data)
|
||||
return {'data': data}
|
||||
|
||||
|
||||
@app.put('/{projectId}/tags/{tagId}', tags=["tags"])
|
||||
def tags_update(projectId: int, tagId: int, data: schemas.TagUpdate = Body(), context: schemas.CurrentContext = Depends(OR_context)):
|
||||
def tags_update(projectId: int, tagId: int, data: schemas.TagUpdate = Body(),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
data = tags.update_tag(project_id=projectId, tag_id=tagId, data=data)
|
||||
return {'data': data}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue