Ejemplo n.º 1
0
class Email(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    subject = db.Column(db.String(1024))
    body = db.Column(db.String(1024))

    def __repr__(self):
        return '<Email {}>'.format(self.subject)
Ejemplo n.º 2
0
class Trash(db.Model):
    uuid = db.Column(db.String(64), primary_key=True, default=default_uuid)
    idx = db.Column(db.Integer(), default=default_trash_index)
    views = db.Column(db.Integer(), default=0)
    title = db.Column(db.String(4096))
    content = db.Column(db.String(4096))
    highlight = db.Column(db.String(4096))
    password = db.Column(db.String(4096))
    is_public = db.Column(db.Boolean())
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<Trash {}>'.format(self.uuid)
class Flaskr(db.Model):

    __tablename__ = "flaskr"

    post_id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, nullable=False)
    text = db.Column(db.String, nullable=False)

    def __init__(self, title, text):
        self.title = title
        self.text = text

    def __repr__(self):
        return '<title {}>'.format(self.body)
Ejemplo n.º 4
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(255), index=True, unique=True)
    passhash = db.Column(db.String(255))
    trash = db.relationship('Trash',
                            backref='author',
                            lazy='dynamic',
                            order_by="desc(Trash.idx)")

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def set_password(self, password):
        self.passhash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.passhash, password)
Ejemplo n.º 5
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    is_admin = db.Column(db.Boolean(), default=False)
    passhash = db.Column(db.String(128))
    reset_q = db.Column(db.String(1024))
    reset_a = db.Column(db.String(1024))

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def set_password(self, password):
        self.passhash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.passhash, password)

    def check_reset(self, response, token):

        return hashlib.sha1(self.username.encode('utf-8')).hexdigest() == token

        return False

    def is_authenticated(self):
        return self.id > 0
Ejemplo n.º 6
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_name = db.Column(db.String(64), unique=True)
    user_pass = db.Column(db.String(256))
    user_firstname = db.Column(db.String(64))
    user_lastname = db.Column(db.String(64))
    user_signature = db.Column(db.String(64))
    user_mailbox = db.Column(db.String(64), unique=True)

    def __init__(self, name=None, password=None, firstname=None, lastname=None, signature=None, mailbox=None, id=None):
        super().__init__()
        if id:
            self.id = id
        self.user_name = name
        self.user_pass = generate_password_hash(password)
        self.user_firstname = firstname
        self.user_lastname = lastname
        self.user_signature = signature
        self.user_mailbox = mailbox

    def change_password(self, password):
        self.user_pass = generate_password_hash(password)
        db.session.commit()

    def check_password(self, password):
        return check_password_hash(self.user_pass, password)

    def update_user(self, firstname=None, lastname=None, signature=None):
        self.user_firstname = firstname
        self.user_lastname = lastname
        self.user_signature = signature
        db.session.commit()

    @staticmethod
    def register_user(new_user):
        db.session.add(new_user)
        db.session.commit()

    def __repr__(self):
        return "<User(user_name='%s',  user_pass='******', user_firstname='%s' user_lastname='%s')>" % (self.user_name, self.user_pass, self.user_firstname, self.user_lastname)