Coverage for chalicelib/core/reset_password.py: 56%

19 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 12:56 +0000

1import logging 

2 

3from fastapi import BackgroundTasks 

4 

5import schemas 

6from chalicelib.core import users 

7from chalicelib.utils import email_helper, captcha, helper, smtp 

8from chalicelib.utils.log import sanitize 

9 

10logger = logging.getLogger(__name__) 

11 

12 

13def reset(data: schemas.ForgetPasswordPayloadSchema, background_tasks: BackgroundTasks): 

14 logger.info(f"forget password request for: {sanitize(data.email)}") 

15 if helper.allow_captcha() and not captcha.is_valid(data.g_recaptcha_response): 15 ↛ 16line 15 didn't jump to line 16 because the condition on line 15 was never true

16 return {"errors": ["Invalid captcha."]} 

17 if not smtp.has_smtp(): 17 ↛ 19line 17 didn't jump to line 19 because the condition on line 17 was always true

18 return {"errors": ["Email delivery failed due to invalid SMTP configuration. Please contact your admin."]} 

19 a_user = users.get_by_email_only(data.email) 

20 if a_user: 

21 invitation_link = users.generate_new_invitation(user_id=a_user["userId"]) 

22 background_tasks.add_task(email_helper.send_forgot_password, 

23 recipient=data.email, 

24 invitation_link=invitation_link) 

25 else: 

26 logger.warning(f"!!!invalid email address [{sanitize(data.email)}]") 

27 return {"data": {"state": "A reset link will be sent if this email exists in our system."}}