account_views.py 文件源码

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

项目:fantasy-dota-heroes 作者: ThePianoDentist 项目源码 文件源码
def change_password(request):
    session = DBSession()
    user_id = authenticated_userid(request)
    new_password = request.params.get('new_password')
    confirm_new_password = request.params.get('confirm_new_password')
    old_password = request.params.get('old_password')
    user = session.query(User).filter(User.id == user_id).first()
    if not user:
        params = {"message": "Your username could not be found",
                  "message_type": "change_password"}
        return HTTPFound(location=request.route_url('account_settings', _query=params))

    if not user.validate_password(old_password):
        params = {"message": "Old password did not match",
                  "message_type": "change_password"}
        return HTTPFound(location=request.route_url('account_settings', _query=params))

    if old_password == "":  # this is the case for steam accounts
        params = {"message": "Change password does not apply to steam logins",
                  "message_type": "failure"}
        return HTTPFound(location=request.route_url('account_settings', _query=params))

    pword_invalid_check = check_invalid_password(new_password, confirm_new_password)
    if pword_invalid_check:
        return HTTPFound(location=request.route_url('account_settings', _query=pword_invalid_check))

    session.query(User).filter(User.id == user_id).update({User.password: bcrypt.encrypt(new_password)})
    params = {"message": "Congratulations! Password successfully changed",
                  "message_type": "success"}
    return HTTPFound(location=request.route_url('account_settings', _query=params))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号