auth.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:varapp-backend-py 作者: varapp 项目源码 文件源码
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, '']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号