コード例 #1
0
class Objects(db.Model):
    """
    Vehicles
    """
    nid = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), unique=True)
    valid_from = db.Column(db.DateTime, default=datetime.utcnow)
    valid_to = db.Column(db.DateTime)
    created_by = db.Column(db.Integer)
    provider_id = db.Column(db.Integer, db.ForeignKey('providers.nid'))
    created = db.Column(db.DateTime(timezone=True))
    nofqueries = db.Column(db.Integer)
    nofsqueries = db.Column(db.Integer)
    lastquery = db.Column(db.DateTime(timezone=True))
    active = db.Column(db.Boolean)
    # backref for locations. Attention at backref!!!
    locations = db.relationship('Location', backref='object', lazy='dynamic')

    def __init__(
        self,
        name,
    ):
        self.name = name

    def __repr__(self):
        return 'Vehicle : %s' % (self.name, )
コード例 #2
0
ファイル: models.py プロジェクト: uros-5/flask-football-forum
class Videos(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    naslov = db.Column(db.String(80), nullable=False)
    podforum = db.Column(db.String(30), nullable=False)
    objavljeno = db.Column(db.DateTime(),
                           nullable=False,
                           default=lambda: datetime.datetime.utcnow())
    slika = db.Column(db.String(255), nullable=False)
    dl_link = db.Column(db.String(80), nullable=False)
    objavio = db.Column(db.Integer(), db.ForeignKey("users.id"))
    url_view = db.Column(db.String(60),
                         nullable=False,
                         unique=True,
                         default=lambda nbytes=16: secrets.token_hex(nbytes))
    korisnici = db.relationship('Users',
                                backref=db.backref('objavio', lazy='dynamic'))

    def __init__(self, naslov, podforum, dl_link, objavio=1):
        self.naslov = naslov
        self.podforum = podforum
        self.dl_link = dl_link
        self.objavio = objavio
        self.slika = ""

    def __repr__(self):
        return str(self.id)

    def __str__(self):
        return str(self.id)

    def get_time_for_index(podforum):
        obj = Videos.query.filter(Videos.podforum == podforum).order_by(
            Videos.id.desc()).first()
        vreme = (datetime.datetime.utcnow() - obj.objavljeno).total_seconds()
        return vreme
コード例 #3
0
class Product(db.Model):
    __tablename__ = 'products'
    id = db.Column(db.Integer, primary_key=True)
    sku = db.Column(db.String(200))
    name = db.Column(db.String(200))
    description = db.Column(db.Text)
    brand = db.Column(db.String(200))
    price = db.Column(db.Float)
    category_id = db.Column(db.Integer,
                            db.ForeignKey('categories.id'),
                            nullable=False)
    file = db.Column(db.String(200))
    created = db.Column(db.DateTime(timezone=False),
                        nullable=False,
                        default=datetime.utcnow())
    deleted = db.Column(db.Integer, default=0)

    def __init__(self, sku, name, description, brand, price, category_id, file,
                 deleted):
        self.sku = sku
        self.name = name
        self.description = description
        self.brand = brand
        self.price = price
        self.category_id = category_id
        self.file = file
        self.deleted = deleted

    # '[<Product 'producto1'>, <Product 'producto2'>]'
    def __repr__(self):
        return '<Product %r>' % (self.name)

    @property
    def serialize(self):
        return {'id': self.id, 'price': self.price, 'name': self.name}
コード例 #4
0
class NuxtApiUsers(db.Model):
    __tablename__ = 'nuxt_api_users'

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(255), nullable=False)
    registered_on = db.Column(db.DateTime())
    signed_in = db.Column(db.DateTime())

    def __init__(self, email, password):
        self.email = email
        self.password = bcrypt.generate_password_hash(password)
        self.registered_on = datetime.now()
        self.signed_in = datetime.now()

    def password_check(self, pw_hash, candidate):
        return bcrypt.check_password_hash(pw_hash, candidate)

    def encode_auth_token(self, email, hash_password):
        """Generates the Auth Token"""
        try:
            payload = {
                email: hash_password,
                'exp': datetime.utcnow() + timedelta(days=0, minutes=60),
                'iat': datetime.utcnow()
            }

            token = jwt.encode(payload,
                               app.config.get('SECRET_KEY'),
                               algorithm='HS256')
            print(token)
            return token

        except Exception as e:
            print(e)
            return e

    def decode_auth_token(self, token):
        try:
            decoded = jwt.decode(token,
                                 app.config.get('SECRET_KEY'),
                                 algorithm='HS256')
            return decoded

        except Exception as e:
            print(e)
            return e
コード例 #5
0
ファイル: models.py プロジェクト: uros-5/flask-football-forum
class KomentariNaVideu(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    komentar = db.Column(db.Text(400), nullable=False)
    napisano = db.Column(db.DateTime(),
                         nullable=False,
                         default=datetime.datetime.utcnow)
    video = db.Column(db.Integer(), db.ForeignKey("videos.id"))
    napisao = db.Column(db.Integer(), db.ForeignKey("users.id"))
    korisnici = db.relationship('Users',
                                backref=db.backref('napisao', lazy='dynamic'))

    def __repr__(self):
        return self.id
コード例 #6
0
ファイル: user.py プロジェクト: diegoavendano1998/Luuna-Test
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(200))
    # Hash the password
    password = db.Column(db.String(255))
    rol = db.Column(db.String(255))
    active = db.Column('is_active',
                       db.Boolean(),
                       nullable=False,
                       server_default='1')
    email = db.Column(db.String(255), nullable=False, unique=True)
    email_confirmed_at = db.Column(db.DateTime())
    # Relationships
    roles = db.relationship('Role', secondary='user_roles')

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.id)

    def __init__(self, username, password, rol, email):
        self.username = username
        self.password = password
        self.rol = rol
        self.email = email

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

    def check_password(self, password):
        # Check for the hashed password
        return check_password_hash(self.password, password)
コード例 #7
0
class Track(db.Model):
    __tablename__ = 'tracks'
    id = db.Column(db.Integer, primary_key=True)
    idUser = db.Column(db.Integer)
    user = db.Column(db.String(200))
    idProduct = db.Column(db.Integer)
    product = db.Column(db.String(200))
    view_at = db.Column(db.DateTime(timezone=False),
                        nullable=False,
                        default=datetime.utcnow())

    def __init__(self, idUser, user, idProduct, product):
        self.idUser = idUser
        self.user = user
        self.idProduct = idProduct
        self.product = product

    def __repr__(self):
        return '<Track %r>' % (self.name)
コード例 #8
0
ファイル: models.py プロジェクト: uros-5/flask-football-forum
class Users(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(10), nullable=False, unique=True)
    password = db.Column(db.String(), nullable=False)
    datum_registracije = db.Column(db.DateTime(),
                                   nullable=False,
                                   default=datetime.datetime.utcnow())
    uploader = db.Column(db.Boolean(), default=False)

    def __init__(self, username, password, uploader=False):
        self.username = username
        self.password = generate_password_hash(password)
        self.uploader = uploader

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymus(self):
        return False

    def get_id(self):
        return str(self.id)

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

    def __repr__(self):
        return self.id

    def is_uploader(self):
        return self.uploader

    def __str__(self):
        return str(self.id)
コード例 #9
0
class Location(db.Model):
    """
    Coords of vehicles at explicit time
    """
    nid = db.Column(db.Integer, primary_key=True)
    ts = db.Column(db.DateTime(timezone=True), nullable=False)
    object_id = db.Column(db.Integer, db.ForeignKey('objects.nid'))
    bssid = db.Column(db.String(50))
    longitude = db.Column(db.NUMERIC(precision=11, scale=6))
    latitude = db.Column(db.NUMERIC(precision=11, scale=6))
    azimuth = db.Column(db.NUMERIC(precision=10, scale=2))
    distance = db.Column(db.NUMERIC(precision=10, scale=2))
    other = db.Column(db.Text)

    def __init__(self, object_id, ts, longitude, latitude):
        self.object_id = object_id
        self.ts = ts
        self.longitude = longitude
        self.latitude = latitude

    def __repr__(self):
        return 'Object %s and it\'s coords [%s, %s] at time %s' % (
            self.object_id, str(self.latitude), str(
                self.longitude), str(self.ts))
コード例 #10
0
class Trava_Users(db.Model):
    __tablename__ = 'trava_users'
    
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(255), nullable=False)
    firstname = db.Column(db.String(50), nullable=False)
    lastname = db.Column(db.String(50), nullable=False)
    dob = db.Column(db.DateTime())
    signup = db.Column(db.DateTime())
    signin = db.Column(db.DateTime())
    active = db.Column(db.Boolean())
    role = db.relationship('Trava_Admin', backref='user', lazy='dynamic')
    picture = db.relationship('Trava_Pictures', backref='user', lazy='dynamic')

    def __repr__(self):
        return f'<User id: {self.id} name: {self.firstname} {self.lastname}>'

    def __str__(self):
        return f'<User id: {self.id} name: {self.firstname} {self.lastname}>'

    def __init__(self, email, password, firstname, lastname, dob):
        self.email = email
        self.password = bcrypt.generate_password_hash(password)
        self.firstname = firstname.lower().capitalize() 
        self.lastname = lastname.lower().capitalize()
        self.dob = dob
        self.signup = datetime.utcnow()
        self.signin = datetime.utcnow()
        self.active = False
    
    def password_hash(self, password):
        return bcrypt.generate_password_hash(password)
    
    def password_check(self, pw_hash, candidate):
        return bcrypt.check_password_hash(pw_hash, candidate)

    def encode_auth_token(self, current_user, exp, name='user_login_token'):
        """Generates the Auth Token"""
        try:
            payload = {
                'name': name,
                'user_id': current_user.id,
                'hashed':current_user.password,
                'exp': datetime.utcnow() + timedelta(seconds=exp),
                'iat': datetime.utcnow(),
                'reset': exp
            }
            
            token = jwt.encode(
                payload,
                app.config.get('SECRET_KEY'),
                algorithm='HS256'
            ).decode("utf-8")

            return token
            
        except Exception as e:
            print(e)
            return e

    def decode_auth_token(self, token):
        try:
            decoded = jwt.decode(
                token, 
                app.config.get('SECRET_KEY'),
                algorithm='HS256'
            )
            return decoded

        except Exception as e :
            print(e)
            return e
コード例 #11
0
class Users(db.Model):
    """
    All registered users
    """
    nid = db.Column(db.Integer, primary_key=True)
    login = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(128), nullable=False)
    name = db.Column(db.String(100))
    locked = db.Column(db.Boolean)
    created = db.Column(db.DateTime, default=datetime.utcnow)
    admin = db.Column(db.Integer, default=0)
    lastlogin = db.Column(db.DateTime(timezone=True))
    lastfailedlogin = db.Column(db.DateTime(timezone=True))
    failcount = db.Column(db.Integer)

    # for db.table
    # vehicles = db.relationship('Objects', secondary=Object2user,
    #                            backref=db.backref('user', lazy='dynamic'))

    vehicles = db.relationship('Object2user',
                               backref='user',
                               lazy='dynamic',
                               cascade="all, delete, delete-orphan")

    def __init__(self, login, password, name):
        self.login = login
        self.password = generate_password_hash(password)
        self.name = name

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

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return unicode(self.nid)

    def __repr__(self):
        return 'User: %s/%s/%s' % (self.login, self.password, self.name)

    def change_pass(self, password):
        self.password = generate_password_hash(password)

    def add_vehicle(self, obj):
        """
        Add object to user
        """
        if not self.is_owned(obj):
            assoc = Object2user()
            assoc.object = obj
            self.vehicles.append(assoc)
            return self

    def del_vehicle(self, obj):
        """
        Delete object from user
        """
        if self.is_owned(obj):
            assoc = Object2user.query.filter_by(user_id=self.nid,
                                                object_id=obj.nid).first()
            self.vehicles.remove(assoc)
            return self

    def is_owned(self, obj):
        return self.vehicles.filter_by(object_id=obj.nid).count() > 0

    def hide_show_vehicle(self, obj):
        """
        Change attr at object (vehicle)
        """
        assoc = Object2user.query.filter_by(user_id=self.nid,
                                            object_id=obj.nid).first()
        if assoc.visible:
            assoc.visible = False
        else:
            assoc.visible = True
        return self

    def change_password(self, password):
        """
        Change user's password
        """
        self.password = generate_password_hash(password)