-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aisuko <[email protected]>
- Loading branch information
Showing
42 changed files
with
479 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
from typing import Annotated | ||
from src.api.dependencies.repository import get_repository | ||
from src.models.schemas.account import AccountInCreate, AccountInLogin, AccountInResponse, AccountWithToken | ||
from src.config.settings.const import ANONYMOUS_USER,ANONYMOUS_PASS | ||
from src.config.settings.const import ANONYMOUS_USER, ANONYMOUS_PASS | ||
from src.repository.crud.account import AccountCRUDRepository | ||
from src.securities.authorizations.jwt import jwt_generator | ||
from src.utilities.exceptions.database import EntityAlreadyExists | ||
|
@@ -29,6 +29,7 @@ | |
|
||
router = fastapi.APIRouter(prefix="/auth", tags=["authentication"]) | ||
|
||
|
||
@router.post( | ||
"/signup", | ||
name="auth:signup", | ||
|
@@ -43,9 +44,9 @@ async def signup( | |
Create a new account | ||
```bash | ||
curl -X 'POST' 'http://127.0.0.1:8000/api/auth/signup' | ||
-H 'accept: application/json' | ||
-H 'Content-Type: application/json' | ||
curl -X 'POST' 'http://127.0.0.1:8000/api/auth/signup' | ||
-H 'accept: application/json' | ||
-H 'Content-Type: application/json' | ||
-d '{"username": "aisuko", "email": "[email protected]", "password": "aisuko"}' | ||
``` | ||
|
@@ -62,7 +63,6 @@ async def signup( | |
- **updated_at**: The update time | ||
""" | ||
|
||
|
||
try: | ||
await account_repo.is_username_taken(username=account_create.username) | ||
await account_repo.is_email_taken(email=account_create.email) | ||
|
@@ -123,7 +123,7 @@ async def signin( | |
|
||
if account_login.username == ANONYMOUS_USER: | ||
raise await http_exc_400_credentials_bad_signin_request() | ||
|
||
try: | ||
db_account = await account_repo.read_user_by_password_authentication(account_login=account_login) | ||
|
||
|
@@ -146,14 +146,15 @@ async def signin( | |
), | ||
) | ||
|
||
|
||
@router.get( | ||
path="/token", | ||
name="authentication: token for anonymous user", | ||
response_model=dict, | ||
status_code=fastapi.status.HTTP_200_OK, | ||
) | ||
async def get_token( | ||
account_repo: AccountCRUDRepository = fastapi.Depends(get_repository(repo_type=AccountCRUDRepository)) | ||
account_repo: AccountCRUDRepository = fastapi.Depends(get_repository(repo_type=AccountCRUDRepository)), | ||
) -> dict: | ||
""" | ||
Get chat history for an anonymous user | ||
|
@@ -171,6 +172,7 @@ async def get_token( | |
|
||
return {"token": access_token} | ||
|
||
|
||
@router.post("/verify") | ||
async def login_for_access_token( | ||
form_data: Annotated[fastapi.security.OAuth2PasswordRequestForm, fastapi.Depends()], | ||
|
@@ -191,8 +193,9 @@ async def login_for_access_token( | |
- **token_type**: The token type | ||
""" | ||
try: | ||
db_account= await account_repo.read_user_by_password_authentication( | ||
account_login=AccountInLogin(username=form_data.username,password=form_data.password)) | ||
db_account = await account_repo.read_user_by_password_authentication( | ||
account_login=AccountInLogin(username=form_data.username, password=form_data.password) | ||
) | ||
except Exception: | ||
raise await http_exc_400_failed_validate_request() | ||
access_token = jwt_generator.generate_access_token(account=db_account) | ||
|
Oops, something went wrong.