|
@@ -33,6 +33,13 @@ class User(Model):
|
|
def authenticate(self, password: str) -> bool:
|
|
def authenticate(self, password: str) -> bool:
|
|
return pwd.verify(password, self.passhash)
|
|
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
|
|
@staticmethod
|
|
def by_slug(slug: str) -> "User":
|
|
def by_slug(slug: str) -> "User":
|
|
return User.get(name=slug)
|
|
return User.get(name=slug)
|