예제 #1
0
def login(request: Request) -> UserResponse:
    """User logs in."""
    body = request.openapi_validated.body

    user = User.by_email(body.user.email, db=request.db)
    if user and user.verify_password(body.user.password):
        return {"user": user}

    raise exception_response(
        422, json_body={"errors": {"email or password": ["is invalid"]}}
    )
예제 #2
0
def test_by_shortcuts(db: Session, democontent: None) -> None:
    """Test that by_* shortcuts work."""
    assert User.by_username("one", db) == User.by_email("*****@*****.**", db)
    assert User.by_username("one", db) == User.by_id(USER_ONE_ID, db)