async def send_confirmation_link(mail: str): """ Sends a link to the user's mail id for account verification :param mail: the mail id of the user :return: mail id, mail subject and mail body """ email_enabled = Utility.email_conf["email"]["enable"] if email_enabled: if isinstance(mail_check(mail), ValidationFailure): raise AppException("Please enter valid email id") Utility.is_exist(UserEmailConfirmation, exp_message="Email already confirmed!", email__iexact=mail.strip()) if not Utility.is_exist(User, email__iexact=mail.strip(), status=True, raise_error=False): raise AppException( "Error! There is no user with the following mail id") user = AccountProcessor.get_user(mail) token = Utility.generate_token(mail) link = Utility.email_conf["app"]["url"] + '/verify/' + token return mail, user['first_name'], link else: raise AppException("Error! Email verification is not enabled")
async def send_confirmation_link(mail: str): """ Sends a link to the user's mail id for account verification :param mail: the mail id of the user :return: mail id, mail subject and mail body """ if AccountProcessor.EMAIL_ENABLED: if isinstance(mail_check(mail), ValidationFailure): raise AppException("Please enter valid email id") Utility.is_exist(UserEmailConfirmation, exp_message="Email already confirmed!", email__iexact=mail.strip()) if not Utility.is_exist( User, email__iexact=mail.strip(), raise_error=False): raise AppException( "Error! There is no user with the following mail id") token = Utility.generate_token(mail) link = Utility.email_conf["app"]["url"] + '/verify/' + token body = Utility.email_conf['email']['templates'][ 'confirmation_body'] + link subject = Utility.email_conf['email']['templates'][ 'confirmation_subject'] return mail, subject, body else: raise AppException("Error! Email verification is not enabled")
def check_config(raw_config): '''''' phone_regex = re.compile(r'^\+79[0-9]{9}$|^89[0-9]{9}$') if raw_config.interact: raw_config.name = input('Имя пользователя: ') while not re.findall(phone_regex, str(raw_config.phone)): raw_config.phone = input('Номер телефона в формате' '+79XXXXXXXXX или 89XXXXXXXXX: ') while not mail_check(raw_config.mail): raw_config.mail = input('Адрес электронной почты: ') elif not (raw_config.name and raw_config.phone and raw_config.mail): print('RTMF!!!') raise SystemExit(1) else: config = raw_config return config
async def validate_and_send_mail(email: str, subject: str, body: str): """ Used to validate the parameters of the mail to be sent :param email: email id of the recipient :param subject: subject of the mail :param body: body or message of the mail :return: None """ if isinstance(mail_check(email), ValidationFailure): raise AppException("Please check if email is valid") if (Utility.check_empty_string(subject) or Utility.check_empty_string(body)): raise ValidationError( "Subject and body of the mail cannot be empty or blank space") await Utility.trigger_smtp(email, subject, body)
async def send_reset_link(mail: str): """ Sends a password reset link to the mail id :param mail: email id of the user :return: mail id, mail subject, mail body """ email_enabled = Utility.email_conf["email"]["enable"] if email_enabled: mail = mail.strip() if isinstance(mail_check(mail), ValidationFailure): raise AppException("Please enter valid email id") if not Utility.is_exist( User, email__iexact=mail, status=True, raise_error=False): raise AppException( "Error! There is no user with the following mail id") if not Utility.is_exist(UserEmailConfirmation, email__iexact=mail, raise_error=False): raise AppException( "Error! The following user's mail is not verified") UserActivityLogger.is_password_reset_within_cooldown_period(mail) UserActivityLogger.is_password_reset_request_limit_exceeded(mail) token_expiry = Utility.environment['user'][ 'reset_password_cooldown_period'] or 120 token = Utility.generate_token(mail, token_expiry * 60) user = AccountProcessor.get_user(mail) link = Utility.email_conf["app"]["url"] + '/reset_password/' + token UserActivityLogger.add_log( account=user['account'], email=mail, a_type=UserActivityType.reset_password_request.value) return mail, user['first_name'], link else: raise AppException("Error! Email verification is not enabled")