<commit_before>from main import db, app
from passlib.apps import custom_app_context as pwd_context
from itsdangerous import (TimedJSONWebSignatureSerializer
                          as Serializer, BadSignature, SignatureExpired)


class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    password_hash = db.Column(db.String(128))
    email = db.Column(db.String(120), unique=True)
    admin = db.Column(db.Boolean)
    active = db.Column(db.Boolean)

    def __init__(self, username, password, email, admin=False, active=False):
        self.username = username
        self.email = email
        self.admin = admin
        self.hash_password(password)
        self.active = active

    def to_dict(self):
        dict = self.__dict__
        del dict['_sa_instance_state']
        del dict['password_hash']
        return dict

    def hash_password(self, password):
        self.password_hash = pwd_context.encrypt(password)

    def verify_password(self, password):
        return pwd_context.verify(password, self.password_hash)

    def generate_auth_token(self, expiration=600):
        s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
        return s.dumps({'id': self.id, "admin": self.admin, "username": self.username})

    @staticmethod
    def verify_auth_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except SignatureExpired:
            return None  # valid token, but expired
        except BadSignature:
            return None  # invalid token
        user = User.query.get(data['id'])
        return user

    @staticmethod
    def get_required_attributes():
        return ['username', 'password', 'email']

    @staticmethod
    def get_admin_accounts():
        return User.query.filter_by(admin=True).all()
<commit_msg>Make token valid for 30 minutes<commit_after>from main import db, app
from passlib.apps import custom_app_context as pwd_context
from itsdangerous import (TimedJSONWebSignatureSerializer
                          as Serializer, BadSignature, SignatureExpired)


class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    password_hash = db.Column(db.String(128))
    email = db.Column(db.String(120), unique=True)
    admin = db.Column(db.Boolean)
    active = db.Column(db.Boolean)

    def __init__(self, username, password, email, admin=False, active=False):
        self.username = username
        self.email = email
        self.admin = admin
        self.hash_password(password)
        self.active = active

    def to_dict(self):
        dict = self.__dict__
        del dict['_sa_instance_state']
        del dict['password_hash']
        return dict

    def hash_password(self, password):
        self.password_hash = pwd_context.encrypt(password)

    def verify_password(self, password):
        return pwd_context.verify(password, self.password_hash)

    def generate_auth_token(self, expiration=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
        return s.dumps({'id': self.id, "admin": self.admin, "username": self.username})

    @staticmethod
    def verify_auth_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except SignatureExpired:
            return None  # valid token, but expired
        except BadSignature:
            return None  # invalid token
        user = User.query.get(data['id'])
        return user

    @staticmethod
    def get_required_attributes():
        return ['username', 'password', 'email']

    @staticmethod
    def get_admin_accounts():
        return User.query.filter_by(admin=True).all()

{'fraction_non_alphanumeric': 0.10368841888057777, 'fraction_numerical': 0.006448284756254836, 'mean_word_length': 2.893574297188755, 'pattern_counts': {'":': 4, '<': 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': '6553921', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1119, 'n_words': 257}