def form_valid(self, form):
user = User.objects.filter(email=self.request.POST.get('email'))
if user:
user = user[0]
subject = "Password Reset"
password = get_random_string(6)
message = '<p>Your Password for the forum account is <strong>'+password + \
'</strong></p><br/><p>Use this credentials to login into <a href="' + \
settings.HOST_URL + '/forum/">forum</a></p>'
to = user.email
from_email = settings.DEFAULT_FROM_EMAIL
Memail([to], from_email, subject, message, email_template_name=None, context=None)
user.set_password(password)
user.save()
data = {
"error": False, "response": "An Email is sent to the entered email id"}
return JsonResponse(data)
else:
data = {
"error": True, "message": "User With this email id doesn't exists!!!"}
return JsonResponse(data)
评论列表
文章目录