<commit_before>from flask_restful import Resource
from flask import jsonify, request, url_for

from app.puppenc import api, db, app, PuppencResource
from app.decorators import *

from app.users.models import User
from app.users.schema import UserSchema

class Users(PuppencResource):
    def __init__(self):
        self.user_schema = UserSchema()
        self.users_schema = UserSchema(many=True)

    """
    @api {post} /users Create a user
    @apiName post_user
    @apiGroup Users
    @apiVersion 1.0.0
    @apiPermission public
    @apiParam   {String}    name              (json document) The user's name
    @apiParam   {Password}  password          (json document)The users's password
    @apiSuccess {String}    name              The user's name
    @apiExample {curl} Example usage :
        curl -X POST -H "Content-Type: application/json" \
        -d '{"name":"my_username","password":"<PASSWORD>"}' \
        http://127.0.0.1:5000/api/v1/users
    """
    def post(self):
        name = request.json.get('name')
        password = request.json.get('password')
        if name is None or password is None:
            abort(400) # missing arguments
        if User.query.filter_by(name = name).first() is not None:
            abort(400) # existing user
        user = User(name = name)
        user.hash_password(password)
        db.session.add(user)
        db.session.commit()
        app.logger.info("Create user %s", user.name)
        return { 'name': user.name }, 200

    """
    @api {get} /users/<id> Get a single user
    @apiVersion 1.0.0
    @apiName get_user
    @apiGroup Users
    @apiParam   {Number}    id                The user's id
    @apiSuccess {String}    name              The user's name
    @apiPermission public
    @apiExample {curl} Example usage :
        curl -X GET -H "Content-Type: application/json" \
        http://127.0.0.1:5000/api/v1/users/1
    """
    def get(self, id):
        user = User.query.get(id)
        if not user:
            abort(400)
        return jsonify({'name': user.name})


class Tokens(PuppencResource):
    def __init__(self):
        self.user_schema = UserSchema()
        self.users_schema = UserSchema(many=True)

    """
    @api {get} /tokens/<id> Get a token
    @apiName get_token
    @apiGroup Tokens
    @apiVersion 1.0.0
    @apiPermission user
    @apiSuccess {String}    token              The token
    @apiParam   {Number}    duration           Pass a custom duration (seconds)
    @apiSuccess {Number}    duration           The token's validity
    @apiExample {curl} Example usage :
        curl -X GET -H "Content-Type: application/json" \
        http://127.0.0.1:5000/api/v1/tokens
    """
    @auth.login_required
    def get(self):
        token = g.user.generate_auth_token()
        duration = int(request.args.get('duration', app.config['AUTH_DURATION']))
        app.logger.info("Generate a token for %s", g.user)
        return jsonify({'token': token.decode('ascii'), 'duration': duration})
<commit_msg>Fix wrong duration<commit_after>from flask_restful import Resource
from flask import jsonify, request, url_for

from app.puppenc import api, db, app, PuppencResource
from app.decorators import *

from app.users.models import User
from app.users.schema import UserSchema

class Users(PuppencResource):
    def __init__(self):
        self.user_schema = UserSchema()
        self.users_schema = UserSchema(many=True)

    """
    @api {post} /users Create a user
    @apiName post_user
    @apiGroup Users
    @apiVersion 1.0.0
    @apiPermission public
    @apiParam   {String}    name              (json document) The user's name
    @apiParam   {Password}  password          (json document)The users's password
    @apiSuccess {String}    name              The user's name
    @apiExample {curl} Example usage :
        curl -X POST -H "Content-Type: application/json" \
        -d '{"name":"my_username","password":"<PASSWORD>"}' \
        http://127.0.0.1:5000/api/v1/users
    """
    def post(self):
        name = request.json.get('name')
        password = request.json.get('password')
        if name is None or password is None:
            abort(400) # missing arguments
        if User.query.filter_by(name = name).first() is not None:
            abort(400) # existing user
        user = User(name = name)
        user.hash_password(password)
        db.session.add(user)
        db.session.commit()
        app.logger.info("Create user %s", user.name)
        return { 'name': user.name }, 200

    """
    @api {get} /users/<id> Get a single user
    @apiVersion 1.0.0
    @apiName get_user
    @apiGroup Users
    @apiParam   {Number}    id                The user's id
    @apiSuccess {String}    name              The user's name
    @apiPermission public
    @apiExample {curl} Example usage :
        curl -X GET -H "Content-Type: application/json" \
        http://127.0.0.1:5000/api/v1/users/1
    """
    def get(self, id):
        user = User.query.get(id)
        if not user:
            abort(400)
        return jsonify({'name': user.name})


class Tokens(PuppencResource):
    def __init__(self):
        self.user_schema = UserSchema()
        self.users_schema = UserSchema(many=True)

    """
    @api {get} /tokens/<id> Get a token
    @apiName get_token
    @apiGroup Tokens
    @apiVersion 1.0.0
    @apiPermission user
    @apiSuccess {String}    token              The token
    @apiParam   {Number}    duration           Pass a custom duration (seconds)
    @apiSuccess {Number}    duration           The token's validity
    @apiExample {curl} Example usage :
        curl -X GET -H "Content-Type: application/json" \
        http://127.0.0.1:5000/api/v1/tokens
    """
    @auth.login_required
    def get(self):
        duration = int(request.args.get('duration', app.config['AUTH_DURATION']))
        token = g.user.generate_auth_token(expiration=duration)
        app.logger.info("Generate a token for %s", g.user)
        return jsonify({'token': token.decode('ascii'), 'duration': duration})

{'fraction_non_alphanumeric': 0.1175206611570248, 'fraction_numerical': 0.01818181818181818, 'mean_word_length': 2.3083652268999453, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '3580927', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1827, 'n_words': 492}