Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime
- from app import db, bcrypt
- class User(db.Model):
- __tablename__ = "user"
- id = db.Column('id', db.Integer, primary_key=True) # Stores the user id
- username = db.Column('username', db.String(50), unique=True) # Stores the username
- lastname = db.Column('lastname', db.String(50)) # Stores the lastname
- secondname = db.Column('secondname', db.Sting(50)) # Stores the secondname
- firstname = db.Column('firstname', db.String(50)) # Stores the firstname
- email = db.Column('email', db.String(255), unique=True) # Stores the mail address
- iconpath = db.Column('iconpath', db.String(255)) # Stores the filepath for the user profile image
- role = db.Column('role', db.String(2)) # Stores the role (Admin='SU' Normal="NO")
- password = db.Column('password', db.String(10)) # Stores the password
- lastlogin = db.Column('lastlogin', db.Datetime) # Stores the latest login date
- lastorDer = db.Column('lastorder', db.Integer) # Stores the LastorderID
- active = db.Column('active', db.Boolean) # is user active or not
- def __init__(self, username, lastname, secondname, firstname, email, iconpath, role, password, lastorder, active):
- self.username = username
- self.lastname = lastname
- self.secondname = secondname
- self.firstname = firstname
- self.email = email
- self.iconpath = iconpath
- self.role = role
- self.password = bcrypt.generate_password_hash(password)
- self.lastlogin = datetime
- self.lastorder = lastorder
- self.active = active
- def dict(self):
- return dict(
- id=self.id,
- role=self.role,
- username=self.username,
- password=self.password,
- email=self.email
- )
- def dict_extended(self):
- return dict(
- id=self.id,
- role=self.role,
- username=self.username,
- password=self.password,
- email=self.email,
- accounts=self.getaccounts()
- )
- def get_id(self):
- return unicode(self.id)
- def dict_getName(self):
- return dict(
- id=self.id,
- username=self.username
- )
- def __repr__(self):
- return '<User %r>' % self.username
- def is_active(self):
- return True
- def is_authenticated(self):
- return True
- def is_anonymous(self):
- return False
- def getaccounts(self):
- a = []
- for account in self.accounts:
- a.append(account.dict())
- return a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement