<commit_before># -*- coding: utf-8 -*-
from flask import render_template
from flask import request
from flask import url_for
from flask import redirect
from flask import session
from passlib.hash import pbkdf2_sha256
from database import *


def do_login(db_pwd, user_id, username='', passwd=''):
    if username not in get_all_user_names():
        raise ValueError("Invalid Username or Password")
    if not pbkdf2_sha256.verify(passwd, db_pwd):
        raise ValueError("Invalid Username or Password")
    session['logged_in'] = True
    session['user_id'] = user_id


# def verify_login(func):
#     def wrapper(*args, **kwargs):
#         if not session['logged_in']:
#             return redirect(url_for('show_login'))
#         else:
#             func(*args, **kwargs)
#     return wrapper


@app.route('/')
def show_login():
    return render_template('login.html')


@app.route('/login', methods=['GET', 'POST'])
def register():
    error = None
    if request.method == 'POST':
        try:
            if request.form['toggle'] == 'register':
                insert_user(request.form['username'],
                            pbkdf2_sha256.encrypt(request.form['password']),
                            request.form['email'])
                user_data = get_login_user(request.form['username'])
                do_login(user_data[0]['user_passwd'], user_data[0]['user_id'],
                         request.form['username'], request.form['password'])
                return redirect(url_for('show_lists_register_sucess'))
            else:
                user_data = get_login_user(request.form['username'])
                if user_data == []:
                    raise ValueError
                do_login(user_data[0]['user_passwd'], user_data[0]['user_id'],
                         request.form['username'], request.form['password'])
                if session['logged_in']:
                    return redirect(url_for('show_lists'))
        except ValueError:
            error = "Invalid Username or Password"
    return render_template('login.html', error=error)


@app.route('/lists/all', methods=['GET'])
def show_lists():
    lists = get_all_users_lists(session['user_id'])
    user = get_user_name(session['user_id'])
    message = "%s's Lists" % user
    return render_template('list_all.html', lists=lists,<commit_msg>made new_register a sepearate function<commit_after># -*- coding: utf-8 -*-
from flask import render_template
from flask import request
from flask import url_for
from flask import redirect
from flask import session
from passlib.hash import pbkdf2_sha256
from database import *


def do_login(db_pwd, user_id, username='', passwd=''):
    if username not in get_all_user_names():
        raise ValueError("Invalid Username or Password")
    if not pbkdf2_sha256.verify(passwd, db_pwd):
        raise ValueError("Invalid Username or Password")
    session['logged_in'] = True
    session['user_id'] = user_id


# def verify_login(func):
#     def wrapper(*args, **kwargs):
#         if not session['logged_in']:
#             return redirect(url_for('show_login'))
#         else:
#             func(*args, **kwargs)
#     return wrapper


@app.route('/')
def show_login():
    return render_template('login.html')


@app.route('/login', methods=['GET', 'POST'])
def register():
    error = None
    if request.method == 'POST':
        try:
            if request.form['toggle'] == 'register':
                return new_register()
            else:
                user_data = get_login_user(request.form['username'])
                if user_data == []:
                    raise ValueError
                do_login(user_data[0]['user_passwd'], user_data[0]['user_id'],
                         request.form['username'], request.form['password'])
                if session['logged_in']:
                    return redirect(url_for('show_lists'))
        except ValueError:
            error = "Invalid Username or Password"
    return render_template('login.html', error=error)


def new_register():
    insert_user(request.form['username'],
                            pbkdf2_sha256.encrypt(request.form['password']),
                            request.form['email'])
    user_data = get_login_user(request.form['username'])
    do_login(user_data[0]['user_passwd'], user_data[0]['user_id'],
             request.form['username'], request.form['password'])
    return redirect(url_for('show_lists'))


@app.route('/lists/all', methods=['GET'])
def show_lists():
    lists = get_all_users_lists(session['user_id'])
    user = get_user_name(session['user_id'])
    message = "%s's Lists" % user
    return render_template('list_all.html', lists=lists,
{'fraction_non_alphanumeric': 0.1326943556975506, 'fraction_numerical': 0.00724174653887114, 'mean_word_length': 2.74780526735834, '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': '7496112', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1323, 'n_words': 293}