Commit 615da07f0b8ec79c4bbc801d1b9d27d8d9a1c372

Authored by hitier
1 parent 4770ee5d

Fix set_role and and set_password to User.init

Showing 1 changed file with 6 additions and 1 deletions   Show diff stats
app/auth/models.py
@@ -49,6 +49,7 @@ class User(UserMixin, db.Model): @@ -49,6 +49,7 @@ class User(UserMixin, db.Model):
49 name = db.Column(db.String(100)) 49 name = db.Column(db.String(100))
50 login = db.Column(db.String(100), unique=True) 50 login = db.Column(db.String(100), unique=True)
51 role = db.Column(db.Integer, default=0) 51 role = db.Column(db.Integer, default=0)
  52 + password = db.Column(db.String(128))
52 password_hash = db.Column(db.String(128)) 53 password_hash = db.Column(db.String(128))
53 54
54 def __repr__(self): 55 def __repr__(self):
@@ -57,7 +58,11 @@ class User(UserMixin, db.Model): @@ -57,7 +58,11 @@ class User(UserMixin, db.Model):
57 # Set role at construction time 58 # Set role at construction time
58 def __init__(self, **kwargs): 59 def __init__(self, **kwargs):
59 super(User, self).__init__(**kwargs) 60 super(User, self).__init__(**kwargs)
60 - self.set_role(kwargs['role']) 61 + if ('role' in kwargs):
  62 + self.set_role(kwargs['role'])
  63 + if ('password' in kwargs):
  64 + self.set_password(kwargs['password'])
  65 + self.password = None
61 66
62 def set_role(self, role): 67 def set_role(self, role):
63 self.role = _checkRole(role) 68 self.role = _checkRole(role)