def login_user(db: Session = Depends(get_db), data: OAuth2PasswordRequestForm = Depends()): db_user = crud.authenticate_user(db, data.username, data.password) if not db_user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, ) access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) access_token = create_access_token(data={"sub": db_user.username}, expires_delta=access_token_expires) return {"access_token": access_token, "token_type": "bearer"}
async def login_for_access_token(form_data: schemas.TokenAuth, db: Session = Depends(get_db)): user = crud.authenticate_user(db, form_data.email, form_data.password) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect email or password", headers={"WWW-Authenticate": "Bearer"}, ) access_token_expires = timedelta( minutes=int(os.environ.get("ACCESS_TOKEN_EXPIRE_MINUTES"))) access_token = crud.create_access_token(data={"email": user.email}, expires_delta=access_token_expires) return {"access_token": access_token, "token_type": "bearer"}
async def login_for_access_token( form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_db)): user = crud.authenticate_user(db, form_data.username, form_data.password) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, ) access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) access_token = crud.create_access_token(db=db, data={"sub": user.login}, expires_delta=access_token_expires) return schemas.Token(access_token=access_token, token_type="bearer")
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_db)): user = crud.authenticate_user( db, form_data.username, form_data.password) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, ) from datetime import timedelta access_token_expires = timedelta(days=utils.ACCESS_TOKEN_EXPIRES_YEAR) from utils import create_access_token access_token = create_access_token( data={"sub": user.username}, expires_delta=access_token_expires ) return {"access_token": access_token, "token_type": "bearer"}
def authenticate_user(): print('*' * 20) print('\n') print( request.form.get('email') ) # request.form.get will grab from the form, matching to the name attribute in the html print(request.form.get('password')) print('\n') print('*' * 20) user_email = request.form.get('email') user_password = request.form.get('password') auth_status = crud.authenticate_user(user_email, user_password) if auth_status == True: session["user_email"] = user_email print(session["user_email"]) return redirect('/add_a_toy') else: flash("incorrect email or password") return redirect('/')
55311) H = crud.create_store("Target", None, "Target.com", "False") J = crud.create_store("Amazon", None, "amazon.com", "True") S1 = crud.create_store("Amazon", None, "amazon.com", "True") S2 = crud.create_store("walmart", None, "walmart.com", "False") S3 = crud.create_store("wayfair", None, "wayfair.com", "True") S4 = crud.create_store("Target", None, "Target.com", "False") S5 = crud.create_store("wayfair", None, "wayfair.com", "True") S6 = crud.create_store("kohls", None, "kohls.com", "False") M = crud.create_toy_feature(y, z) N = crud.create_toy_feature(y, k) D = crud.create_price(x, H, 15, 1112020, 11102020) E = crud.create_price(x, J, 20, 1122020, 12122020) p1 = crud.create_price(cc, H, 25, 11162020, 11232020) p2 = crud.create_price(ee, S2, 30, 11162020, 11232020) p3 = crud.create_price(gg, S3, 30, 12012020, 12072020) p4 = crud.create_price(hh, S4, 25, 12072020, 12172020) p5 = crud.create_price(ii, S5, 20, 12072020, 12172020) p6 = crud.create_price(bb, S1, 35, 11252020, 12052020) p7 = crud.create_price(aa, S6, 50, 12022020, 12122020) p8 = crud.create_price(ff, S4, 60, 12022020, 12122020) p9 = crud.create_price(jj, S4, 35, 12022020, 12122020) t = crud.authenticate_user('*****@*****.**', 'test') # S = crud.create_user_toy(x,u) # T = crud.create_user_toy(y,I)