class Role(db.Model): id = db.Column(db.Integer, primary_key=True) group = db.Column(db.String(60), unique=True, nullable=False) description = db.Column(db.String(120), nullable=False) def __repr__(self): return f"Role('{self.group}')"
class Link(db.Model): id = db.Column(db.Integer, primary_key=True) linkname = db.Column(db.String(100), unique=True, nullable=False) url = db.Column(db.String(255), unique=True, nullable=False) group = db.Column(db.String(100), nullable=False) def __repr__(self): return f"Link('{self.linkname}', '{self.group}')"
class Post(db.Model): id = db.Column("id", db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) datePosted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.datePosted}')"
class Customer(db.Model): id = db.Column(db.INTEGER, primary_key=True) customerName = db.Column(db.String(100)) customerAge = db.Column(db.INTEGER) customerDOB = db.Column(db.String(50)) serviceOfficerName = db.Column(db.String(50)) NRIC = db.Column(db.String(20)) registrationTime = db.Column(db.String(50), default="25/09/20 00:00:00") branchCode = db.Column(db.INTEGER) productType = db.Column(db.String(100))
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) is_admin = db.Column(db.Boolean, nullable=False, default=False) rights = db.relationship('Role', secondary=access, backref=db.backref('members', lazy='dynamic')) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')" def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id)
class User(db.Model, UserMixin): id = db.Column("id", db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(100), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default="default.png") password = db.Column(db.String(60), nullable=False) posts = db.relationship("Post", backref="author", lazy=True) def get_reset_token(self, expire_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expire_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) about_me = db.Column(db.String(140)) last_seen = db.Column(db.DateTime, default=datetime.utcnow) is_admin = db.Column(db.Boolean, default=False) def __repr__(self): return '<User {}>'.format(self.username) def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) def avatar(self, size): digest = md5(self.email.lower().encode('utf-8')).hexdigest() return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format( digest, size) @staticmethod def verify_reset_password_token(token): try: id = jwt.decode(token, app.config['SECRET_KEY'], algorithms=['HS256'])['reset_password'] except: return return User.query.get(id) def generate_auth_token(self, expiration): s = Serializer(current_app.config['SECRET_KEY'], expires_in=expiration) return s.dumps({'id': self.id}).decode('utf-8') @staticmethod def verify_auth_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: data = s.loads(token) except: return None return User.query.get(data['id'])
from datetime import datetime from itsdangerous import TimedJSONWebSignatureSerializer as Serializer from flask import current_app from WebApp import db, login_manager from flask_login import UserMixin @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) access = db.Table('access', db.Column('user_id', db.Integer, db.ForeignKey('user.id')), db.Column('role_id', db.Integer, db.ForeignKey('role.id'))) #class User(db.Model): class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) is_admin = db.Column(db.Boolean, nullable=False, default=False) rights = db.relationship('Role', secondary=access, backref=db.backref('members', lazy='dynamic'))