Exemple #1
0
class FeatureRole(db.Model, TimestampMixin):
    __table_name = 'feature_role'
    id = db.Column(db.Integer, primary_key=True)
    public_id = db.Column(db.String(255),
                          nullable=False,
                          unique=True,
                          index=True)
    role_public_id = db.Column(db.String(255),
                               db.ForeignKey('usertype.public_id'),
                               nullable=False)
    feature_public_id = db.Column(db.String(255),
                                  db.ForeignKey('feature.public_id'),
                                  nullable=False)
    menu_public_id = db.Column(db.String(255),
                               db.ForeignKey('menu.public_id'),
                               nullable=False)

    def serialize(self):
        return {
            'name': self.name,
            'description': self.description,
            'public_id': self.public_id,
            'created_at': self.created_at,
            'menu_public_id': self.menu_public_id
        }
Exemple #2
0
class FeatureAssignmentTracker(db.Model, TimestampMixin):
    id = db.Column(db.Integer, primary_key=True)
    public_id = db.Column(db.String(100), nullable=False)
    feature_public_id = db.Column(db.String(255),
                                  db.ForeignKey('feature.public_id'),
                                  nullable=False)
    role_public_id = db.Column(db.String(255),
                               db.ForeignKey('usertype.public_id'),
                               nullable=True)
    action = db.Column(db.Integer, nullable=False)
    action_by = db.Column(db.String(200),
                          db.ForeignKey('user.public_id'),
                          nullable=True,
                          index=True)

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

    def to_json(self):
        return {
            'public_id': self.public_id,
            'feature_public_id': self.feature_public_id,
            'feature_name': self.feature.name,
            'role': self.usertype.name if self.role_public_id else None,
            'action': self.action,
            'created_at': self.created_at,
            'action_by': '{} {}'.format(self.user.first_name,
                                        self.user.last_name)
        }
Exemple #3
0
class User(db.Model, TimestampMixin, BaseTracker):
	type_id = db.Column(db.String(100), db.ForeignKey('usertype.public_id') ,nullable=False)
	category_id = db.Column(db.String(100), db.ForeignKey('category.public_id'), nullable=False, index=True)
	first_name = db.Column(db.String(100), nullable=False)
	last_name = db.Column(db.String(100), nullable=False)
	email = db.Column(db.String(100), nullable=False)
	phone_number = db.Column(db.String(100), nullable=False)
	company_name = db.Column(db.String(200))
	address = db.Column(db.String(200))
	description = db.Column(db.String(200))
	password = db.Column(db.String(150), nullable=False)

	def encode_auth_token(self, user_id):
		"""
		Generates the Auth Token
		:return: string
		"""
		try:
			payload = {
				'exp': datetime.utcnow() + timedelta(days=1, seconds=5),
				'iat': datetime.utcnow(),
				'sub': user_id
			}
			return jwt.encode(
				payload,
				app.config.get('SECRET_KEY'),
				algorithm='HS256'
			)
		except Exception as e:
			return e

	@staticmethod
	def decode_auth_token(auth_token):
		"""
		Validates the auth token
		:param auth_token:
		:return: integer|string
		"""
		try:
			payload = jwt.decode(auth_token, app.config['SECRET_KEY'], 'utf-8')
			is_blacklisted_token = BlacklistToken.check_blacklist(auth_token)
			if is_blacklisted_token:
				return 'Token blacklisted. Please log in again.'
			else:
				return payload['sub']
		except jwt.ExpiredSignatureError:
			return 'Signature expired. Please log in again.'
		except jwt.InvalidTokenError:
			return 'Invalid token. Please log in again.'
		
	def save_to_db(self):
		db.session.add(self)
		db.session.commit()
		clearCache()
		close(db)
Exemple #4
0
class TagTender(db.Model, TimestampMixin, BaseTracker):
    tender_id = db.Column(db.String(100),
                          db.ForeignKey('tender.public_id'),
                          nullable=False,
                          index=True)
    tag_id = db.Column(db.String(100),
                       db.ForeignKey('tag.public_id'),
                       nullable=False,
                       index=True)

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
        db.session.close()
        clearCache()
Exemple #5
0
class Feature(db.Model, TimestampMixin):
    __table_name = 'features'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False, unique=True)
    description = db.Column(db.Text, nullable=True)
    public_id = db.Column(db.String(255),
                          nullable=False,
                          unique=True,
                          index=True)
    menu_public_id = db.Column(db.String(255),
                               db.ForeignKey('menu.public_id'),
                               nullable=False)
    tracker = db.relationship('FeatureAssignmentTracker',
                              backref='feature',
                              lazy=True)
    url = db.Column(db.String(255), nullable=True)
    feature_type = db.Column(db.Integer, nullable=False, default="1")

    def serialize(self):
        return {
            'name': self.name,
            'description': self.description,
            'public_id': self.public_id,
            'created_at': self.created_at,
            'menu_public_id': self.menu_public_id,
            'url': self.url
        }
Exemple #6
0
class AccessTimes(db.Model, TimestampMixin):
    id = db.Column(db.Integer, primary_key=True)
    public_id = db.Column(db.String(100))
    user_public_id = db.Column(db.String(255),
                               db.ForeignKey('user.public_id'),
                               nullable=True,
                               index=True)
    logged_in_at = db.Column(db.DateTime, onupdate=datetime.utcnow)
    logged_out_at = db.Column(db.DateTime, nullable=True)
    location = db.Column(db.String(255), nullable=True)
    loggin_status_code = db.Column(db.Integer, nullable=False)
    ip_address = db.Column(db.String(255), nullable=True)
    browser = db.Column(db.Text, nullable=True)
    latitude = db.Column(db.String(100), nullable=True)
    longitude = db.Column(db.String(100), nullable=True)
    timezone = db.Column(db.String(100), nullable=True)
    country_name = db.Column(db.String(100), nullable=True)
    public_ip = db.Column(db.String(100), nullable=True)

    def to_json(self):
        return {
            'user_public_id': self.user_public_id,
            'user': '******'.format(self.user.first_name, self.user.last_name),
            'logged_in_at': self.logged_in_at,
            'logged_out_at': self.logged_out_at,
            'location': self.location,
            'loggin_status_code': self.loggin_status_code,
            'ip_address': self.ip_address,
            'browser': self.browser,
            'latitude': self.latitude,
            'longitude': self.longitude,
            'timezone': self.timezone,
            'country_name': self.country_name,
            'public_id': self.public_id
        }
Exemple #7
0
class Document(db.Model, TimestampMixin, BaseTracker):
    tender_id = db.Column(db.String(100),
                          db.ForeignKey('tender.public_id'),
                          nullable=False)
    doc_type = db.Column(db.String(100), nullable=False)
    doc_url = db.Column(db.String(100), nullable=False)

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
        db.session.close()
        clearCache()
Exemple #8
0
class Tender(db.Model, TimestampMixin, BaseTracker):
    category_id = db.Column(db.String(100),
                            db.ForeignKey('category.public_id'),
                            nullable=False,
                            index=True)
    type_id = db.Column(db.String(100),
                        db.ForeignKey('type.public_id'),
                        nullable=False,
                        index=True)
    owner_id = db.Column(db.String(100), index=True)
    title = db.Column(db.String(100), nullable=False)
    description = db.Column(db.Text, nullable=False)
    application_start_date = db.Column(db.DateTime)
    application_close_date = db.Column(db.DateTime)
    tender_code = db.Column(db.String(20), index=True, unique=True)
    documents = db.relationship('Document', backref='tender', lazy=True)

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
        db.session.close()
        clearCache()
Exemple #9
0
class Token(db.Model, TimestampMixin):
	id = db.Column(db.Integer, primary_key=True)
	public_id = db.Column(db.String(100), nullable=False)
	user_public_id = db.Column(db.String(100), db.ForeignKey('user.public_id'), index=True)
	token = db.Column(db.Text, nullable=False)
	client_id = db.Column(db.Integer, nullable=True)
	scopes = db.Column(db.Text, nullable=True)
	revoked = db.Column(db.Integer, nullable=True)

	def save_to_db(self):
		db.session.add(self)
		db.session.commit()
		clearCache()
		close(db)
Exemple #10
0
class Bid(db.Model, TimestampMixin, BaseTracker):
    tender_id = db.Column(db.String(100),
                          db.ForeignKey('tender.public_id'),
                          nullable=False,
                          index=True)
    supplier_id = db.Column(db.String(100), index=True)
    amount = db.Column(db.Float(6, 2), nullable=True)
    duration = db.Column(db.Integer, nullable=False)
    awarded_at = db.Column(db.DateTime, default=datetime.now())
    awarded_by = db.Column(db.String(100))

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
        db.session.close()
        clearCache()
Exemple #11
0
class Token(db.Model, TimestampMixin):
    id = db.Column(db.Integer, primary_key=True)
    public_id = db.Column(db.String(100), nullable=False)
    user_public_id = db.Column(db.String(100),
                               db.ForeignKey('user.public_id'),
                               index=True)
    token = db.Column(db.Text, nullable=False)
    client_id = db.Column(db.Integer, nullable=True)
    scopes = db.Column(db.Text, nullable=True)
    revoked = db.Column(db.Integer, nullable=True)

    def serialize(self):
        return {
            'user_public_id': self.user_public_id,
            'client_id': self.client_id,
            'scopes': self.scopes,
            'revoked': self.revoked
        }
Exemple #12
0
class User(db.Model, TimestampMixin):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    public_id = db.Column(db.String(100),
                          nullable=True,
                          unique=True,
                          index=True)
    first_name = db.Column(db.String(100), nullable=False)
    last_name = db.Column(db.String(100), nullable=False)
    phone_number = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), unique=True, nullable=False, index=True)
    password = db.Column(db.String(150), nullable=False)
    user_type = db.Column(db.String(100),
                          db.ForeignKey('usertype.public_id'),
                          nullable=False,
                          index=True)
    remember_token = db.Column(db.String(255), nullable=True)
    access_times = db.relationship('AccessTimes', backref='user', lazy=True)
    user_tracker = db.relationship('FeatureAssignmentTracker',
                                   backref='user',
                                   lazy=True)
    instituition_id = db.Column(db.String(100), nullable=True)
    tokens = db.relationship('Token', backref='user', lazy=True)
    partner_admin_status = db.Column(db.Integer, nullable=True)
    suspended_by = db.Column(db.String(100), nullable=True)
    unsuspended_by = db.Column(db.String(100), nullable=True)
    suspended_at = db.Column(db.DateTime, nullable=True)
    unsuspended_at = db.Column(db.DateTime, nullable=True)

    def serialize(self):
        return {
            'first_name': self.first_name,
            'last_name': self.last_name,
            'phone_number': self.phone_number,
            'email': self.email,
            'user_type': self.user_type,
            'password': self.password,
            'remember_token': self.remember_token
        }

    def encode_auth_token(self, user_id):
        """
        Generates the Auth Token
        :return: string
        """
        try:
            payload = {
                'exp': datetime.utcnow() + timedelta(days=1, seconds=5),
                'iat': datetime.utcnow(),
                'sub': user_id
            }
            return jwt.encode(payload,
                              app.config.get('SECRET_KEY'),
                              algorithm='HS256')
        except Exception as e:
            return e

    @staticmethod
    def decode_auth_token(auth_token):
        """
        Validates the auth token
        :param auth_token:
        :return: integer|string
        """
        try:
            payload = jwt.decode(auth_token, app.config['SECRET_KEY'], 'utf-8')
            is_blacklisted_token = BlacklistToken.check_blacklist(auth_token)
            if is_blacklisted_token:
                return 'Token blacklisted. Please log in again.'
            else:
                return payload['sub']
        except jwt.ExpiredSignatureError:
            return 'Signature expired. Please log in again'
            # return 'Signature expired. Please log in again.'
        except jwt.InvalidTokenError:
            return ''