Store password as a hash
This commit is contained in:
parent
97700c0855
commit
eb56623bd4
|
@ -4,17 +4,16 @@ from sqlalchemy.orm import Session
|
|||
|
||||
from app.external_services import resend_otp, send_otp
|
||||
from app.schemas import *
|
||||
from database.crud import get_db, insert_data, verify_otp
|
||||
from database.crud import add_user, get_db, verify_otp
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||
|
||||
|
||||
# FIXME Password hash
|
||||
@router.post("/register", response_model=UserCreateResponse)
|
||||
def create_user(data: UserCreate, db: Session = Depends(get_db)):
|
||||
user = insert_data(model="Users", data=data, db=db)
|
||||
user = add_user(data=data, db=db)
|
||||
send_otp(data=user, db=db)
|
||||
return user
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
from datetime import datetime
|
||||
from fastapi import HTTPException
|
||||
from passlib.context import CryptContext
|
||||
|
||||
from app.schemas import *
|
||||
from database import SessionLocal
|
||||
from database.models import *
|
||||
|
||||
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
|
@ -43,6 +47,12 @@ def fetch_user_by_email(data, db):
|
|||
return db.query(Users).filter(Users.email == data.email).first()
|
||||
|
||||
|
||||
def add_user(data, db):
|
||||
data.password = pwd_context.hash(data.password)
|
||||
user = insert_data(model="Users", data=data, db=db)
|
||||
return user
|
||||
|
||||
|
||||
def activate_account(data: OTPVerify, db):
|
||||
db.query(Users).filter(Users.access_key == data.access_key).update(
|
||||
{Users.status: 1}
|
||||
|
|
Loading…
Reference in New Issue