sql_app: auth by user not email
This commit is contained in:
parent
f1cbd6d265
commit
08b8aafcf0
@ -27,8 +27,8 @@ def create_access_token(data : dict, expires_delta : Optional[timedelta] = None)
|
|||||||
encoded_jwt = jwt.encode(to_encode, JWT_SECRET, algorithm=JWT_ALGO)
|
encoded_jwt = jwt.encode(to_encode, JWT_SECRET, algorithm=JWT_ALGO)
|
||||||
return encoded_jwt
|
return encoded_jwt
|
||||||
|
|
||||||
def authenticate_user(db: Session, email : str, password : str):
|
def authenticate_user(db: Session, username : str, password : str):
|
||||||
user = crud.get_user_by_email(db=db, email=email)
|
user = crud.get_user_by_username(db, username)
|
||||||
if not user:
|
if not user:
|
||||||
return False
|
return False
|
||||||
return crypto.verify_key(password, user.passwd_salt, user.hashed_password)
|
return crypto.verify_key(password, user.passwd_salt, user.hashed_password)
|
||||||
|
@ -48,7 +48,7 @@ async def get_current_active_user(current_user: schemas.User = Depends(get_curre
|
|||||||
raise HTTPException(status_code=400, detail="Inactive user")
|
raise HTTPException(status_code=400, detail="Inactive user")
|
||||||
return current_user
|
return current_user
|
||||||
|
|
||||||
@app.post("/users/reg", response_model=schemas.User)
|
@app.post("/users/reg", response_model=schemas.User, tags=['users'])
|
||||||
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
|
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
|
||||||
db_user = crud.get_user_by_email(db, email=user.email)
|
db_user = crud.get_user_by_email(db, email=user.email)
|
||||||
if db_user:
|
if db_user:
|
||||||
|
Loading…
Reference in New Issue
Block a user