<commit_before>from application import db
from flask import request, jsonify, url_for, g, Blueprint
from flask.ext.restful import abort

from application.authorization.models import User
from application.decorators import public_endpoint


bp = Blueprint('api', __name__)


@bp.route('/api/login')
def get_auth_token():
    token = g.user.generate_auth_token(600)
    return jsonify({'token': token.decode('ascii'), 'duration': 600})


@bp.route('/api/users', methods=['POST'])
@public_endpoint
def new_user():
    json_data = request.get_json()
    username = json_data.get('username')
    password = <PASSWORD>_data.<PASSWORD>('password')

    if username is None or password is None:
        print("Abort - username or password is None.")
        abort(400)  # missing arguments
    if User.query.filter_by(username=username).first() is not None:
        print("Abort - user already exists.")
        abort(400)  # existing user

    user = User(username=username)
    user.hash_password(password)
    db.session.add(user)<commit_msg>Enhance Registration view<commit_after>from application import db
from flask import request, jsonify, url_for, g, Blueprint
from flask.ext.restful import abort

from application.authorization.models import User
from application.decorators import public_endpoint


bp = Blueprint('api', __name__)


@bp.route('/api/login')
def get_auth_token():
    token = g.user.generate_auth_token(600)
    return jsonify({'token': token.decode('ascii'), 'duration': 600})


@bp.route('/api/users', methods=['POST'])
@public_endpoint
def new_user():
    json_data = request.get_json()
    username = json_data.get('username')
    password = <PASSWORD>_data.get('password')
    first_name = json_data.get('firstName')
    last_name = json_data.get('lastName')

    if username is None or password is None:
        print("Abort - username or password is None.")
        abort(400)  # missing arguments
    if User.query.filter_by(username=username).first() is not None:
        print("Abort - user already exists.")
        abort(400)  # existing user

    user = User(username=username, first_name=first_name, last_name=last_name)
    user.hash_password(password)
    db.session.add(user)
{'fraction_non_alphanumeric': 0.1213218650973291, 'fraction_numerical': 0.010864644635581712, 'mean_word_length': 4.249406175771972, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '3217288', 'n_tokens_mistral': 686, 'n_tokens_neox': 653, 'n_words': 169}