예제 #1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    pic = db.Column(db.String(20), default="")
    username = db.Column(db.String(120),nullable = False, unique=True)
    email = db.Column(db.String(120),nullable = False, unique=True)
    password = db.Column(db.String(80), nullable = False)
    date_created = db.Column(db.DateTime, default = datetime.utcnow)
    texts = db.Column(db.Text, default="")
    tech = db.Column(db.Text, default="")
    gen = db.Column(db.Text, default="")

    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}')"
예제 #2
0
class Users(db.Model):
    """"""

    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column("username", db.String(64))
    display_name = db.Column("DisplayName", db.String(128))
    email = db.Column("Email", db.String(128))
    # spotify_username = db.Column("spotify_username", db.String(64))

    # saved_tracks_id = db.Column(db.Integer, db.ForeignKey("saved_tracks.id"))
    # saved_tracks = db.relationship("SavedTracks", backref="users")

    # top_artists_id = db.Column(db.Integer, db.ForeignKey("top_artists.id"))
    top_artists = db.relationship("TopArtists", backref="users")

    # top_tracks_id = db.Column(db.Integer, db.ForeignKey("top_tracks.id"))
    top_tracks = db.relationship("TopTracks", backref="users")

    # user_playlists_id = db.Column(db.Integer, db.ForeignKey("UserPlaylists.id"))
    # user_playlists = db.relationship(
    #     UserPlaylists, uselist=False, back_populates="users"
    # )

    # followed_artists_id = db.Column(db.Integer, db.ForeignKey("followed_artists.id"))
    # followed_artists = db.relationship("FollowedArtists", backref="users")

    def get_user_id(self):
        return self.id

    def get_username(self):
        return self.username
예제 #3
0
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)
    posts = db.relationship('Post', backref='author', lazy='dynamic')
    followed = db.relationship('User',
                               secondary=followers,
                               primaryjoin=(followers.c.follower_id == id),
                               secondaryjoin=(followers.c.followed_id == id),
                               backref=db.backref('followers', lazy='dynamic'),
                               lazy='dynamic')

    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=identicons&s={}'.format(
            digest, size)
예제 #4
0
class User(db.Model):
	id = db.Column(db.Integer,primary_key=True)
	username = db.Column(db.String(100))
	email_id= db.Column(db.String(50), unique=True)
	password = db.Column(db.String(100))
	access_level = db.Column(db.String(100))
	flag = db.Column(db.String(100))
예제 #5
0
class Role(db.Model):
    """
    Roles are an aggregate of permissions
    """
    __tablename__ = 'roles'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(64), unique=True)
    description = db.Column(db.String(280))
    default = db.Column(db.Boolean, default=False, index=True)
    permissions = db.Column(db.Integer)
    users = db.relationship('User', backref='role', lazy='dynamic')

    def __repr__(self):
        return '<Role: {}> \n'.format(self.name)

    @staticmethod
    def insert_roles():
        roles = {
            'Customer': (Permission.BUY, True),
            'Moderator': (Permission.BUY |
                          Permission.WRITE_BLOGS |
                          Permission.MODERATE_CONTENT, False),
            'Administrator': (0xff, False)
        }
        for r in roles:
            role = Role.query.filter_by(name=r).first()
            if role is None:
                role = Role(name=r)
            role.permissions = roles[r][0]
            role.default = roles[r][1]
            db.session.add(role)
        db.session.commit()
예제 #6
0
class Preview(db.Model):
    __tablename__='preview'
    id=db.Column(db.Integer,primary_key=True)
    title=db.Column(db.String(255),unique=True)
    logo=db.Column(db.String(255),unique=True)
    addtime=db.Column(db.DATETIME,index=True,default=datetime.datetime.now)
    def __repr__(self):
        return "preview %s"%self.title
    def preview_add(data):
        try:
            db.session.add(data)
            db.session.commit()
            return True
        except Exception as e:
            print(e)
            return False
    def preview_edit(id,data):
        try:
            preview=Preview.query.filter_by(id=id).first_or_404()
            preview.id=data.id
            preview.title=data.title
            preview.logo=data.logo
            db.session.add(preview)
            db.session.commit()
            return True
        except Exception as e:
            return False
    def preview_del(id):
        preview=Preview.query.filter_by(id=id).first_or_404()
        db.session.delete(preview)
        db.session.commit()
        return True
예제 #7
0
class Comments(db.Model):
    __tablename__ = 'comments'
    postId = db.Column(db.Integer)
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(500))
    email = db.Column(db.String(100))
    body = db.Column(db.String(5000))
예제 #8
0
class Flyreq(db.Model):
    __tablename__ = 'flyreqs'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(120), nullable=False)
    leaving_city = db.Column(db.String, nullable=False)
    arriving_city = db.Column(db.String, nullable=False)
    flightnumber = db.Column(db.String, nullable=True)
    requesttext = db.Column(db.Text, nullable=False)
    moneyamount = db.Column(db.String, nullable=False)
    event_date = db.Column(db.String, nullable=False)
    email = db.Column(db.String(120), nullable=False)

    def __init__(self, username, event_date, leaving_city, arriving_city,
                 flightnumber, requesttext, moneyamount, email):
        self.username = username
        self.event_date = event_date
        self.leaving_city = leaving_city
        self.arriving_city = arriving_city
        self.flightnumber = flightnumber
        self.requesttext = requesttext
        self.moneyamount = moneyamount
        self.email = email

    def __repr__(self):
        return '<Flyreq obj for user: {}.>'.format(self.username)
예제 #9
0
class Employee(UserMixin, db.Model):
    ''' Create an Employee table'''
    __tablename__ = 'employees'

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(60), index=True, unique=True)
    username = db.Column(db.String(60), index=True, unique=True)
    first_name = db.Column(db.String(60), index=True)
    last_name = db.Column(db.String(60), index=True)
    password_hash = db.Column(db.String(128))
    department_id = db.Column(db.Integer, db.ForeignKey('departments.id'))
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
    is_admin = db.Column(db.Boolean, default=False)

    @property
    def password(self):
        '''Prevent password from being accessed'''
        raise AttributeError('Password is not a readable attribute!')

    @password.setter
    def password(self, password):
        '''Set password to a hashed password'''
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        '''Check if hashed password matches actual password'''
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return '<Employee: {}>'.format(self.username)
예제 #10
0
class Role(db.Model):
    role_id = db.Column(db.String(7), primary_key=True)
    role_name = db.Column(db.String(255), nullable=False)
    user = db.relationship('User', backref='role', lazy=True)

    def __repr__(self) -> str:
        return '<Role %s>' % self.role_name
예제 #11
0
class Course(db.Model):
    __tablename__ = "courses"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    admin_id = db.Column(db.Integer, db.ForeignKey('admins.id'))
    content = db.Column(db.Text)
    videos = db.Column(db.Text)
    type = db.Column(db.Integer)
    module_id = db.Column(db.Integer, db.ForeignKey('modules.id'))
    cover = db.Column(db.String(255))
    collect_num = db.Column(db.Integer, default=0)
    view_num = db.Column(db.Integer, default=0)
    score = db.Column(db.Integer, default=0)
    created_at = db.Column(db.DateTime, default=datetime.now())
    module = db.relationship('Module')
    admin = db.relationship("Admin")
    users = db.relationship("User", secondary=user_course_table)

    def to_json(self):
        return {
            "id": self.id,
            "name": self.name,
            "admin": self.admin.to_json(),
            "content": self.content,
            "videos": self.videos,
            "type": self.type,
            "module": self.module.name,
            "score": self.score,
            "view_num": self.view_num,
            "collect_num": self.collect_num,
            "created_at": self.created_at,
            "cover": self.cover
        }
예제 #12
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(32), index=True)
    password_hash = db.Column(db.String(64))

    def hash_password(self, password):
        self.password_hash = pwd_context.encrypt(password)

    def verify_password(self, password):
        return pwd_context.verify(password, self.password_hash)

    def generate_auth_token(self, expiration=600):
        s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
        return s.dumps({'id': self.id})

    @staticmethod
    def verify_auth_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except SignatureExpired:
            return None  # valid token, but expired
        except BadSignature:
            return None  # invalid token
        user = User.query.get(data['id'])
        return user
예제 #13
0
class Student(db.Model, UserMixin):
    id = db.Column(db.Integer,primary_key=True)
    username = db.Column(db.String(25),nullable=False,unique=True)
    email = db.Column(db.String(30),nullable=False,unique=True)
    password = db.Column(db.String(100),nullable=False)
    gender = db.Column(db.String(5))
    birthday = db.Column(db.Date)
    phone = db.Column(db.BigInteger(),nullable=False,unique=True)
    image_file = db.Column(db.String(64),nullable=False,default='default.jpg')
    events = db.relationship('Event',secondary='student_events',backref='student',lazy='dynamic')


    def __repr__(self):
        return '<User %r>' % self.username

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

    @staticmethod
    def get_verify_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except itsdangerous.SignatureExpired:
            return None
        return Student.query.get(user_id)
예제 #14
0
class Photos(db.Model):
    __tablename__ = 'photos'
    albumId = db.Column(db.Integer)
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200))
    url = db.Column(db.String(300))
    thumbnailUrl = db.Column(db.String(300))
예제 #15
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    avatar = db.Column(db.String(255))
    sex = db.Column(db.String(10))
    age = db.Column(db.Integer)
    account = db.Column(db.String(100), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    describe = db.Column(db.Text)
    created_at = db.Column(db.DateTime, default=datetime.now())
    courses = db.relationship("Course", secondary=user_course_table)
    modules = db.relationship("Module", secondary=user_module_table)

    def to_json(self):
        return {
            "id": self.id,
            "account": self.account,
            "name": self.name,
            "avatar": self.avatar,
            "sex": self.sex,
            "age": self.age,
            "describe": self.describe,
            "created_at": self.created_at
        }
예제 #16
0
class Location(db.Model):
    __tablename__ = 'location'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.uid'))
    name = db.Column(db.String(100))
    address = db.Column(db.String(200))
    city = db.Column(db.String(50))
    state = db.Column(db.String(50))
    #country=db.column(db.String(50))
    zip = db.Column(db.String(20))
    lat = db.Column(db.Float)
    lng = db.Column(db.Float)
    is_end_point = db.Column(db.Integer, unique=False, default=0)

    def __init__(self, user_id, name, address, city, state, zip, lat, lng,
                 is_end_point):
        self.user_id = user_id
        self.name = name
        self.address = address
        self.city = city
        self.state = state
        #self.country=country
        self.zip = zip
        self.lat = lat
        self.lng = lng
        self.is_end_point = is_end_point
예제 #17
0
class Participant(UserMixin, db.Model):
    """create a  Participant table"""
    __tablename__ = 'participants'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), )
    email = db.Column(db.String(60), unique=True)
    password_hash = db.Column(db.String(128))
    is_admin = db.Column(db.Boolean, default=False)

    @property
    def password(self):
        """
        Prevent pasword from being accessed
        """
        raise AttributeError('password is not a readable attribute.')

    @password.setter
    def password(self, password):
        """
        Set password to a hashed password
        """
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        """
        Check if hashed password matches actual password
        """
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return '<Participant: {}>'.format(self.name)
예제 #18
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True)
    password = db.Column(db.String(64))
    role = db.Column(db.SmallInteger, default=ROLE_USER)
    posts = db.relationship('Post', backref='author', lazy='dynamic')
    about_me = db.Column(db.String(140))
    last_seen = db.Column(db.DateTime)

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return self.id

    def __repr__(self):
        return '<User %r>' % (self.username)

    @classmethod
    def login_check(cls, username, password):
        user = cls.query.filter(
            db.and_(User.username == username,
                    User.password == password)).first()
        if not user:
            return None
        return user
예제 #19
0
class News(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    news_title = db.Column(db.String(255), nullable=False)
    news_message = db.Column(db.String(255), nullable=False)
    news_file = db.Column(db.String(255), nullable=True)

    def __repr__(self) -> str:
        return '<Role %s>' % self.news_title
예제 #20
0
class User(Base):
    __tablename__ = 'user'
    email = db.Column(db.String(100), unique=True, nullable=False)
    password = db.Column(db.String(8), nullable=False)

    def __init__(self, email, password):
        self.email = email
        self.password = password
예제 #21
0
class Resource(db.Model):
    ip = db.Column(db.String, primary_key=True)
    username = db.Column(db.String(30), unique=True, nullable=False)
    password = db.Column(db.String(30), nullable=False)
    availability = db.Column(db.Boolean, nullable=False, default=True)

    def __repr__(self):
        return f"Resource('{self.ip}', '{self.username}', '{self.password}')"
예제 #22
0
class Book(db.Model):
    __tablename__ = 'book'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(40), nullable=False)
    author = db.Column(db.String(60), nullable=False)
    publish_date = db.Column(db.DateTime)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
예제 #23
0
class Player(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), unique=True, nullable=False)
    platform = db.Column(db.String(3), nullable=False)

    def __repr__(self):
        return ("Username : {} Platform : {}".format(self.username,
                                                     self.platform))
예제 #24
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), index=True, unique=True)
    location = db.Column(db.String(64))
    password_hash = db.Column(db.String(128))

    def __repr__(self):
        return '<User {}>'.format(self.name)
예제 #25
0
class Artists(db.Model):
    """"""

    __tablename__ = "artists"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column("name", db.String(64))
    uri = db.Column("uri", db.String(128))
예제 #26
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String(140))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    language = db.Column(db.String(5))

    def __repr__(self):
        return '<Post {}>'.format(self.body)
예제 #27
0
class User(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)
    pass_hash = db.Column(db.String(128))
    posts = db.relationship('Post', backref='author', lazy='dynamic')

    def __repr__(self):
        return '<User {} with {}>'.format(self.username, self.email)
예제 #28
0
파일: __init__.py 프로젝트: zvrr/ubackup
class Cluster(db.Model):
    __tablename__ = 'cluster'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True, nullable=False)
    queue_address = db.Column(db.String(255), nullable=False)
    queue_size = db.Column(db.Integer)

    def __repr__(self):
        return '<Cluster %r>' % self.name
예제 #29
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    uname = db.Column(db.String(30), nullable=False, unique=True)
    email = db.Column(db.String(40), unique=True, nullable=False)
    password_hash = db.Column(db.String, nullable=False)
    tasks = db.relationship("Task", backref="author", lazy=True)

    def __repr__(self):
        return f"User('{self.uname}','{self.email}')"
예제 #30
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(20), nullable=False)
    address = db.Column(db.String(80), nullable=False)
    password = db.Column(db.String(80), nullable=False)
    image = db.Column(db.String(80), nullable=False, default='default.jpd')

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image}','{self.address}')"