Exemplo n.º 1
0
def get_token():
    '''获取一个口令,用于保持登陆'''
    params = request.get_json()
    return jsonify(
        IdentifyUtil.authenticate(
            params.get('username'),
            IdentifyUtil.hash_secret(params.get('password'))))
Exemplo n.º 2
0
 def updateUserBase(userid,username,password):
     if not blogDB.getUserById(userid):
         return Common.falseReturn(None, "{} doesn't exist in user_base".format(userid))
     if not username or not password:
         return Common.falseReturn(None, 'username or password cannot be empty')
     if blogDB.updateUser(userid,username,IdentifyUtil.hash_secret(password)):
         return Common.trueReturn({'userid':userid},'change ok')
     else:
         return Common.falseReturn(None,'change false')
Exemplo n.º 3
0
 def registerUserBase(username,password):
     if not username or not password:
         return Common.falseReturn(None, 'username or password cannot be empty')
     if blogDB.getUserByName(username) is not None:
         return Common.falseReturn(None,'{} is already exists'.format(username))
     userid = blogDB.addUser(username, IdentifyUtil.hash_secret(password))
     if userid is not None:
         return Common.trueReturn({'userid':userid},'register ok')
     else :
         return Common.falseReturn('unknown reason','register wrong')
Exemplo n.º 4
0
def change_userpassword():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'user not find'))
    params = request.get_json()
    if not params.get('oldpassword') or not params.get('newpassword'):
        return jsonify(
            Common.falseReturn(None,
                               'newpassword or oldpassword cannot be empty'))
    user = UserApi.getUserBase(userid)
    if user['status'] and user['data'].get(
            'password') == IdentifyUtil.hash_secret(params.get('oldpassword')):
        return jsonify(
            UserApi.updateUserPassword(userid, params.get('newpassword')))
    return jsonify(Common.falseReturn(None, 'check old password wrong'))
Exemplo n.º 5
0
 def updateUserPassword(userid,password):
     if blogDB.updateUserPassword(userid,IdentifyUtil.hash_secret(password)):
         return Common.trueReturn(userid,'change password ok')
     return Common.falseReturn(None,"change password error")