Explorar el Código

Add login method

Getty Ritter hace 4 años
padre
commit
8f75eb4208
Se han modificado 1 ficheros con 7 adiciones y 0 borrados
  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)