def get_verification_code(request):
"""API get_verification_code"""
email = request.POST.get('email')
if User.objects.filter(email__iexact=email).exists():
msg = _('E-mail exists. Why don\'t you try to find your password?')
data = {
'result': False,
'msg': msg,
}
return JsonResponse(data, status=201)
signer = TimestampSigner()
value = signer.sign(email)
subject = _('[%(site_name)s] Verification code for signing in') % {
'site_name': settings.SITE_NAME
}
body = value
try:
send_mail(subject, body, settings.EMAIL_HOST_USER, [email], fail_silently=False)
msg = _('Verification code sent. Please check your E-mail.')
data = {
'result': True,
'msg': msg,
}
return JsonResponse(data, status=201)
except SMTPException:
return JsonResponse({'status': 'false'}, status=400)
评论列表
文章目录