コード例 #1
0
def channel_details(token, channel_id):
    registeredUsersDB = load_user()
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = load_channel()

    email = token_to_email(token)
    if not is_loggedIn(loggedInUsersDB, email):
        raise AccessError(
            description=
            "You must be logged in to view the details of a channel!")

    u_id = token_to_u_ID(loggedInUsersDB, token)
    channelDictionary = get_channel_details(channelsDB, u_id, channel_id)
    save_channel()
    return channelDictionary
コード例 #2
0
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}
コード例 #3
0
def auth_login(email, password):
    registeredUsersDB = load_user()
    loggedInUsersDB = get_global_loggedInUsers()
    channelsDB = load_channel()

    check_valid_email(email)
    check_valid_password(password)
    password = hashPassword(password)

    # Check if the email and password belongs to a registered user
    userDictionary = get_registered_user(registeredUsersDB, email, password)
    # Set the reset code to be none, in case this log in was right after resetting password
    userDictionary['reset_code'] = None
    u_id = get_u_ID(registeredUsersDB, email)

    if not is_loggedIn(loggedInUsersDB, email):
        loggedInUsersDB.append(userDictionary)
        make_online(channelsDB, u_id)
        save_channel()

    userDictionary = generateUserDictionary(email, password)
    token = generateToken(userDictionary)

    return {'u_id': u_id, 'token': token}
コード例 #4
0
import pytest
import server.token_functions as TF
import server.user_functions as UF
import server.channel_functions as CF
import server.user_helper_functions as UHF
import server.helperFunctions as HF
from server.global_variables import reset_data, load_user
from server.auth_functions import auth_login, auth_register, auth_logout

reset_data()
A = auth_register("*****@*****.**", "wsad1990", "Good", "Morning")
databaseListDict = load_user()
'''Invalid token'''


def test_photo_invalidToken():
    token = None
    img_url = "http://ichef.bbci.co.uk/onesport/cps/480/mcs/media/images/57210000/jpg/_57210683_57210682.jpg"
    x_start = 0
    y_start = 0
    x_end = 200
    y_end = 200
    base = 5001

    with pytest.raises(TypeError):
        UF.user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end,
                                     y_end, base)


def test_photo_invalidBase():
    reset_data()