def send_verification_email(user): try: result = EmailVerification.objects.get(user = user) if result.is_not_expired_email_verification(): #if verification code is not expired, send the same code result.sent_datetime = timezone.now() #reset the time result.save() verification_code = result.verification_code else: #if expired, delete the previous code result.delete() raise Exception except Exception: verification_code = ran.rand_alphanumeric() email_ver_storage = EmailVerification.objects.create(user=user, verification_code = verification_code) email_msg = ac_msg.registration_email_verfication email_msg += "http://127.0.0.1:8000" + reverse('accounts:verify', kwargs= {'verification_code' : verification_code, 'username' : user.username}) send_mail('Verify your email', email_msg, settings_sensitive.EMAIL_HOST_USER, [user.email], fail_silently=True)
def send_forgot_password_verification_email(user): try: result = ForgotPasswordVerification.objects.get(user = user) if result.is_not_expired_forgot_password(): #if verification code is not expired, send the same code result.sent_datetime = timezone.now() #reset the time result.save() verification_code = result.verification_code else: #if expired, delete the previous code result.delete() raise Exception except Exception: verification_code = ran.rand_alphanumeric() forgot_password_ver_storage = ForgotPasswordVerification.objects.create(user=user, verification_code = verification_code) email_msg = ac_msg.forgot_password_message email_msg += "http://127.0.0.1:8000" + reverse('accounts:forget_password_check')+ "?verification_code=" + verification_code + '&username='******'Reset Password', email_msg, settings_sensitive.EMAIL_HOST_USER, [user.email], fail_silently=True)