Ejemplo n.º 1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True)
    email = db.Column(db.String(120), unique=True)
    password = db.Column(db.String(128))
    about_me = db.Column(db.String(10000))
    created = db.Column(db.DateTime, default=datetime.utcnow())
    firstname = db.Column(db.String(50))
    lastname = db.Column(db.String(50))
    password_code = db.Column(db.String(50))
    posts = db.relationship("Post", back_populates="user")
    role = db.relationship('Role', secondary=users_roles, backref=db.backref('users', lazy='dynamic'))

    def __str__(self):
        return self.username
Ejemplo n.º 2
0
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.png')  # profile picture
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)  # makes reference of user connected to post

    # 30 minutes to allow for password reset
    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')

    # verify the reset
    @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)

    # how object is printed
    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
Ejemplo n.º 3
0
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.png")
    password = db.Column(db.String(60), nullable=False)
    post = db.relationship('Post', backref='author', lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(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}')"
Ejemplo n.º 4
0
class WhiteHeaderWithButton(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    header_text = db.Column(db.String, nullable=False)
    button_text = db.Column(db.String, nullable=False)
    button_url = db.Column(db.String, nullable=False)
    order_whiteheaderwithbutton = db.Column(db.Integer)
    whiteheaderwithbutton_id = db.Column(db.Integer, db.ForeignKey(UniversalPage.id))
    whiteheaderwithbutton = db.relationship(UniversalPage, backref='whiteheaderwithbutton')
Ejemplo n.º 5
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    intro = db.Column(db.String(200))
    body = db.Column(db.Text(), nullable=False)
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)

    user_name = db.Column(db.Integer, db.ForeignKey('user.username'))
    user = db.relationship("User", back_populates="posts")

    @property
    def slugified_title(self):
        return slugify(self.title)

    def __repr__(self):
        return 'Post {}'.format(self.title)