Ejemplo n.º 1
0
def register():
    """Render the form to register a new user.

    The function renders the registration form and stores its values
    if the current user submitted the form.
    """

    from .forms import RegisterForm

    form = RegisterForm(request.form)

    if form.validate_on_submit():
        username = request.form['username']
        password = request.form['password1']
        app.add_user_and_password(username, password)
        logger.info('Created account for ' + username + '.')

        if "rememberMe" in request.form:
            user = User()
            user.id = username
            session['username'] = username
            session['registrations'] = []
            login_user(user, remember=True)
            logger.info('Logged ' + username + ' in after account creation.')

        return redirect(url_for('home'))

    return render_template('signup.html', form=form)
Ejemplo n.º 2
0
def request_loader(request):
    """Callback function for reloading a user from a Flask request.

    The function takes the Flask request and returns a user object
    or None if the user does not exist.
    """

    if 'user_id' in session:
        logger.info(session['user_id'])
        user = User()
        user.id = session['user_id']
        user.registrations = app.load_config(user.id)
        return user
    return
Ejemplo n.º 3
0
def user_loader(username):
    """Callback function for reloading a user from the session.

    The function takes the username and returns a user object
    or None if the user does not exist.
    """

    users = app.users
    if username not in users:
        return

    user = User()
    user.id = username
    user.registrations = app.load_config(username)
    return user
Ejemplo n.º 4
0
def login():
    """Render the login page and check login credentials.

    The function renders the login form and checks if username
    does exist and the provided password is correct when the user
    submits his or her data.
    """

    from .forms import LoginForm

    form = LoginForm(request.form)
    if form.validate_on_submit():
        username = request.form['username']
        user = User()
        user.id = username
        login_user(user, remember=True)
        logger.info(username + ' successfully logged in.')
        response = redirect(request.args.get("next") or url_for("home"))
        return response
    else:
        return render_template('login.html', form=form)