async def get_token_for_logging(form: OAuth2PasswordRequestForm = Depends()): jwt_dict = {'username': form.username, 'password': form.password} jwt_user = JWT_User(**jwt_dict) is_user = authenticate_user(jwt_user) if not is_user: raise HTTPException(status_code=HTTP_401_UNAUTHORIZED) jwt_token = create_jwt_token(jwt_user) return {'access_token': jwt_token}
async def login_for_access_token( form_data: OAuth2PasswordRequestForm = Depends()): jwt_user_dict = { "username": form_data.username, "password": form_data.password } jwt_user = JWTUser(**jwt_user_dict) user = await authenticate_user(jwt_user) if user is None: raise HTTPException(status_code=HTTP_401_UNAUTHORIZED) jwt_token = create_jwt_token(user) return {"access_token": jwt_token}
async def login_for_access_token( form_data: OAuth2PasswordRequestForm = Depends()): jwt_user_dict = { 'username': form_data.username, 'password': form_data.password } jwt_user = JWTUser(**jwt_user_dict) user = authenticate_user(jwt_user) if user is None: raise HTTPException(HTTP_401_UNAUTHORIZED) jwt_token = create_jwt_token(user) return {'token': jwt_token}
async def login_access_token(form_data: OAuth2PasswordRequestForm = Depends()): redis_key = f"token:{form_data.username},{form_data.password}" user = await re.redis.get(redis_key) if not user: jwt_user_dict = { "username": form_data.username, "password": form_data.password } jwt_user = JWTUser(**jwt_user_dict) user = await authenticate_user(jwt_user) await re.redis.set(redis_key, pickle.dumps(user)) if user is None: raise HTTPException(status_code=HTTP_401_UNAUTHORIZED) else: user = pickle.loads(user) jwt_token = create_jwt_token(user) return {"access_token": jwt_token}