예제 #1
0
def logout(_):
    print("[Server] User {0} logged out".format(auth.get_username()))
    # Set session in database to logged out
    auth.logout()
    # Expire the session cookie
    dash.callback_context.response.set_cookie('session', '', expires=0)
    return "Logout successful!"
예제 #2
0
def set_username(_):
    """
    Sets the session's username in the right column.

    :returns: the current username (string)
    """
    if auth.is_authorized():
        return auth.get_username()
예제 #3
0
def set_greeting(_):
    """
    Sets the username and adds admin distinction is user is admin.

    :returns: username and if admin admin distrinction (string)
    """
    username = auth.get_username()
    addition = '' if not auth.is_admin() else " (admin)"
    return "Hello {0}{1}".format(username, addition)
예제 #4
0
def change_password(_, __, password):
    """
    Change the current user's password.

    :param password: new user password
    :returns: success or error messge, new value for password input box
    """
    username = auth.get_username()
    if auth.change_password(username, password):
        return ["Password change successful!", ""]
    else:
        return ["Not authorized to do that, please log in again", ""]
예제 #5
0
def insert_schedule_tests_button(n):
    """
    Inserts the button for scheduling a new test and inserts test scheduling
    when button is clicked.

    :param n: number of clicks of button
    :returns: html.Button if authorized, None otherwise
    """
    # Catch non authorized requests
    if not auth.is_authorized() or not auth.is_admin():
        return
    # None means page load
    if n is None:
        return html.Button('Schedule now', className='topbar-button')
    # n=1 means first click on button
    if n == 1:
        by = auth.get_username()
        add_test_scheduling(by)
        return html.Button('Scheduled', className='topbar-button')