diff options
author | Michaël Ball <michael.ball@gmail.com> | 2014-12-28 12:24:22 +0000 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2015-11-27 20:02:04 +0000 |
commit | 75beec91a8526fbbc0a90134140b9dff6af15c0c (patch) | |
tree | 02414e46da3e08000384c40c27b7aab9748de0fe /models/user.py | |
parent | a2964845e3c03b9cf5f01583f53f7553c7d67caf (diff) |
Initial frontend work
Diffstat (limited to 'models/user.py')
-rw-r--r-- | models/user.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/models/user.py b/models/user.py new file mode 100644 index 0000000..f912e43 --- /dev/null +++ b/models/user.py @@ -0,0 +1,52 @@ +from common.security import pwd_context + + +class User: + def __init__(self, **kwargs): + for (key, value) in kwargs.items(): + setattr(self, key, value) + + def get_id(self): + if self.id: + return str(self.id) + else: + raise ValueError("No user") + + def is_authenticated(self): + if self.authenticated > 0: + return True + else: + return False + + def is_active(self): + if self.active > 0: + return True + else: + return False + + def is_anonymous(self): + if self.anonymous > 0: + return True + else: + return False + + def verify(self, password): + if self.id and pwd_context.verify(password, self.password_hash): + self.authenticated = 1 + return True + else: + return False + + def new_password(self, password, category=None): + if self.id: + hash = None + + if category: + hash = pwd_context.encrypt(password, category=category) + else: + hash = pwd_context.encrypt(password) + + return hash + + else: + raise ValueError("No user") |