def admin_permission_change(token, u_id, permission_id):
	if permission_id > MEMBER() or permission_id < OWNER():
		raise ValueError(description="Invalid Permission ID")

	registeredUsersDB = get_global_registeredUsers()
	channelsDB = get_global_existingChannels()

	appointerID = token_to_u_ID(registeredUsersDB, token)
	appointerID = int(appointerID)
	u_id = int(u_id)
	permission_id = int(permission_id)
	appointerPID = get_user_permission(appointerID)
	u_PID = get_user_permission(u_id)

	if appointerPID > permission_id:
		raise ValueError(description="You are not permitted to change a user to higher permission!")

	if appointerPID > u_PID:
		raise ValueError(description="You cannot change a permission of a user with higher permission than you")

	registeredUsersDB = get_global_registeredUsers()
	for user in registeredUsersDB:
		if user['u_id'] == u_id:
			user['permission_id'] = permission_id
			promote_to_owner_all_channels(channelsDB, u_id)
			save_registered_users()
			return {}


	raise ValueError(description=f"User with the user id {u_id} not found")
def auth_passwordreset_reset(code, password):
    registeredUsersDB = get_global_registeredUsers()

    check_valid_reset_code(code)
    check_valid_password(password)

    for user in registeredUsersDB:
        if user['reset_code'] == code:
            user['password'] = hashPassword(password)
            user['reset_code'] = None
            save_registered_users()
            return {}

    raise ValueError(description="Please try again")
示例#3
0
def update_profile_photo(databaseListDict,channelsDB, u_id, local_url):
	for user in databaseListDict:
		if user['u_id'] == u_id:
			user['profile_img_url'] = local_url
			save_registered_users()
			for channel in channelsDB:
				for owner in channel['owner_members']:
					if owner['u_id'] == u_id:
						#UPDATE
						owner['profile_img_url'] = local_url
						save_channel()
				for member in channel['other_members']:
					if member['u_id'] == u_id:
						#UPDATE
						member['profile_img_url'] = local_url
						save_channel()
def user_profile(token, u_id):
    registeredUsersDB = get_global_registeredUsers()
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()

    email = token_to_email(token)

    if not is_loggedIn(loggedInUsersDB, email):
        raise AccessError(
            description="You must be logged in to view a profile!")

    viewerID = token_to_u_ID(registeredUsersDB, token)

    userDictionary = get_user_profile(registeredUsersDB, u_id)
    save_registered_users()
    return userDictionary
def user_profile_sethandle(token, handle):
    registeredUsersDB = get_global_registeredUsers()
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()

    email = token_to_email(token)
    if not is_loggedIn(loggedInUsersDB, email):
        raise AccessError(
            description="You must be logged in to change your handle")

    check_valid_handle(registeredUsersDB, handle)

    u_id = token_to_u_ID(registeredUsersDB, token)

    update_handle(registeredUsersDB, u_id, handle)
    save_registered_users()
    return {}
示例#6
0
def update_name(userDB, channelsDB, u_id, name_first, name_last):
	u_id = int(u_id)
	# update user in users dictionary
	for user in userDB:
		if user['u_id'] == u_id:
			user['name_first'] = name_first
			user['name_last'] = name_last
			save_registered_users()
	# update user in channels dictionary
	for channel in channelsDB:
		for owner in channel['owner_members']:
			if owner['u_id'] == u_id:
				#UPDATE
				owner['name_last'] = name_last
				owner['name_first'] = name_first
		for member in channel['other_members']:
			if member['u_id'] == u_id:
				#UPDATE
				member['name_last'] = name_last
				member['name_first'] = name_first
		save_channel()
def auth_register(email, password, firstName, lastName):
    registeredUsersDB = load_user()
    loggedInUsersDB = get_global_loggedInUsers()
    check_valid_name(firstName)
    check_valid_name(lastName)
    check_valid_email(email)
    check_valid_password(password)

    # Converts the passed name into a propoer name
    # -- starting with a capital letter followed by small letters
    firstName = convert_legible_name(firstName)
    lastName = convert_legible_name(lastName)

    if is_already_registered(registeredUsersDB, email):
        raise ValueError(description='Email taken by another user')

    userHandle = generateUserHandle(registeredUsersDB, firstName, lastName)
    password = hashPassword(password)
    u_id = generateU_ID(userHandle)

    permission_id = generate_permission_id(email)
    # Generate a dictionary with the set values
    # and also set some required fields to none if not passed in
    registeredDictionary = generate_empty_user(handle=userHandle,
                                               email=email,
                                               password=password,
                                               u_id=u_id,
                                               first_name=firstName,
                                               last_name=lastName,
                                               permission_id=permission_id)
    registeredUsersDB.append(registeredDictionary)
    # Dictionary of email and password for token generation -- think of it as 'payload'
    userDictionary = generateUserDictionary(email, password)
    token = generateToken(userDictionary)
    # The user registered is now logged in
    loggedInUsersDB.append(registeredDictionary)

    save_registered_users()
    return {'u_id': u_id, 'token': token}
def user_profile_delete(token, password):
    registeredUsersDB = get_global_registeredUsers()
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = get_global_existingChannels()

    password = hashPassword(password)
    email = token_to_email(token)
    u_id = token_to_u_ID(registeredUsersDB, token)
    u_id = int(u_id)

    if not is_loggedIn(loggedInUsersDB, email):
        raise AccessError("You must be logged in to delete your account")

    delete_user(registeredUsersDB, u_id, password)
    delete_user(loggedInUsersDB, u_id, password)

    for channel in channelsDB:
        remove_user_from_channel(channelsDB, u_id, channel['channel_id'])

    save_channel()
    save_registered_users()
    return {}