Ejemplo n.º 1
0
def delete(secret: schemas.SecretDelete, token, db: Session = Depends(get_db)):
    tokenValid = token_is_valid(token)
    if tokenValid:
        userRequest = getUser(db, tokenValid)
        if userRequest:
            crud.delete_secret(db, secret.id)
        if not validate_if_logged(db, userRequest.id):
            return schemas.ServerResult(status='not logged',
                                        ok=False,
                                        forceLogin=False)
    return schemas.ServerResult(status='sucess', ok=True, forceLogin=True)
Ejemplo n.º 2
0
def change_password( user:schemas.UserPassword,token, db:Session = Depends(get_db)):
    userAuth = Token().decodeToken(token)
    if not userAuth:
        raise HTTPException(status_code=401, detail='unauthorized')
    userToUpdate = crud.getUser_by_email(db, userAuth['email'])
    if not userToUpdate:
        raise HTTPException(status_code=401, detail='user not found')
    if not validate_if_logged(db,userToUpdate.id):
        return schemas.ServerResult(status='not logged', ok=False, forceLogin= False)
    userUpdated = crud.updateUser(db,userToUpdate= userToUpdate,email=userToUpdate.email,name=userToUpdate.name,
                                  password=user.password)
    return schemas.ServerResult(status='sucess', ok=True, forceLogin= True)
Ejemplo n.º 3
0
def getSecrests_By_User(token, db: Session = Depends(get_db)):
    tokenValid = token_is_valid(token)
    if tokenValid:
        userRequest = getUser(db, tokenValid)
        if userRequest:
            items = crud.getSecrets_by_user(db, userRequest.id)
        if not validate_if_logged(db, userRequest.id):
            return schemas.ServerResult(status='not logged',
                                        ok=False,
                                        forceLogin=False)
    return schemas.ServerResult(status='sucess',
                                ok=True,
                                forceLogin=True,
                                data=items)
Ejemplo n.º 4
0
def edit_name_email(user:schemas.UserBase,token, db: Session = Depends(get_db)):
    tokenAuth = Token().decodeToken(token)
    if not tokenAuth:
       raise HTTPException(status_code=401, detail="unauthorized") 
    userRquest = crud.getUser_by_email(db, email= tokenAuth['email'])
    if not userRquest:
        raise HTTPException(status_code=401, detail='User not found')
    if not validate_if_logged(db,userRquest.id):
        return schemas.ServerResult(status='not logged', ok=False, forceLogin= False)
    #'userToUpdate' is the memory position
    userUpdated = crud.updateUser(db,userToUpdate= userRquest, **user.dict(),password=userRquest.password)
    newToken = Token().generateToken(sub=userUpdated.id,userName=userUpdated.name,
                                       email=userUpdated.email, forceLogin=True)
    #update to login
    crud.update_token_user(db,newToken, userRquest.id)
    return schemas.ServerResult(status='sucess', ok=True, forceLogin= True ,token=newToken)