def change_password(username, email, activation_code, password, email_to_file=None, send=True):
if not find_user2(username=username, email=email):
return [None, USER_NOT_FOUND_WITH_EMAIL_MSG]
user = Users.objects.get(username=username, email=email, is_active=1)
if user.activation_code != activation_code:
logging.warning("Invalid activation code: {}".format(activation_code))
return [None, "Password has already been reset"]
user.password = crypt.crypt(password, user.salt)
user.activation_code = None
user.save()
if send:
text = "Your varapp password has changed. " + \
"Please use the new login information below:" + \
"\n\n\tLogin: {}\n\tPassword: {}\n\n".format(username, password)
html = "<p>Your varapp password changed. " + \
"Please use the new login information below:</p>" + \
"<table><tr><td>Login:</td><td>{}</td></tr>".format(username) + \
"<tr><td>Password:</td><td>{}</td></tr></table>".format(password)
send_email(email, "Password reset", text=text, html=html, tofile=email_to_file)
return [user, '']
评论列表
文章目录