Пример #1
0
def del_user_role_lib(self, userid):
    user = User.by_id(userid)
    if user is None:
        return
    user.roles = []
    self.db.add(user)
    self.db.commit()
def del_user_allrole_lib(self, userid):
    """13删除用户的所有角色"""
    user = User.by_id(userid)
    user.roles = []
    self.db.add(user)
    self.db.commit()
    flash(self, '用户角色删除成功', 'success')
Пример #3
0
 def get_current_user(self):  #重写方法 如果要使用authenticated方法
     """获取当前用户"""
     username = self.session.get("user_name")
     user = None
     if username:
         user = User.by_name(username)
     return user if user else None
Пример #4
0
 def get_current_user(self):
     '''获取当前用户'''
     username = self.session.get('user_name')
     user = None
     if username:
         user = User.by_name(username)
     return user if user else None
Пример #5
0
 def get_current_user(self):
     """获取当前用户"""
     username = self.session.get("user_name")
     user = None
     if username:
         user = User.by_name(username)
     return user if user else None
Пример #6
0
 def get_current_user(self):
     """获取当前用户"""
     username = self.session.get("user_name")  # 从session中获取user.name
     user = None
     if username:
         user = User.by_name(username)
     # 如果用户存在,就返回user,如果不存在就返回None
     return user if user else None
def del_user_role_lib(self, userid,roleid):
    """12删除用户的角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    user.roles.remove(role)
    self.db.add(user)
    self.db.commit()
    flash(self, '用户角色删除成功', 'success')
Пример #8
0
def permission_manager_list_lib(self):
    ''' 返回给权限管理页面 '''
    roles = Role.all()
    permissions = Permission.all()
    menus = Menu.all()
    handlers = Handler.all()
    users = User.all()
    return roles, permissions, menus, handlers, users
def add_user_dev_role_lib(self, userid, roleid):
    """13为用户添加角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.append(role)
    self.db.add(user)
    self.db.commit()
def permission_manager_list_lib(self):
    # 获取所有的角色/权限/菜单/处理器/用户
    roles = Role.all()
    permissions = Permission.all()
    menus = Menu.all()
    handlers = Handler.all()
    users = User.all()

    return roles, permissions, menus, handlers, users
def del_user_role_lib(self, userid):
    '''12 删除用户角色'''
    user = User.by_id(userid)
    if user is None:
        flash(self, '用户角色不存在,删除失败!', 'error')
        return
    self.db.delete(user)
    self.db.commit()
    flash(self, '用户删除成功!', 'success')
def del_user_dev_role_lib(self, userid, roleid):
    """14为用户删除角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.remove(role)
    self.db.add(user)
    self.db.commit()
Пример #13
0
 def get_current_user(self):
     '''获取当前用户'''
     username = self.session.get('user_name')
     # 注意这里的'user_name'是我们在登陆成功的时候
     # 设置的self.session.set('username': user.username)
     user = None
     if username:
         user = User.by_name(username)
     return user if user else None
Пример #14
0
def del_user_lib(self, uuid):
    """12为用户删除角色"""
    user = User.by_id(uuid)
    if user is None:
        return
    user.roles = []
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户删除角色删除成功", "success")
Пример #15
0
def add_user_dev_role_lib(self, userid, roleid):
    """13添加用户到研发部门"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.append(role)
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户添加研发部门的角色添加成功", "success")
Пример #16
0
def add_user_role_lib(self, userid, roleid):
    """10为用户添加角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.append(role)  #注意这里画龙点睛
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户添加角色添加成功", "success")
Пример #17
0
def add_user_role_lib(self, userid, roleid):
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.append(role)  #多对多关系添加
    #role.users.append(user)

    self.db.add(user)
    self.db.commit()
Пример #18
0
def del_user_for_one_role_lib(self, userid, roleid):
    """15为用户删除某个角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    # print("********%s"%role)
    if user is None or role is None:
        return
    user.roles.remove(role)
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户删除某个角色删除成功", "success")
def add_user_role_lib(self, userid, roleid):
    """10为用户添加角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        flash(self, "为用户添加角色失败", "error")
        return
    user.roles.append(role) #这行的意思是:往多对多关系表中插入数据
    #role.users.append(user)
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户添加角色成功", "success")
Пример #20
0
def user_edit(self, name, password):
    ''' 用户基本修改信息 '''
    if name == '' or password == '':
        return {'status': False, 'msg': '用户密码不能为空'}
    user = User.by_name(name)
    user.password = password
    user.name = name
    user.update_time = datetime.now()
    self.db.add(user)
    self.db.commit()
    self.session.set('username', name)
    return {'status': True, 'msg': '修改成功啦'}
Пример #21
0
def regist(self, mobile, mobile_captcha, name, password1, password2, captcha,
           code, agree):
    print('------------------')
    print(mobile_captcha)
    print(captcha)
    print('------------------')
    if agree == "":
        return {'status': False, 'msg': '请点击同意条款'}
    if self.conn.get("captcha:%s" % code) != captcha:
        return {'status': False, 'msg': '图形验证码不正确'}
    if self.conn.get("mobile_code:%s" % mobile) != mobile_captcha:
        return {'status': False, 'msg': '短信验证码不正确'}

    user = User.by_name(name)
    # print(type(user))
    # print(user)
    if name == "":
        return {'status': False, 'msg': '用户名不能为空'}
    if user != None:
        return {'status': False, 'msg': '用户已经存在'}
    if password1 != password2 and password1 != None:
        return {'status': False, 'msg': '两次密码不一致'}
    #存入数据库
    user = User()
    user.username = name
    user.password = password2
    user.mobile = mobile
    self.db.add(user)
    self.db.commit()
    return {'status': True, 'msg': "注册成功"}
Пример #22
0
def regist(self, name, mobile, mobile_captcha, password1, password2, captcha,
           code):
    """04注册函数
    判断类型  边界值
    """
    if self.conn.get("captcha:%s" % code) != captcha.lower():
        flash(self, '图片验证码不正确', 'error')
        return {'status': False, 'msg': '图片验证码不正确'}
    if self.conn.get("mobile_code:%s" % mobile) != mobile_captcha:
        flash(self, '短信验证码不正确', 'error')
        return {'status': False, 'msg': '短信验证码不正确'}
    if password1 != password2:
        flash(self, '两次密码不一致', 'error')
        return {'status': False, 'msg': '两次密码不一致'}
    #存入数据库
    user = User.by_name(name)
    if user is not None:
        flash(self, '用户名已存在', 'error')
        return {'status': False, 'msg': '用户名已存在'}
    user = User()
    user.name = name
    user.password = password2
    user.mobile = mobile
    self.db.add(user)
    self.db.commit()
    flash(self, '注册成功', 'success')
    return {'status': True, 'msg': '注册成功'}
def login(self, name, password):
    """02登录函数"""
    if name == '' or password == '':
        return {'status': False, 'msg': '请输入用户名或密码'}
    user = User.by_name(name)
    if user and user.auth_password(password):
        user.last_login = datetime.now()
        user.loginnum += 1  #修改了信息就要add然后commit
        self.db.add(user)
        self.db.commit()
        self.session.set('user_name', user.name)
        return {"status": True, 'msg': '登录成功'}
    return {'status': False, 'msg': '用户名或密码错误'}
Пример #24
0
def permission_manager_list_lib(self):
    """01权限管理页面函数"""
    roles = Role.all()
    permissions = Permission.all()
    menus = Menu.all()
    handlers = Handler.all()
    users = User.all()

    # 研发员工
    dev_role = Role.by_name('研发员工')
    dev_users = dev_role.users if dev_role else []
    dev_roleid = dev_role.id if dev_role else ''
    return roles, permissions, menus, handlers, users, dev_users, dev_roleid
Пример #25
0
def login(self, name, password):
    '''02登陆函数'''
    if name == '' and password == '':
        return {'status': False, 'msg': '请输入用户名或密码'}
    user = User.by_name(name)
    if user and user.auth_password(password):
        user.last_login = datetime.now()
        user.loginnum += 1
        self.db.add(user)
        self.db.commit()
        self.session.set('user_name', user.username)
        return {'status': True, 'msg': '登陆成功'}
    return {'status': False, 'msg': '用户名或密码不正确'}
Пример #26
0
def msg_count(self):
    msgs = self.conn.lrange('message:%s' % self.current_user.name, 0, -1)

    msgs.reverse()
    dict_list = []
    for message in msgs:
        message = tornado.escape.json_decode(message)
        message['sender_module'] = User.by_name(message['sender'])
        dict_list.append(message)
    count = len(msgs)
    msgs = dict(count=count, dict_list=dict_list)

    return msgs
Пример #27
0
def login(self, name, password):
    """02登录函数"""
    print name, password
    if name == '' and password == '':
        return {'status': False, 'msg': '请输入用户名或密码'}
    user= User.by_name(name)#注意
    if user and user.auth_password(password):#注意
        user.last_login = datetime.now()
        user.loginnum += 1
        self.db.add(user)
        self.db.commit()
        self.session.set('user_name', user.name)
        return {'status': True, 'msg': '登录成功'}
    return {'status': False, 'msg': '用户名输入错误或者密码不正确'}
Пример #28
0
def del_user_dev_role_lib(self, userid, roleid):
    """14为用户删除角色"""
    try:
        user = User.by_id(userid)
        role = Role.by_id(roleid)
        if user is None or role is None:
            flash(self, '用户或者角色不存在', 'error')
        user.roles.remove(role)  # 添加到中间表
        self.db.add(user)
        self.db.commit()
        flash(self, '用户删除角色成功', 'success')
    except Exception as e:
        print e
        flash(self, '用户删除角色失败', 'error')
Пример #29
0
def user_add_role(self, user_id, role_id):
    ''' 给用户添加角色 '''
    user = User.by_id(user_id)
    if user is None:
        return {'status': False, 'msg': '不存在该用户ID'}
    role = Role.by_id(role_id)
    if role is None:
        return {'status': False, 'msg': '不存在该角色ID'}
    user_role = UserToRole()
    user_role.r_id = role_id
    user_role.u_id = user_id
    self.db.add(user_role)
    self.db.commit()
    return {'status': True}
Пример #30
0
def del_user_role_lib(self, userid):
    """12删除用户角色"""
    try:
        user = User.by_id(userid)
        if user is None:
            flash(self, '用户不存在', 'error')
        # []
        user.roles = []
        # user.roles.remove(obj)  # 删除一个对象
        # user.roles.pop()  # 弹出最后一个
        self.db.add(user)
        self.db.commit()
        flash(self, '用户删除角色成功', 'success')
    except Exception as e:
        print e
        flash(self, '用户删除角色失败', 'error')