Example #1
0
def login():
    """
    Dummy implementation.
    The real login is to be implemented by Ben & co :)
    """
    from main import app
    from main import User

    if request.method == "POST":
        # get parameters
        data = request.get_json(force=True)
        username = data.get('username')
        password = data.get('password')

        user = User.check_password(username, password)
        if user is not None:
            # remember=True means that the session will remember a user.
            # If not set, the user will be deleted from the session once the browser tab is closed
            login_user(user, remember=True)
            return jsonify({'status': 'success', 'user_data': user.to_json()})
        else:
            # what if connection to LDAP failed?
            return jsonify({
                'status': 'error',
                'error': 'Incorrect username or password'
            })

    # if GET, return index.html
    return app.send_static_file('index.html')
Example #2
0
def main():

    user = User('John', 'password', '*****@*****.**', '12/25/1999')
    print(user.username)
    print(user.password)
    print(user)
    print()
    print(repr(user))

    user2 = User("John", "password", "*****@*****.**", "12/25/1999")
    print(user == user2)
    print(user.check_password('1234'))

    user.username = '******'
    print(user.username)

    superuser = SuperUser('jon', 'password', '*****@*****.**', '12/24/1999',
                          'admin')

    print(superuser)
    print()
    print(repr(superuser))

    print('ran demo.main')