Пример #1
0
 def verify_auth_token(token):
     s = Serializer(app.config['SECRET_KEY'])
     try:
         data = s.loads(token)
     except SignatureExpired:
         return None  # valid token, but expired
     except BadSignature:
         return None  # invalid token
     user = UserBusiness.find_user_by_id(data['id'])
     return user
Пример #2
0
 def find_role_by_user_id(cls, user_id):
     user = UserBusiness.find_user_by_id(user_id)
     if user is not None:
         for role in user.roles:
             yield role
     pass
Пример #3
0
    # blacklist.add(jti)
    resp = jsonify({'logout': True})
    unset_jwt_cookies(resp)
    
    return resp, 200


@app.route('/api/user/<int:id>')
@jwt_required
def get_user(id):
    """
    :获取用户信息
    :param id: 用户id
    :return: json
    """
    user = UserBusiness.find_user_by_id(id)
    roles = []
    for i in user.roles:
        print(str(i))
        # roles += str(i)
        roles.append(i.name)
        
    group = []
    for j in user.group:
        group.append(j.name)
    
    if not user:
        abort(404)
    # return '<h1> Hello,%s </h1><h1>Role:  Group</h1>' % user.name + roles
    return jsonify(
        {'username': user.name, 'phone': user.phone, 'email': user.email,
Пример #4
0
# 查询所有用户列表
users = xxx.find_all_users()
if users is not None:
    for user in users:
        print(user)

# 通过用户id 来进行删除 (√)
# user = xxx.delete_user_by_id(18)
# print user

# 密码的更新,总提示参数不对。
# xxx.update_pwd(name='Brand',pwd=m.update('123'))

# 输出根据id 去查询用户信息
print('start\n')
user5 = xxx.find_user_by_id(1)
print('user - id ==5:', user5)

users = xxx.search_user_by_info('Brank', '1762388223')
for user in users:
    print(user)
# 提交即保存到数据库:
db.session.commit()

# 测试用法
# 创建Query查询,filter是where条件,最后调用one()返回唯一行,如果调用all()则返回所有行:
# role = db.session.query(Role).filter(Role.id=='5').one()
# 打印类型和对象的name属性:
# print 'type:', type(role)
# print 'role——name:', role.name
# print role