예제 #1
0
def deleteUser(user: User):
    _userLogger.info(f"Processing Delete:{user.username}")
    query = users.objects(username=user.username)
    if query.count() == 0:
        _userLogger.info(
            f"Username {user.username} does not exists to delete. Raising Exception."
        )
        raise HTTPException(
            status_code=HTTPStatus.CONFLICT,
            detail=f"The user {user.username} does not exist or is not logged in",
        )
    _userLogger.info(f"User Exists. Checking if logged in of {user.username}")
    db_user = query[0]
    if not db_user.logged_in:
        raise HTTPException(
            status_code=HTTPStatus.CONFLICT,
            detail=f"The user {user.username} does not exist or is not logged in.",
        )
    try:
        _hasher.verify(db_user.password, user.password)
    except (VerificationError, VerifyMismatchError):
        raise HTTPException(
            status_code=HTTPStatus.CONFLICT,
            detail=f"The user {user.username} does not exist or is not logged in.",
        )
    users.delete(db_user)
    _userLogger.info(f"Successfully deleted {user.username}")
    return {"detail": f"Successfully deleted {user.username}"}
예제 #2
0
def getPublicKey(username: str):
    query = users.objects(username=username)
    if query.count() == 0:
        raise HTTPException(
            status_code=HTTPStatus.CONFLICT,
            detail=f"The user {username} does not exist",
        )
    return {"detail": query[0].public_key}
예제 #3
0
def loggedIn(request: Request, address: str = Form("address")):
    """Returns True or False depending on a users logged in state

    Args:
        username (str): Username to be checked

    Returns:
        bool: True if logged in, False if logged out.
    """
    if not request.client.host == Config.Potion_IP:
        raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED)
    query = users.objects(logged_in=address)
    return True if query.count() > 0 else False
예제 #4
0
def loginUser(request: Request, user: User):
    _userLogger.info(f"Logging in {user.username} with key {user.api_key}")
    if not Helper.validate_APIKey(user.api_key):
        raise HTTPException(
            status_code=HTTPStatus.BAD_REQUEST, detail="Invalid API Key"
        )
    query = users.objects(username=user.username)

    if query.count() == 0:
        raise HTTPException(
            status_code=HTTPStatus.BAD_REQUEST,
            detail="Invalid password or username",
        )
    db_user = query[0]
    try:
        _hasher.verify(db_user.password, user.password)
    except (VerificationError, VerifyMismatchError):
        raise HTTPException(
            status_code=HTTPStatus.BAD_REQUEST,
            detail="Invalid Password or username",
        )
    db_user.logged_in = request.client.host
    db_user.save()
    return {"detail": f"Successful Login for {user.username}"}
예제 #5
0
def usernameExists(username: str):
    query = users.objects(username=username)
    if query.count() > 0:
        return {"detail": "true"}
    return {"detail": "false"}