예제 #1
0
 def login(body: LoginUserBodyModel) -> LoginResponseModel:
     UserActions.is_user_exist(body.username, should_exist=True)
     hashed_password = UserActions.password_to_hash(body.password)
     user_in_db: UserDB = session.query(UserDB).filter(
         UserDB.name == body.username)[0]
     if user_in_db.password == hashed_password:
         return LoginResponseModel(Authorization=Authentication.create_jwt(
             JwtPayloadModel(username=body.username)))
     raise Forbidden(description="wrong password or username")
예제 #2
0
 def signup(body: SignUpUserBodyModel) -> SignUpResponseModel:
     hashed_password = UserActions.password_to_hash(body.password)
     user = UserDB(name=body.username, password=hashed_password)
     UserActions.is_user_exist(user.name)
     session.add(user)
     token = Authentication.create_jwt(
         JwtPayloadModel(username=body.username))
     session.commit()
     return SignUpResponseModel(Authorization=token)