Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. from datetime import datetime
  2. from app import db, bcrypt
  3.  
  4.  
  5. class User(db.Model):
  6.     __tablename__ = "user"
  7.     id = db.Column('id', db.Integer, primary_key=True)            # Stores the user id
  8.     username = db.Column('username', db.String(50), unique=True)  # Stores the username
  9.     lastname = db.Column('lastname', db.String(50))               # Stores the lastname
  10.     secondname = db.Column('secondname', db.Sting(50))            # Stores the secondname
  11.     firstname = db.Column('firstname', db.String(50))             # Stores the firstname
  12.     email = db.Column('email', db.String(255), unique=True)       # Stores the mail address
  13.     iconpath = db.Column('iconpath', db.String(255))              # Stores the filepath for the user profile image
  14.     role = db.Column('role', db.String(2))                        # Stores the role (Admin='SU' Normal="NO")
  15.     password = db.Column('password', db.String(10))               # Stores the password
  16.     lastlogin = db.Column('lastlogin', db.Datetime)               # Stores the latest login date
  17.     lastorDer = db.Column('lastorder', db.Integer)                # Stores the LastorderID
  18.     active = db.Column('active', db.Boolean)                      # is user active or not
  19.  
  20.     def __init__(self, username, lastname, secondname, firstname, email, iconpath, role, password, lastorder, active):
  21.         self.username = username
  22.         self.lastname = lastname
  23.         self.secondname = secondname
  24.         self.firstname = firstname
  25.         self.email = email
  26.         self.iconpath = iconpath
  27.         self.role = role
  28.         self.password = bcrypt.generate_password_hash(password)
  29.         self.lastlogin = datetime
  30.         self.lastorder = lastorder
  31.         self.active = active
  32.  
  33.     def dict(self):
  34.         return dict(
  35.             id=self.id,
  36.             role=self.role,
  37.             username=self.username,
  38.             password=self.password,
  39.             email=self.email
  40.         )
  41.  
  42.     def dict_extended(self):
  43.         return dict(
  44.             id=self.id,
  45.             role=self.role,
  46.             username=self.username,
  47.             password=self.password,
  48.             email=self.email,
  49.             accounts=self.getaccounts()
  50.         )
  51.  
  52.     def get_id(self):
  53.         return unicode(self.id)
  54.  
  55.     def dict_getName(self):
  56.         return dict(
  57.             id=self.id,
  58.             username=self.username
  59.         )
  60.  
  61.     def __repr__(self):
  62.         return '<User %r>' % self.username
  63.  
  64.     def is_active(self):
  65.         return True
  66.  
  67.     def is_authenticated(self):
  68.         return True
  69.  
  70.     def is_anonymous(self):
  71.         return False
  72.  
  73.     def getaccounts(self):
  74.         a = []
  75.         for account in self.accounts:
  76.             a.append(account.dict())
  77.         return a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement