示例#1
0
 def mutate(root, info, title, content, token):
     try:
         payload = decode_access_token(data=token)
         username: str = payload.get("sub")
         if username is None:
             raise GraphQLError("Invalid credentials")
         token_data = TokenData(username=username)
     except PyJWTError:
         raise GraphQLError("Invalid credentials")
     user = crud.get_user_by_username(db, username=token_data.username)
     if user is None:
         raise GraphQLError("Invalid credentials")
     blog = BlogBase(title=title, content=content)
     crud.create_new_blog(db=db, blog=blog)
     ok = True
     return CreateNewBlog(ok=ok)
示例#2
0
    def mutate(root, info, token, title):

        query = AnimeSchema.get_query(info)
        try:
            payload = decode_access_token(data=token)
            username: str = payload.get("sub")
            if username is None:
                raise GraphQLError("Invalid credentials")
            token_data = TokenData(username=username)
        except PyJWTError:
            raise GraphQLError("Invalid credentials")
        user = crud.get_user_by_username(db, username=token_data.username)
        if user is None:
            raise GraphQLError("Invalid credentials")
        AnimeSearch = route_optima_search(query, title, str(title))
        return SearchAnime(AnimeSearch=AnimeSearch)
示例#3
0
    def mutate(root, info, token):

        query = AnimeSchema.get_query(info)
        try:
            payload = decode_access_token(data=token)
            username: str = payload.get("sub")
            if username is None:
                raise GraphQLError("Invalid credentials")
            token_data = TokenData(username=username)
        except PyJWTError:
            raise GraphQLError("Invalid credentials")
        user = crud.get_user_by_username(db, username=token_data.username)
        if user is None:
            raise GraphQLError("Invalid credentials")
        AnimeList = route_optima(query, "allanime")

        return GetAnimeList(AnimeList=AnimeList)
示例#4
0
def get_curret_user(token: str = Depends(oauth2_scheme)):
    credentials_exception = HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Could not validate credentials",
        headers={"WWW-Authenticate": "Bearer"}
    )
    try:
        payload = jwt.decode(token, SECRET_KEY, alogrithm=ALGORITHM)
        username: str = payload.get("sub")
        if username is None:
            raise credentials_exception
        token_data = TokenData(username=username)
    except JWTError:
        raise credentials_exception
    user = get_user(models.User, username=token_data.username)
    if user is None:
        raise credentials_exception
    return user
示例#5
0
async def get_current_user(token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)):
    credentials_exception = HTTPException(
        status_code = status.HTTP_401_UNAUTHORIZED,
        detail = "Could not validate credentials",
        headers = {"WWW-Authenticate": "Bearer"},
    )
    try:
        payload = decode_access_token(data=token)
        username: str = payload.get("sub")
        if username is None:
            raise credentials_exception
        token_data = TokenData(username=username)
    except PyJWTError:
        raise credentials_exception
    user = get_user_by_username(db, username=token_data.username)
    if user is None:
        raise credentials_exception
    return user
示例#6
0
async def get_current_user(token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)):
    credentials_exception = HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Could not validate credentials",
        headers={"WWW-Authenticate": "Bearer"},
    )
    try:
        payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
        email: str = payload.get("sub")
        if email is None:
            raise credentials_exception
        token_data = TokenData(email=email)
    except JWTError:
        raise credentials_exception
    user = crud.get_user_by_email(db, email=token_data.email)
    if user is None:
        raise credentials_exception
    return user
示例#7
0
async def get_user_from_token(token: str = Depends(oauth2_scheme),
                              db: Session = Depends(get_db)):
    credentials_exception = HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Could not validate credentials",
        headers={"WWW-Authenticate": "Bearer"},
    )
    try:
        payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
        username: str = payload.get("sub")
        if username is None:
            raise credentials_exception
        token_data = TokenData(username=username)
    except PyJWTError:
        raise credentials_exception
    user = await get_user(db, username=token_data.username)
    if user is None:
        raise credentials_exception
    return user
示例#8
0
async def get_current_user(token: str = Depends(oauth2_scheme)):
    credentials_exception = HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Could not validate credentials",
        headers={"WWW-Authenticate": "Bearer"},
    )
    print(token)
    try:
        payload = jwt.decode(token, SECRET_KEY_IN_DOCS, algorithms=[ALGORITHM])
        username: str = payload.get("sub")
        if username is None:
            raise credentials_exception
        token_data = TokenData(username=username)
    except PyJWTError as e:
        print(e)
        raise credentials_exception
    user = get_user(fake_users_db, username=token_data.username)
    if user is None:
        raise credentials_exception
    return user
async def getCurrentUser(token: str = Depends(oauth2_scheme), db: Session = Depends(getDb)):
    try:
        credentials_exception = HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Invalid Credentials",
            headers={"WWW-Authenticate": "Bearer"},
        )
        try:
            payload = jwt.decode(token, crud.SECRET_KEY, algorithms=[crud.ALGORITHM])
            userName: str = payload.get("sub")
            if userName is None:
                raise credentials_exception
            token_data = TokenData(userName=userName)
        except JWTError:
            raise credentials_exception
        user = getUser(db=db, userName=token_data.userName)
        if user is None:
            raise credentials_exception
        return user
    except Exception as e:
        print(e)
        raise HTTPException(status_code=400, detail={"message": "Invalid Credentials"})