23 lines
614 B
Python
23 lines
614 B
Python
from fooder.controller.base import ModelController
|
|
from fooder.domain import User
|
|
from fooder.context import Context
|
|
from fooder.exc import Unauthorized, NotFound
|
|
|
|
|
|
class UserController(ModelController[User]):
|
|
@classmethod
|
|
async def session_start(
|
|
cls,
|
|
ctx: Context,
|
|
username: str,
|
|
password: str,
|
|
) -> "UserController":
|
|
try:
|
|
obj = await ctx.repo.user.get(User.username == username)
|
|
except NotFound:
|
|
raise Unauthorized()
|
|
|
|
if not obj.verify_password(password):
|
|
raise Unauthorized()
|
|
|
|
return cls(ctx, obj)
|