Beispiel #1
0
def change_username(profile_id: int, username: str):
    profile = Profile.get_or_none(Profile.username == username)
    if profile is not None:
        raise BadRequest('A user with this username already exists')
    try:
        update_username = Profile.update({
            Profile.username: username
        }).where(Profile.id == profile_id)
        update_username.execute()
    except Exception as e:
        raise BadRequest('Failure to change username: {}'.format(str(e)))
Beispiel #2
0
def ban_user(profile_id: int):
    rows = Profile.update({
        Profile.is_banned: True
    }).where(Profile.id == profile_id).execute()
    if rows == 0:
        raise BadRequest("Cannot ban user")

    profile = Profile.get_or_none(Profile.id == profile_id)
    if not profile:
        raise BadRequest("Profile not found")
    print("BANNED PROFILE IS BANNED:", profile.is_banned)

    broadcast(profile, "ban",
              "Your account has been banned for violating our policy.", True)
Beispiel #3
0
def change_password(profile: Profile, old_password: str, new_password: str):
    if not bcrypt.checkpw(old_password.encode(),
                          profile.hashed_password.encode()):
        raise BadRequest('Incorrect old password')
    hashed_new_password = bcrypt.hashpw(new_password.encode(),
                                        bcrypt.gensalt()).decode()
    try:
        update_password = Profile.update({
            Profile.hashed_password:
            hashed_new_password
        }).where(Profile.id == profile.id)
        update_password.execute()
    except Exception as e:
        raise BadRequest('Failure to change password: {}'.format(str(e)))