Store password as a hash

This commit is contained in:
coolneng 2020-09-30 11:27:48 +02:00
parent 97700c0855
commit eb56623bd4
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
3 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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}

View File

@ -13,6 +13,8 @@ mkShell {
python38Packages.alembic
python38Packages.pytest
python38Packages.twilio
python38Packages.passlib
python38Packages.bcrypt
sqlite
# Development tools
python38Packages.isort