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.external_services import resend_otp, send_otp
|
||||||
from app.schemas import *
|
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()
|
router = APIRouter()
|
||||||
|
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||||
|
|
||||||
|
|
||||||
# FIXME Password hash
|
|
||||||
@router.post("/register", response_model=UserCreateResponse)
|
@router.post("/register", response_model=UserCreateResponse)
|
||||||
def create_user(data: UserCreate, db: Session = Depends(get_db)):
|
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)
|
send_otp(data=user, db=db)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
from passlib.context import CryptContext
|
||||||
|
|
||||||
from app.schemas import *
|
from app.schemas import *
|
||||||
from database import SessionLocal
|
from database import SessionLocal
|
||||||
from database.models import *
|
from database.models import *
|
||||||
|
|
||||||
|
|
||||||
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||||
|
|
||||||
|
|
||||||
def get_db():
|
def get_db():
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
try:
|
try:
|
||||||
|
@ -43,6 +47,12 @@ def fetch_user_by_email(data, db):
|
||||||
return db.query(Users).filter(Users.email == data.email).first()
|
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):
|
def activate_account(data: OTPVerify, db):
|
||||||
db.query(Users).filter(Users.access_key == data.access_key).update(
|
db.query(Users).filter(Users.access_key == data.access_key).update(
|
||||||
{Users.status: 1}
|
{Users.status: 1}
|
||||||
|
|
|
@ -13,6 +13,8 @@ mkShell {
|
||||||
python38Packages.alembic
|
python38Packages.alembic
|
||||||
python38Packages.pytest
|
python38Packages.pytest
|
||||||
python38Packages.twilio
|
python38Packages.twilio
|
||||||
|
python38Packages.passlib
|
||||||
|
python38Packages.bcrypt
|
||||||
sqlite
|
sqlite
|
||||||
# Development tools
|
# Development tools
|
||||||
python38Packages.isort
|
python38Packages.isort
|
||||||
|
|
Loading…
Reference in New Issue