<commit_before>#   imports    #
from flask import flash, redirect, render_template, request, url_for, Blueprint
from flask_login import login_user, login_required, logout_user

import controller as user_controller
from slot.users.models import User
from .forms import LoginForm

#    config    #
users_blueprint = Blueprint(
        'users', __name__,
        template_folder='templates')


#    routes    #
@users_blueprint.route('/login', methods=['GET', 'POST'])
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            if user_controller.validate_credentials(request.form['username'],
                                                    request.form['password']):
                user = User('slot', 'test')
                login_user(user)
                flash('You were logged in.')
                return redirect(url_for('dashboard'))
            else:
                flash('Invalid credentials. Try again.')
    return render_template('login.html', form=form, error=error)


@users_blueprint.route('/logout')
@login_required
def logout():
    logout_user()
    flash('You were logged out.')
    return redirect(url_for('users.login'))<commit_msg>Update users.views to make use of new function.<commit_after>#   imports    #
from flask import flash, redirect, render_template, request, url_for, Blueprint
from flask_login import login_user, login_required, logout_user

import controller as user_controller
from slot.users.models import User
from .forms import LoginForm

#    config    #
users_blueprint = Blueprint(
        'users', __name__,
        template_folder='templates')


#    routes    #
@users_blueprint.route('/login', methods=['GET', 'POST'])
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():

            user = user_controller.return_user_if_valid_credentials(
                request.form['username'],
                request.form['password'])

            if user:
                login_user(user)
                flash('You were logged in.')
                return redirect(url_for('dashboard'))

            else:
                flash('Invalid credentials. Try again.')

    return render_template('login.html', form=form, error=error)


@users_blueprint.route('/logout')
@login_required
def logout():
    logout_user()
    flash('You were logged out.')
    return redirect(url_for('users.login'))
{'fraction_non_alphanumeric': 0.10969285999202234, 'fraction_numerical': 0.0, 'mean_word_length': 2.72106824925816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5858636', 'n_tokens_mistral': 690, 'n_tokens_neox': 672, 'n_words': 172}