Beispiel #1
0
def forget_passwd():
    error = Error(0, '人生需要目标,有了目标才有奋斗的方向!')
    forget_info = request.json
    email = forget_info.get('email')
    passwd = forget_info.get('password')
    verify = forget_info.get('verify')
    if not (email and verify):
        error.err_code = 9
        error.err_msg = "参数为空"
        return error.make_json_response()
    user = User.get_user_by_email(email)
    if user is None:
        error.err_code = 9
        error.err_msg = '该邮箱填写错误'
    new_veri_code = redis_client.get(email)
    if new_veri_code is None:
        error.err_code = 9
        error.err_msg = '请获取邮箱验证码'
        return error.make_json_response()
    if str(new_veri_code, encoding='utf-8') != str(verify):
        error.err_code = 9
        error.err_msg = '该验证码错误,请尝试重新获取'
        return error.make_json_response()
    passwd = render_password(passwd)
    acc = {'password': passwd}
    add_status = User.update_user(user.id, acc)
    if add_status:
        return error.make_json_response()
    else:
        error.err_code = 0
        error.err_msg = "修改成功"
        return error.make_json_response()
Beispiel #2
0
def account_login():
    if request.method == 'POST':
        json_info = request.json
        email = json_info.get('email')
        password = json_info.get("password")
        if not email or not password:
            return jsonify({"error": 1, "msg": "用户名或密码为空"})

        if type(User.check(email, password)) is str:
            return jsonify({"error": 1, "msg": "用户名或密码错误"})
        else:
            user = User.get_user_by_email(email)
            if user.status == 0 or user.status == '0':
                return jsonify({"error": 2, "msg": "该用户未激活,请联系管理员"})
            from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
            s = Serializer(b'flag_nb_no_1')
            token = s.dumps({'id': str(user.id)})
            redis_client.set(token, user.id, ex=24 * 3600)
            return jsonify({
                "error": 0,
                "msg": "登陆成功",
                "token": str(token, 'utf-8')
            })