Exemple #1
0
class User(db.Model, UserMixin):
    id = db.Column(db.String, primary_key = True)
    first_name = db.Column(db.String(150), nullable = True, default = '')
    last_name = db.Column(db.String(150), nullable = True, default = '')
    email = db.Column(db.String(150), nullable = False)
    password = db.Column(db.String(150), nullable = True, default = '')
    g_auth_verify = db.Column(db.Boolean, default = False)
    token = db.Column(db.String, default = '', unique = True)
    data_created = db.Column(db.DateTime, nullable = False, default = datetime.utcnow)
    car = db.relationship('Car', backref = 'owner', lazy = True)

    def __init__(self,email,first_name= '', last_name = '', id = '', password = '', token = '', g_auth_verify = False):
        self.id = self.set_id()
        self.first_name = first_name
        self.last_name = last_name
        self.password = self.set_password(password)
        self.email = email
        self.token = self.set_token(24)
        self.g_auth_verify = g_auth_verify

    def set_token(self, length):
        return secrets.token_hex(length)

    def set_id(self):
        return str(uuid.uuid4())

    def set_password(self, password):
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash
    
    def __repr__(self):
        return f'User {self.email} has been added to the database' 
Exemple #2
0
class Car(db.Model):
    #creates PK of ID
    id = db.Column(db.Integer, primary_key=True)
    make = db.Column(db.String(150))
    model = db.Column(db.String(150))
    color = db.Column(db.String(150))
    price = db.Column(db.Integer)
    user_id = db.Column(db.String, db.ForeignKey('user.token'), nullable=False)

    def __init__(self, make, model, color, price, user_id):
        self.make = make
        self.model = model
        self.color = color
        self.price = price
        self.user_id = user_id

    def __repr__(self):
        return f'The following car {self.model} has been added to {self.user_id}s garage'

    def to_dict(self):
        return {
            "id": self.id,
            "make": self.make,
            "model": self.model,
            "color": self.color,
            "price": self.price
        }
Exemple #3
0
class Car(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    make = db.Column(db.String(150))
    model = db.Column(db.String(150))
    year = db.Column(db.Integer)
    color = db.Column(db.String(150))
    price = db.Column(db.Integer)
    user_id = db.Column(db.String, db.ForeignKey('user.token'), nullable=False)

    def __init__(self, make, model, year, color, price, user_id):
        self.make = make
        self.model = model
        self.year = year
        self.color = color
        self.price = price
        self.user_id = user_id

    def __repr__(self):
        return f'The following Car has been added: {self.make} {self.model} which belongs to {self.user_id}'

    def to_dict(self):
        return {
            "id": self.id,
            "make": self.make,
            "model": self.model,
            "year": self.year,
            "color": self.color,
            "price": self.price
        }
Exemple #4
0
class Car(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(150))
    price = db.Column(db.Integer)
    model = db.Column(db.String(150))
    year = db.Column(db.Integer)
    user_id = db.Column(db.String, db.ForeignKey('user.id'), nullable=False)

    def __init__(self, name, price, model, year, user_id):
        self.name = name
        self.price = price
        self.model = model
        self.year = year
        self.user_id = user_id

    def __repr__(self):
        return f'The following car has been added: {self.year} {self.name} {self.model} which belongs to {self.user_id}'

    def to_dict(self):
        return {
            "id": self.id,
            "name": self.name,
            "price": self.price,
            "model": self.model,
            "year": self.year
        }
Exemple #5
0
class User(db.Model, UserMixin):
    #creating PK and user ID number
    id = db.Column(db.String, primary_key=True)
    first_name = db.Column(db.String(150), nullable=True, default="")
    last_name = db.Column(db.String(150), nullable=True, default="")
    email = db.Column(db.String(150), nullable=False)
    #password string has no limit to allow for complex password hasing from werkzeug
    password = db.Column(db.String, nullable=True, default="")
    #creates True/False to tie account with google authentication
    g_auth_verify = db.Column(db.Boolean, default=False)
    #token allows persistent login based on timeing - logic to follow
    token = db.Column(db.String, default="", unique=True)
    #create automatic timestamp when account is first created
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    #creates a link to the car table
    car = db.relationship('Car', backref='owner', lazy=True)

    #creates method for class
    def __init__(self,
                 email,
                 first_name="",
                 last_name="",
                 id="",
                 password="",
                 token="",
                 g_auth_verify=False):
        self.id = self.set_id()
        self.first_name = first_name
        self.last_name = last_name
        self.password = self.set_password(password)
        self.email = email
        self.token = self.set_token(24)
        self.g_auth_verify = g_auth_verify

    def set_token(self, length):
        return secrets.token_hex(length)

    #creates method for self.id used in __init__
    def set_id(self):
        #makes a string with uuid
        return str(uuid.uuid4())

    def set_password(self, password):
        #uses werkzeug to create password has for method defined in __init__
        self.pw_hash = generate_password_hash(password)
        return self.pw_hash

    def __repr__self(self):
        return f'User {self.email} has been added to the database'