<commit_before>from flask import Blueprint, request, session, g, redirect, url_for, abort, \
                  render_template, flash, make_response

from .forms import RegisterForm

forum = Blueprint('forum', __name__)


@forum.route('/')
def index():
    return render_template('forum.html')



@forum.route('/user')
def user():
    form = RegisterForm()
    return render_template('user.html', form=form)


@forum.route('/login', methods=['GET', 'POST'])
def login():
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        password = form.password.data
        repassword = form.repassword.data

        if repassword:
            if password == repassword:
                # create account
                # login
                flash('Account created')
            form.errors['re-password'] = ['Password does not match']
            return render_template('login.html', form=form)
                
        # login

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

<commit_msg>login logout logic in views<commit_after>from flask import Blueprint, request, session, g, redirect, url_for, abort, \
                  render_template, flash

from .models import User, Session, UserExistsError
from .forms import RegisterForm
from .auth import login_user, logout_user


forum = Blueprint('forum', __name__)


@forum.route('/')
def index():
    return render_template('forum.html')


@forum.route('/user')
def user():
    form = RegisterForm()
    return render_template('user.html', form=form)


@forum.route('/login', methods=['GET', 'POST'])
def login():
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        password = form.password.data
        repassword = form.repassword.data

        if repassword:
            if password != repassword:
                form.errors['re-password'] = ['Password does not match']
                return render_template('login.html', form=form)
            try:
                user = User.create(username, password)
                flash('Account created', 'success')
                login_user(username, password)
                return redirect(url_for('.index'))
            except UserExistsError:
                form.errors['username'] = ['Username already exists']

        if login_user(username, password):
            return redirect(url_for('.index'))

        form.errors['authentication'] = ['wrong username or password']

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


@forum.route('/logout')
def logout():
    session_key = session.get('s_key', None)
    if session_key:
        uid = Session.get(session_key)['user']
        user = User.get(uid)
        logout_user(user)
    return redirect(url_for('.index'))

{'fraction_non_alphanumeric': 0.12486809708054872, 'fraction_numerical': 0.0, 'mean_word_length': 2.641485275288092, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1829357', 'n_tokens_mistral': 800, 'n_tokens_neox': 758, 'n_words': 196}