Browse Source

Add login method

Getty Ritter 4 years ago
parent
commit
8f75eb4208
1 changed files with 7 additions and 0 deletions
  1. 7 0
      lc/model.py

+ 7 - 0
lc/model.py

@@ -33,6 +33,13 @@ class User(Model):
     def authenticate(self, password: str) -> bool:
         return pwd.verify(password, self.passhash)
 
+    @staticmethod
+    def login(user: r.User) -> "User":
+        u = User.by_slug(user.name)
+        if not u.authenticate(user.password):
+            raise e.BadPassword(name=user.name)
+        return u
+
     @staticmethod
     def by_slug(slug: str) -> "User":
         return User.get(name=slug)