Пример #1
0
async def sign_in(
        api_key: Optional[str] = Header(None),
        x_access_token: Optional[str] = Header(None),
):
    auth_service.verify_api_key(api_key)
    auth_service.verify_access_token(x_access_token)
    return {"message": "ok"}
Пример #2
0
async def unblock_user(uuid: int,
                       db: Session = Depends(get_db),
                       api_key: Optional[str] = Header(None)):
    auth_service.verify_api_key(api_key)
    user = RegisteredUserDAO.get_user(db, uuid)
    auth_service.unblock_user(user['email'])
    unblocked_user = RegisteredUserDAO.unblock_user(db, uuid)
    return unblocked_user
Пример #3
0
async def get_user_uuid(
        db: Session = Depends(get_db),
        api_key: Optional[str] = Header(None),
        x_access_token: Optional[str] = Header(None),
):
    auth_service.verify_api_key(api_key)
    user_data = auth_service.verify_access_token(x_access_token)
    user = RegisteredUserDAO.get_by_email(db, user_data["email"])
    return user
Пример #4
0
async def delete_registered_user(
        uuid: int,
        db: Session = Depends(get_db),
        api_key: Optional[str] = Header(None),
        x_access_token: Optional[str] = Header(None),
):
    auth_service.verify_api_key(api_key)
    auth_service.verify_access_token(x_access_token)
    user = RegisteredUserDAO.delete_by_uuid(db, uuid)
    return user
Пример #5
0
async def add_registered_user(
        payload: RegisteredUserSchema,
        db: Session = Depends(get_db),
        api_key: Optional[str] = Header(None),
        x_access_token: Optional[str] = Header(None),
):
    auth_service.verify_api_key(api_key)
    auth_service.verify_access_token(x_access_token)
    user = RegisteredUserDAO.add_new_registered_user(db, payload, False)
    return user
Пример #6
0
async def add_registered_admin(
        payload: RegisteredUserSchema,
        db: Session = Depends(get_db),
        api_key: Optional[str] = Header(None),
        x_access_token: Optional[str] = Header(None),
):
    # Check API-KEY
    auth_service.verify_api_key(api_key)

    # Check that x-access-token is from a registered admin
    user_data = auth_service.verify_access_token(x_access_token)
    RegisteredUserDAO.get_admin_by_email(db, user_data["email"])

    # Create the new admin
    user = RegisteredUserDAO.add_new_registered_user(db, payload, True)
    return user
Пример #7
0
async def get_all_admin_users(db: Session = Depends(get_db),
                              api_key: Optional[str] = Header(None)):
    auth_service.verify_api_key(api_key)
    users = RegisteredUserDAO.get_all_admins(db)
    return {"amount": len(users), "users": users}