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

"""
byceps.blueprints.user.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2014 <NAME>
"""

from datetime import datetime

from flask import abort, g, request, session, url_for

from ...database import db
from ...util.framework import create_blueprint, flash_error, flash_success
from ...util.image import Dimensions, guess_type as guess_image_type, \
    read_dimensions
from ...util.templating import templated
from ...util import upload
from ...util.views import redirect_to, respond_no_content

from ..authorization.models import Role
from ..terms.models import Consent, ConsentContext

from .forms import AvatarImageUpdateForm, CreateForm, LoginForm
from .models import User, VerificationToken, VerificationTokenPurpose


blueprint = create_blueprint('user', __name__)


@blueprint.before_app_request
def before_request():
    g.current_user = UserSession.get_user()


@blueprint.route('/<id>')
@templated
def view(id):
    """Show a user's profile."""
    user = find_user_by_id(id)
    return {'user': user}


@blueprint.route('/create')
@templated
def create_form(errorneous_form=None):
    """Show a form to create a user."""
    form = errorneous_form if errorneous_form else CreateForm()
    return {'form': form}


@blueprint.route('/', methods=['POST'])
def create():
    """Create a user."""
    form = CreateForm(request.form)
    if not form.validate():
        return create_form(form)

    screen_name = form.screen_name.data
    email_address = form.email_address.data
    password = form.password.data
    consent_to_terms = form.consent_to_terms.data

    user = User.create(screen_name, email_address, password)
    db.session.add(user)

    verification_token = VerificationToken(
        user, VerificationTokenPurpose.email_address_confirmation)
    db.session.add(verification_token)

    terms_consent = Consent(user, ConsentContext.account_creation)
    db.session.add(terms_consent)
<commit_msg>Abort account creation if screen name or email address are already assigned to an existing account.<commit_after># -*- coding: utf-8 -*-

"""
byceps.blueprints.user.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2014 <NAME>
"""

from datetime import datetime

from flask import abort, g, request, session, url_for

from ...database import db
from ...util.framework import create_blueprint, flash_error, flash_success
from ...util.image import Dimensions, guess_type as guess_image_type, \
    read_dimensions
from ...util.templating import templated
from ...util import upload
from ...util.views import redirect_to, respond_no_content

from ..authorization.models import Role
from ..terms.models import Consent, ConsentContext

from .forms import AvatarImageUpdateForm, CreateForm, LoginForm
from .models import User, VerificationToken, VerificationTokenPurpose


blueprint = create_blueprint('user', __name__)


@blueprint.before_app_request
def before_request():
    g.current_user = UserSession.get_user()


@blueprint.route('/<id>')
@templated
def view(id):
    """Show a user's profile."""
    user = find_user_by_id(id)
    return {'user': user}


@blueprint.route('/create')
@templated
def create_form(errorneous_form=None):
    """Show a form to create a user."""
    form = errorneous_form if errorneous_form else CreateForm()
    return {'form': form}


@blueprint.route('/', methods=['POST'])
def create():
    """Create a user."""
    form = CreateForm(request.form)
    if not form.validate():
        return create_form(form)

    screen_name = form.screen_name.data
    email_address = form.email_address.data
    password = form.password.data
    consent_to_terms = form.consent_to_terms.data

    email_address_already_assigned = User.query \
        .filter_by(email_address=email_address) \
        .first() is not None
    if email_address_already_assigned:
        flash_error(
            'Diese E-Mail-Adresse ist bereits einem Benutzerkonto zugeordnet.')
        return create_form(form)

    screen_name_already_assigned = User.query \
        .filter_by(screen_name=screen_name) \
        .first() is not None
    if screen_name_already_assigned:
        flash_error(
            'Dieser Benutzername ist bereits einem Benutzerkonto zugeordnet.')
        return create_form(form)

    user = User.create(screen_name, email_address, password)
    db.session.add(user)

    verification_token = VerificationToken(
        user, VerificationTokenPurpose.email_address_confirmation)
    db.session.add(verification_token)

    terms_consent = Consent(user, ConsentContext.account_creation)
    db.session.add(terms_consent)

{'fraction_non_alphanumeric': 0.11447738584721921, 'fraction_numerical': 0.0038952607660679506, 'mean_word_length': 4.15273132664437, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6424525', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1380, 'n_words': 349}