Exemplo n.º 1
0
class UserModel(db.Model):
    __tablename__ = 'user'

    user_id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(50), nullable=False)
    lastname = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(120), index=True, nullable=False, unique=True)
    phonenumber = db.Column(db.String(20),
                            index=True,
                            nullable=False,
                            unique=True)
    gender = db.Column(db.String(1), nullable=False)
    dateofbirth = db.Column(db.String(10), nullable=False)
    password = db.Column(db.Binary(120), nullable=False)
    username = db.Column(db.String(64),
                         index=True,
                         nullable=False,
                         unique=True)
    location = db.Column(db.String(50), nullable=False)
    salt = db.Column(db.Binary(50), nullable=False)

    def __init__(self, firstname, lastname, email, phonenumber, gender,
                 dateofbirth, password, username, location):
        self.firstname = firstname
        self.lastname = lastname
        self.email = email
        self.phonenumber = phonenumber
        self.gender = gender
        self.dateofbirth = dateofbirth
        self.username = username
        self.location = location
        self.password, self.salt = create_password_hash(password)

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def find_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @classmethod
    def find_by_id(cls, uid):
        return cls.query.filter_by(user_id=uid).first()

    @classmethod
    def find_by_email(cls, mail):
        return cls.query.filter_by(email=mail).first()

    @classmethod
    def find_by_phonenumber(cls, cell):
        return cls.query.filter_by(phonenumber=cell).first()
class AdminModel(db.Model):
    __tablename__ = 'admin'

    admin_id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(50), nullable=False)
    lastname = db.Column(db.String(50), nullable=False)
    username = db.Column(db.String(50),
                         index=True,
                         nullable=False,
                         unique=True)
    email = db.Column(db.String(120), index=True, nullable=False, unique=True)
    password = db.Column(db.Binary(120), nullable=False)
    nationality = db.Column(db.String(50),
                            index=True,
                            nullable=False,
                            unique=True)
    salt = db.Column(db.Binary(50), nullable=False)

    def __init__(self, firstname, lastname, username, email, nationality,
                 password):
        self.firstname = firstname
        self.lastname = lastname
        self.username = username
        self.email = email
        self.nationality = nationality
        self.password, self.salt = create_password_hash(password)

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def find_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @classmethod
    def find_by_email(cls, mail):
        return cls.query.filter_by(email=mail).first()
Exemplo n.º 3
0
class UserModel(db.Model):
    __tablename__ = 'users'

    def generate_uuid():
        return str(uuid.uuid4())

    id = db.Column(db.Integer, primary_key=True)  # default=generate_uuid()
    email = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(db.Binary(60), nullable=False)
    fullname = db.Column(db.String(80))

    def __init__(self, email, plaintext_password, fullname=''):
        self.email = email
        self.password = generate_password_hash(plaintext_password)
        self.fullname = fullname

    # @hybrid_property
    # def password(self):
    #     return self._password

    # def set_password(self, plaintext_password):
    #     self._password = generate_password_hash(plaintext_password)

    # @hybrid_method
    def is_correct_password(self, plaintext_password):
        print("inside is_correct_password function")
        return check_password_hash(self.password, plaintext_password)

    @classmethod
    def find_by_email(cls, email):
        return cls.query.filter_by(email=email).first()

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
Exemplo n.º 4
0
class User(Base):
    __tablename__ = 'users'

    username = db.Column(db.String(100), unique=True, nullable=False)
    _password = db.Column(db.Binary(60), nullable=False)

    def __init__(self, username, password):
        self.username = username
        self._password = bcrypt.generate_password_hash(password)

    def json(self):
        return {'username': self.username, 'password': self._password}

    def save(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def get_by_username(cls, username):
        return cls.query.filter_by(username).first()

    def __repr__(self):
        """ Return username which represetns user object """
        return "<User: {}".format(self.username)
class RiderModel(db.Model):
    __tablename__= 'rider'
    
    rider_id = db.Column(db.Integer, primary_key=True)
    rider_firstname = db.Column(db.String(50), nullable=False)
    rider_lastname = db.Column(db.String(50), nullable=False)
    rider_username = db.Column(db.String(50), index =True, nullable =False, unique =True)
    rider_email = db.Column(db.String(120), index=True, nullable=False, unique=True)
    password = db.Column(db.Binary(120), nullable=False)
    rider_nationality = db.Column(db.String(50), index=True, nullable=False)  
    rider_dateofbirth = db.Column(db.String(15), nullable=False)
    rider_profilepicture = db.Column(db.String(450),index=True, nullable=False,unique=True)
    rider_gender = db.Column(db.String(1),nullable=False)
    salt = db.Column(db.Binary(50),nullable=False)
    status = db.Column(db.Integer, default= 0)
    lon = db.Column(db.Float(precision=4), nullable= True, default =0.00)
    lat = db.Column(db.Float(precision=4), nullable= True, default = 0.00)
    #earnings = db.Column(db.Decimal(10,2), nullable=True, default=0.0)
    #ratings = db.Column(db.dec(200), nullable=True , default ='0')

    account = db.relationship('AccountModel')
    vehicle = db.relationship('VehicleModel')

    
    def __init__(self, rider_firstname, rider_lastname, rider_username, rider_email, rider_password, rider_nationality, rider_dateofbirth, rider_profilepicture,rider_gender):
        self.rider_firstname = rider_firstname
        self.rider_lastname = rider_lastname
        self.rider_username = rider_username
        self.rider_email = rider_email
        self.rider_nationality = rider_nationality
        self.rider_dateofbirth = rider_dateofbirth
        self.rider_profilepicture = rider_profilepicture
        self.rider_gender = rider_gender
        self.password,self.salt = create_password_hash(rider_password)
        #self.earnings = totalearnings(rider)

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def find_by_rider_id(cls, rider_id):
        return cls.query.filter_by(rider_id = rider_id).first()

    @classmethod
    def find_by_username(cls, username):
        return cls.query.filter_by(rider_username=username).first()
   
    @classmethod
    def find_by_email(cls, email):
        return cls.query.filter_by(rider_email=email).first()

    @classmethod
    def find_by_picture(cls, picture):
        return cls.query.filter_by(rider_profilepicture=picture).first()

    @classmethod
    def find_by_status(cls, status):
        return cls.query.filter_by(status = status).all()
    
    @property
    def is_active(self):
        """Always True, as all users are active."""
        return True

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()