<commit_before># -*- coding: utf-8 -*-
"""User views."""
from flask import Blueprint, request
from flask_apispec import use_kwargs, marshal_with
from flask_jwt_extended import jwt_required, jwt_optional, create_access_token, current_user
from sqlalchemy.exc import IntegrityError

from remixvr.database import db
from remixvr.exceptions import InvalidUsage
from remixvr.extensions import cors
from remixvr.profile.models import UserProfile
from .models import User
from .serializers import user_schema
import re

blueprint = Blueprint('user', __name__)


@blueprint.route('/api/users', methods=('POST',))
@use_kwargs(user_schema)
@marshal_with(user_schema)
def register_user(username, password, email, **kwargs):
    try:
        school_id = kwargs.pop('school_id')
        userprofile = UserProfile(
            User(username.lower(), email.lower(), password=password, **kwargs).save()).save()
        userprofile.user.token = create_access_token(identity=userprofile.user)

        if school_id:
            userprofile.school_id = school_id
            userprofile.save()
    except IntegrityError:
        db.session.rollback()
        raise InvalidUsage.user_already_registered()
    return userprofile.user


@blueprint.route('/api/users/login', methods=('POST',))
@jwt_optional
@use_kwargs(user_schema)
@marshal_with(user_schema)<commit_msg>fix access token issue on backend<commit_after># -*- coding: utf-8 -*-
"""User views."""
from flask import Blueprint, request
from flask_apispec import use_kwargs, marshal_with
from flask_jwt_extended import jwt_required, jwt_optional, create_access_token, current_user
from sqlalchemy.exc import IntegrityError

from remixvr.database import db
from remixvr.exceptions import InvalidUsage
from remixvr.extensions import cors
from remixvr.profile.models import UserProfile
from .models import User
from .serializers import user_schema
import re

blueprint = Blueprint('user', __name__)


@blueprint.route('/api/users', methods=('POST',))
@use_kwargs(user_schema)
@marshal_with(user_schema)
def register_user(username, password, email, **kwargs):
    try:
        school_id = kwargs.pop('school_id')
        userprofile = UserProfile(
            User(username.lower(), email.lower(), password=password, **kwargs).save()).save()
        if school_id:
            userprofile.school_id = school_id
            userprofile.save()
        userprofile.user.token = create_access_token(identity=userprofile.user)
    except IntegrityError:
        db.session.rollback()
        raise InvalidUsage.user_already_registered()
    return userprofile.user


@blueprint.route('/api/users/login', methods=('POST',))
@jwt_optional
@use_kwargs(user_schema)
@marshal_with(user_schema)
{'fraction_non_alphanumeric': 0.10460405156537753, 'fraction_numerical': 0.0007366482504604051, 'mean_word_length': 4.69392033542977, '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': '790297', 'n_tokens_mistral': 805, 'n_tokens_neox': 782, 'n_words': 188}