Esempio n. 1
0
def test_auth():
    clear()
    # Testing register and authentication works
    result = auth.auth_register('*****@*****.**', 'abc123', 'Nick Patrikeos')
    assert result
    assert auth.authenticate_token(result['token']) == result['u_id']

    # Test logout works
    assert auth.auth_logout(result['token']) == {'is_success': True}
    assert not auth.authenticate_token(result['token'])

    # Test logging back in works
    login_result = auth.auth_login('*****@*****.**', 'abc123')
    assert login_result
    assert auth.authenticate_token(login_result['token']) == result['u_id']
Esempio n. 2
0
def logout():
    token = request.args.get('token')

    if token and auth.authenticate_token(token):
        functions.deleteActiveToken(token)

    return render_template('index.html')
Esempio n. 3
0
def authenticate_page(token, page):
    if token is None or not auth.authenticate_token(token):
        return render_template('index.html')
    if not functions.validateTokenPermissions(token, page):
        return render_template('homepage.html',
                               permission_denied=True,
                               token=token)

    return False
Esempio n. 4
0
def admin():
    token = request.args.get('token')

    if token and auth.authenticate_token(token):
        return render_template('homepage.html',
                               token=token,
                               permission_denied=False)

    return render_template('index.html')
Esempio n. 5
0
def profile():
    token = request.args.get('token')

    if token is None or not auth.authenticate_token(token):
        return render_template('index.html')

    if request.method == 'POST':
        form = request.form

        email = form['email']
        dietaries = form['dietaries']
        roomshown = form.get('roomshown')
        user.user_update(token, email, dietaries, roomshown)

    client = user.user_profile(token)
    outstanding_meals = latemeals.latemeals_oustanding_resident(client['id'])

    return render_template('profile.html',
                           user=client,
                           token=token,
                           outstandingMeals=outstanding_meals)