Exemple #1
0
def sign_up(self, data):
    user = User(name=data.get('name'))
    local_oauth = LocalOAuth()
    local_oauth.password = data.get('password')
    user.local_oauth = local_oauth
    try:
        self.db.add(user)
        self.db.commit()
        return msg(True, "注册成功")
    except exc.IntegrityError as e:
        return msg(False, str(e))
Exemple #2
0
 def get(self, *args, **kwargs):
     data, count = UserModel.all()
     kwargs = {
         "count": count,
         "data": data
     }
     self.render("passport/accounts/index.html", **kwargs)
Exemple #3
0
def sign_in(self, data):
    user = User.by_name(name=data.get('name'))
    password = user.local_oauth
    if user and password.auth_password(other_password=data.get('password')):
        self.session.set('user_name', user.name)
        return msg(True, "登陆成功")
    return msg(False, '用户名和密码不正确')
Exemple #4
0
 def validate_name(self, field):
     """
     如果用户已经有了,就不让注册
     :param self:
     :param field:
     :return:
     """
     if User.by_name(field.data) is None:
         raise ValidationError("用户没注册")
Exemple #5
0
    def get(self, user_id):
        data, count = RoleModel.all()
        user = UserModel.by_id(user_id)
        roles = user.roles
        rlist = list()
        for i in roles:
            rlist.append(i.id)
        kwargs = {
            "data": data,
            "user": user,
            "rlist": rlist
        }

        self.render("passport/accounts/set_role.html", **kwargs)
Exemple #6
0
def create_user():
    user = User()
    user.name = "admin"
    user.password = "******"
    dbSession.add(user)
    dbSession.commit()
Exemple #7
0
 def get(self, user_id):
     kwargs = {
         "form": EditForm(),
         "data": UserModel.by_id(user_id)
     }
     self.render("passport/accounts/edit.html", **kwargs)
Exemple #8
0
 def get_current_user(self):
     user_name = self.session.get("user_name")
     user = None
     if user_name:
         user = User.by_name(name=user_name)
     return user if user else None