def update_user_details(user_id: int, user_dto: UserDTO) -> dict: """ Update user with info supplied by user, if they add or change their email address a verification mail will be sent """ user = UserService.get_user_by_id(user_id) verification_email_sent = False if ( user_dto.email_address and user.email_address != user_dto.email_address.lower() ): # Send user verification email if they are adding or changing their email address SMTPService.send_verification_email( user_dto.email_address.lower(), user.username ) user.set_email_verified_status(is_verified=False) verification_email_sent = True user.update(user_dto) user_email = UserEmail.query.filter( UserEmail.email == user_dto.email_address ).one_or_none() if user_email is not None: user_email.delete() return dict(verificationEmailSent=verification_email_sent)
def test_send_verification_mail(self): if os.getenv("TM_SMTP_HOST") is None: return # If SMTP not setup there's no value attempting the integration tests self.assertTrue( SMTPService.send_verification_email("*****@*****.**", "mrtest"))
def resend_email_validation(user_id: int): """ Resends the email validation email to the logged in user """ user = UserService.get_user_by_id(user_id) SMTPService.send_verification_email(user.email_address, user.username)