<commit_before># -*- coding: utf-8 -*-

from flask import (Blueprint, render_template, request, g, redirect, url_for,
                   flash)
from flask_babel import gettext

from db import db_session
from journalist_app.utils import (make_password, set_diceware_password,
                                  validate_user)


def make_blueprint(config):
    view = Blueprint('account', __name__)

    @view.route('/account', methods=('GET',))
    def edit():
        password = make_password(config)
        return render_template('edit_account.html',
                               password=password)

    @view.route('/new-password', methods=('POST',))
    def new_password():
        user = g.user
        current_password = request.form.get('current_password')
        token = request.form.get('token')
        error_message = gettext('Incorrect password or two-factor code.')
        # If the user is validated, change their password
        if validate_user(user.username, current_password, token,
                         error_message):
            password = request.form.get('password')
            set_diceware_password(user, password)
        return redirect(url_for('account.edit'))

    @view.route('/2fa', methods=('GET', 'POST'))
    def new_two_factor():
        if request.method == 'POST':
            token = request.form['token']
            if g.user.verify_token(token):
                flash(gettext("Token in two-factor authentication verified."),
                      "notification")
                return redirect(url_for('account.edit'))
            else:
                flash(gettext(
                    "Could not verify token in two-factor authentication."),
                      "error")

        return render_template('account_new_two_factor.html', user=g.user)

    @view.route('/reset-2fa-totp', methods=['POST'])
    def reset_two_factor_totp():
        g.user.is_totp = True
        g.user.regenerate_totp_shared_secret()
        db_session.commit()
        return redirect(url_for('account.new_two_factor'))

    @view.route('/reset-2fa-hotp', methods=['POST'])<commit_msg>journalist: popped relevant session variables in new-password route to log the user out<commit_after># -*- coding: utf-8 -*-

from flask import (Blueprint, render_template, request, g, redirect, url_for,
                   flash, session)
from flask_babel import gettext

from db import db_session
from journalist_app.utils import (make_password, set_diceware_password,
                                  validate_user)


def make_blueprint(config):
    view = Blueprint('account', __name__)

    @view.route('/account', methods=('GET',))
    def edit():
        password = make_password(config)
        return render_template('edit_account.html',
                               password=password)

    @view.route('/new-password', methods=('POST',))
    def new_password():
        user = g.user
        current_password = request.form.get('current_password')
        token = request.form.get('token')
        error_message = gettext('Incorrect password or two-factor code.')
        # If the user is validated, change their password
        if validate_user(user.username, current_password, token,
                         error_message):
            password = request.form.get('password')
            set_diceware_password(user, password)
            session.pop('uid', None)
            session.pop('expires', None)
        return redirect(url_for('account.edit'))

    @view.route('/2fa', methods=('GET', 'POST'))
    def new_two_factor():
        if request.method == 'POST':
            token = request.form['token']
            if g.user.verify_token(token):
                flash(gettext("Token in two-factor authentication verified."),
                      "notification")
                return redirect(url_for('account.edit'))
            else:
                flash(gettext(
                    "Could not verify token in two-factor authentication."),
                      "error")

        return render_template('account_new_two_factor.html', user=g.user)

    @view.route('/reset-2fa-totp', methods=['POST'])
    def reset_two_factor_totp():
        g.user.is_totp = True
        g.user.regenerate_totp_shared_secret()
        db_session.commit()
        return redirect(url_for('account.new_two_factor'))

    @view.route('/reset-2fa-hotp', methods=['POST'])
{'fraction_non_alphanumeric': 0.11808873720136519, 'fraction_numerical': 0.0018202502844141069, 'mean_word_length': 2.348057882711348, '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': '2747624', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1165, 'n_words': 258}