Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 52f1e05

Browse files
committed
updated
2 parents 3983a1a + e381590 commit 52f1e05

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

‎app/models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from unicodedata import category
2-
from uuid import UUID
31
from .database import Base
42
from sqlalchemy import TIMESTAMP, Column, ForeignKey, String, Boolean, text
53
from sqlalchemy.dialects.postgresql import UUID

‎app/oauth2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1+
import base64
2+
from typing import List
13
from fastapi import Depends, HTTPException, status
24
from fastapi_jwt_auth import AuthJWT
5+
from pydantic import BaseModel
36

47
from . import models
58
from .database import get_db
69
from sqlalchemy.orm import Session
10+
from .config import settings
11+
12+
13+
class Settings(BaseModel):
14+
authjwt_algorithm: str = settings.JWT_ALGORITHM
15+
authjwt_decode_algorithms: List[str] = [settings.JWT_ALGORITHM]
16+
authjwt_token_location: set = {'cookies', 'headers'}
17+
authjwt_access_cookie_key: str = 'access_token'
18+
authjwt_refresh_cookie_key: str = 'refresh_token'
19+
authjwt_public_key: str = base64.b64decode(
20+
settings.JWT_PUBLIC_KEY).decode('utf-8')
21+
authjwt_private_key: str = base64.b64decode(
22+
settings.JWT_PRIVATE_KEY).decode('utf-8')
23+
24+
25+
@AuthJWT.load_config
26+
def get_config():
27+
return Settings()
728

829

930
class NotVerified(Exception):

‎app/routers/auth.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import base64
21
from datetime import timedelta
3-
from typing import List
4-
from urllib import response
52
from fastapi import APIRouter, Request, Response, status, Depends, HTTPException
6-
from pydantic import BaseModel, EmailStr
3+
from pydantic import EmailStr
74

85
from app import oauth2
96
from .. import schemas, models, utils
@@ -13,23 +10,6 @@
1310
from ..config import settings
1411

1512

16-
class Settings(BaseModel):
17-
authjwt_algorithm: str = settings.JWT_ALGORITHM
18-
authjwt_decode_algorithms: List[str] = [settings.JWT_ALGORITHM]
19-
authjwt_token_location: set = {'cookies', 'headers'}
20-
authjwt_access_cookie_key: str = 'access_token'
21-
authjwt_refresh_cookie_key: str = 'refresh_token'
22-
authjwt_public_key: str = base64.b64decode(
23-
settings.JWT_PUBLIC_KEY).decode('utf-8')
24-
authjwt_private_key: str = base64.b64decode(
25-
settings.JWT_PRIVATE_KEY).decode('utf-8')
26-
27-
28-
@AuthJWT.load_config
29-
def get_config():
30-
return Settings()
31-
32-
3313
router = APIRouter()
3414
ACCESS_TOKEN_EXPIRES_IN = settings.ACCESS_TOKEN_EXPIRES_IN
3515
REFRESH_TOKEN_EXPIRES_IN = settings.REFRESH_TOKEN_EXPIRES_IN
@@ -48,7 +28,7 @@ async def create_user(payload: schemas.CreateUserSchema, db: Session = Depends(g
4828
raise HTTPException(
4929
status_code=status.HTTP_400_BAD_REQUEST, detail='Passwords do not match')
5030
# Hash the password
51-
payload.password = utils.hash(payload.password)
31+
payload.password = utils.hash_password(payload.password)
5232
del payload.passwordConfirm
5333
payload.role = 'user'
5434
payload.verified = True

‎app/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
44

55

6-
def hash(password: str):
6+
def hash_password(password: str):
77
return pwd_context.hash(password)
88

99

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /