Ejemplo n.º 1
0
def profile(user_id):
    if request.method == 'GET':
        return get_user(id)
    elif request.method == 'PUT':
        return update_user(id, **request.get_json())
    elif request.method == 'DELETE':
        return destroy_user(id)
Ejemplo n.º 2
0
def user_show_put_delete(id):
    if request.method == 'GET':
        return get_user(id)
    if request.method == 'PUT': 
        return update_user(
                        id, 
                        name=request.form['name'], 
                        email=request.form['email'],
                        bio=request.form['bio'])
Ejemplo n.º 3
0
def user_show_update_delete(id):
    if request.method == 'GET':
        return get_user(id)
    if request.method == 'PUT':
        return update_user(id=id,
                           name=request.form['name'],
                           email=request.form['email'],
                           nickname=request.form['nickname'])
    if request.method == 'DELETE':
        return destroy_user(id)
Ejemplo n.º 4
0
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,
                             security.SECRET_KEY,
                             algorithms=[security.ALGORITHM])
        id_user: int = payload.get("sub")
        if id_user is None:
            raise credentials_exception
        token_data = token_schema.TokenPayload(**payload)
    except jwt.JWTError:
        raise credentials_exception
    user = user_crud.get_user(db, user_id=token_data.sub)
    if not user:
        raise HTTPException(status_code=404, detail="User not found")
    return user
Ejemplo n.º 5
0
def user_get_one(id):
    return get_user(id)