Example #1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    active = db.Column(db.Boolean(), nullable=False, default=False)
    posts = db.relationship('Post', backref='author', lazy=True)

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

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_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 "User('{}, {}, {}')".format(self.username, self.email,
                                           self.image_file)
Example #2
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), index=True, unique=True)
    password = db.Column(db.String(200),
                         primary_key=False,
                         unique=False,
                         nullable=False)
    email = db.Column(db.String(40), index=True, unique=True, nullable=False)
    carpools = db.relationship(
        "Carpool",
        secondary=passengers,
        primaryjoin=(passengers.c.user_id == id),
        secondaryjoin=(passengers.c.carpool_id == Carpool.id),
        backref=db.backref("passengers", lazy="dynamic"),
        lazy="dynamic",
    )
    created_carpools = db.relationship("Carpool", backref="creator")

    def set_password(self, password):
        """Create hashed password."""
        self.password = generate_password_hash(password, method="sha256")

    def check_password(self, password):
        """Check hashed password."""
        return check_password_hash(self.password, password)

    def __repr__(self):
        return "<User: {}>".format(self.name)
Example #3
0
class Users(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    email = db.Column(db.String(100), unique=True)
    contact = db.Column(db.String(100))
    password = db.Column(db.String(100))

    def __init__(self, name, email, contact, password):
        self.name = name
        self.email = email
        self.contact = contact
        self.password = password

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

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.email)
Example #4
0
class Carpool(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), index=True, unique=True)
    summary = db.Column(db.String(128))
    time_created = db.Column(db.DateTime(), index=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    from_location = db.Column(db.String(32))
    to_location = db.Column(db.String(32))

    @staticmethod
    def get_all():
        return Carpool.query.order_by(db.desc(Carpool.time_created))

    def __repr__(self):
        return "<Carpool: {}>".format(self.name)
Example #5
0
class Rides(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(100))
    start = db.Column(db.String(100))
    end = db.Column(db.String(100))
    car_num = db.Column(db.String(100))
    seats = db.Column(db.Integer)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))

    def __init__(self, email, start, end, car_num, seats, user_id):
        self.email = email
        self.start = start
        self.end = end
        self.car_num = car_num
        self.seats = seats
        self.user_id = user_id

    def __repr__(self):
        return '<Service %r>' % self.email
Example #6
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return "Post('{}, {}')".format(self.title, self.date_posted)
Example #7
0
class Car(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    car_name = db.Column(db.String(100), nullable=False)

    member_one = db.Column(db.Integer, nullable=False)
    member_two = db.Column(db.Integer, nullable=True)
    member_three = db.Column(db.Integer, nullable=True)
    member_four = db.Column(db.Integer, nullable=True)
    member_five = db.Column(db.Integer, nullable=True)

    week_day_one = db.Column(db.Integer, nullable=True)
    week_day_two = db.Column(db.Integer, nullable=True)
    week_day_three = db.Column(db.Integer, nullable=True)
    week_day_four = db.Column(db.Integer, nullable=True)
    week_day_five = db.Column(db.Integer, nullable=True)

    # user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return "Car('{}, {}, {}, {}, {}, {}')".format(
            self.car_name, self.member_one, self.member_two, self.member_three,
            self.member_four, self.member_five)
Example #8
0
class Bookings(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    rider = db.Column(db.String(100))
    owner = db.Column(db.String(100))
    ride_id = db.Column(db.Integer, db.ForeignKey('rides.id'))
    pickup = db.Column(db.String(100))
    drop = db.Column(db.String(100))
    status = db.Column(db.String(100))
    booking_code = db.Column(db.String(100))

    def __init__(self, rider, owner, ride_id, pickup, drop, status,
                 booking_code):
        self.rider = rider
        self.owner = owner
        self.ride_id = ride_id
        self.pickup = pickup
        self.drop = drop
        self.status = status
        self.booking_code = booking_code