Ejemplo n.º 1
0
def userInfo():
    """
    向客户端返回用户权限信息
    :return:
    """
    if 'current_user_proxy' in session:
        up = session['current_user_proxy']
        if up:
            h = UserHandler()
            a = h.getUserAvatarByCode(up.user_code)
            return packageResponse({'data':{'roles':[e.role_code for e in up.roles], 'name':up.user_data.name, 'avatar': a.avatar if a else 'common/portrait.gif', 'introduction':up.user_data.name+'('+up.user_code+')'}})
    return '登录超时,根据秘钥无法找到在线用户!', 401
Ejemplo n.º 2
0
 def getRoles(self):
     """
     获得对象的角色列表
     :return: list, 对象的角色列表
     """
     h = UserHandler()
     r = RoleHandler()
     roles = h.getUserRolesByCode(self.user_code)
     all_roles = roles.copy()
     for e in roles:
         all_roles.extend(r.getAllDescendantsByCode(e.role_code))
     return all_roles
Ejemplo n.º 3
0
def pushUserAvatar():
    """
    更新用户头像
    :return: json, {'data':{'code': r}} r为0表示更新成功, 否则表示更新失败
    """
    data = request.get_json()
    if data:
        h = UserHandler()
        r = h.pushUserAvatar(data)
    return packageResponse({'data': {
        'code': r
    }}) if r == 0 else ('头像信息更新失败!', 500)
Ejemplo n.º 4
0
def listUsers():
    """
    向客户端返回所有用户
    :return: json, {'data': [{'user_code': str, 'name': str}]}
    """
    h = UserHandler()
    u = h.listUsers(status='')
    return packageResponse(
        {'data': [{
            'user_code': e.user_code,
            'name': e.name
        } for e in u]})
Ejemplo n.º 5
0
def updateUser():
    """
    更新用户数据
    :return: json, {'data':{'code': r}} r为0表示更新成功, 否则表示更新失败
    """
    data = request.get_json()
    if data:
        h = UserHandler()
        r = h.updateUserData(data)
    return packageResponse({'data': {
        'code': r
    }}) if r == 0 else ('用户信息更新失败!', 500)
Ejemplo n.º 6
0
def getUserData():
    """
    向客户端返回用户数据
    :return: json, {'data':{'user_code':str, 'name':str, 'status':boolean, 'password':'', 'phone':str, 'email':str, 'avatar':str, 'role':[]}}
    """
    args = request.args
    params = {'user_code': '', 'name': ''}
    if 'user_code' in args:
        params['user_code'] = args['user_code']
    if 'name' in args:
        params['name'] = args['name']
    h = UserHandler()
    return packageResponse({'data': h.getUserData(params)})
Ejemplo n.º 7
0
def setPassword():
    """
    设置用户密码
    :return: json, {'data':{'code': r}} r为0表示设置成功, 否则表示设置失败
    """
    data = request.get_json()
    if data:
        h = UserHandler()
        user_code = data['user_code']
        password = data['password']
        r = h.setPassword(user_code, password)
    return packageResponse({'data': {
        'code': r
    }}) if r == 0 else ('密码信息更新失败!', 500)
Ejemplo n.º 8
0
def authSignInUser(code, pwd):
    """
    根据用户代码和密码校验用户
    :param code: 用户代码
    :param pwd: 用户密码
    :return: {'authenticated': i}, i为1表示成功, 为0表示失败
    """
    h = UserHandler()
    l = h.authenticateUser(code, pwd, 'B')
    if(len(l)>0):
        return packageResponse({'authenticated':'1'})
    else:
        l = h.authenticateUser(code, pwd, 'A')
        if(len(l)>0):
            return packageResponse({'authenticated':'1'})
    return packageResponse({'authenticated':'0'})
Ejemplo n.º 9
0
def get_password_func(username):
    h = UserHandler()
    u = h.getUserByCode(username)
    return u.password