<commit_before>from datetime import datetime

from werkzeug.security import generate_password_hash, check_password_hash

from . import db

class User(db.Model):
  __tablename__ = 'users'
  id            = db.Column(db.Integer, primary_key=True, autoincrement=True)
  email         = db.Column(db.String(64), 
                            nullable=False, 
                            unique=True, 
                            index=True)
  username      = db.Column(db.String(64), 
                            nullable=False, 
                            unique=True, 
                            index=True)
  is_admin      = db.Column(db.Boolean)
  password_hash = db.Column(db.String(128))
  name          = db.Column(db.String(64))
  member_since  = db.Column(db.DateTime(), default = datetime.utcnow)

  @property
  def password(self):
    raise AttributeError('Password is not a readable attribute')
  
  @password.setter
  def password(self, password):
    self.password_hash = generate_password_hash(password)

  def verify_password(self, password):
    return check_password_hash(self.password_hash, password)<commit_msg>Add user_loader function for loading a user<commit_after>from datetime import datetime

from flask.ext.login import UserMixin

from werkzeug.security import generate_password_hash, check_password_hash

from . import db, login_manager

class User(UserMixin, db.Model):
  __tablename__ = 'users'
  id            = db.Column(db.Integer, primary_key=True, autoincrement=True)
  email         = db.Column(db.String(64), 
                            nullable=False, 
                            unique=True, 
                            index=True)
  username      = db.Column(db.String(64), 
                            nullable=False, 
                            unique=True, 
                            index=True)
  is_admin      = db.Column(db.Boolean)
  password_hash = db.Column(db.String(128))
  name          = db.Column(db.String(64))
  member_since  = db.Column(db.DateTime(), default = datetime.utcnow)

  @property
  def password(self):
    raise AttributeError('Password is not a readable attribute')

  @login_manager.user_loader
  def load_user(user_id):
    return User.query.get(int(user_id))
  
  @password.setter
  def password(self, password):
    self.password_hash = generate_password_hash(password)

  def verify_password(self, password):
    return check_password_hash(self.password_hash, password)
{'fraction_non_alphanumeric': 0.09031467102574581, 'fraction_numerical': 0.0073559460563955865, 'mean_word_length': 2.32157394843962, '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': '563983', 'n_tokens_mistral': 719, 'n_tokens_neox': 689, 'n_words': 140}