class UserModule(db.Model): __tablename__ = 'user_modules' id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('users.id', ondelete='CASCADE')) module_id = db.Column(db.Integer(), db.ForeignKey('modules.id', ondelete='CASCADE'))
class FieldAttendance(db.Model): __tablename__ = "field_attendence" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) title = db.Column(db.String(255), nullable=False) assigned_time = db.Column(db.String(255), nullable=False) assigned_location_lattitude = db.Column(db.String(255), nullable=False) assigned_location_longitude = db.Column(db.String(255), nullable=False) address = db.Column(db.String(255), nullable=False) admin_id = db.Column(db.Integer(), nullable=False) attendence_time = db.Column(db.String(255), nullable=True) attendence_location_lattitude = db.Column(db.String(255), nullable=True) attendence_location_longitude = db.Column(db.String(255), nullable=True) attendence_status = db.Column(db.Boolean(), nullable=True) comment = db.Column(db.String(255), nullable=True) user_id = db.Column(db.Integer(), nullable=True) album_id = db.Column(db.Integer(), nullable=True) createdAt = db.Column(db.DateTime, nullable=False) updatedAt = db.Column(db.DateTime, nullable=False) def __init__(self, title, assigned_time, assigned_location_lattitude, assigned_location_longitude, address, admin_id): self.title = title self.assigned_time = assigned_time self.assigned_location_lattitude = assigned_location_lattitude self.assigned_location_longitude = assigned_location_longitude self.address = address self.admin_id = admin_id self.createdAt = datetime.utcnow() self.updatedAt = datetime.utcnow()
class CompanyUsers(db.Model): __tablename__ = "company_general_users" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) company_id = db.Column(db.Integer(), nullable=False) user_id = db.Column(db.Integer(), nullable=False) def __init__(self, company_id, user_id): self.company_id = company_id self.user_id = user_id
class CompanyPanel(db.Model): __tablename__ = "company_dashboard_users" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) dashboard_user_id = db.Column(db.Integer(), nullable=False) company_id = db.Column(db.Integer(), nullable=False) def __init__(self, dashboard_user_id, company_id): self.dashboard_user_id = dashboard_user_id self.company_id = company_id
class TaskAlbums(db.Model): __tablename__ = "task_albums" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) task_id = db.Column(db.Integer(), nullable=False) createdAt = db.Column(db.DateTime, nullable=False) updatedAt = db.Column(db.DateTime, nullable=False) def __init__(self, task_id=''): self.task_id = task_id self.createdAt = datetime.utcnow() self.updatedAt = datetime.utcnow()
class Albums(db.Model): __tablename__ = "albums" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) field_attendence_id = db.Column(db.Integer(), nullable=False) createdAt = db.Column(db.DateTime, nullable=False) updatedAt = db.Column(db.DateTime, nullable=False) def __init__(self, field_attendence_id=''): self.field_attendence_id = field_attendence_id self.createdAt = datetime.utcnow() self.updatedAt = datetime.utcnow()
class CompanyServices(db.Model): __tablename__ = "company_services" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) company_id = db.Column(db.Integer(), nullable=False) service_id = db.Column(db.Integer(), nullable=False) createdAt = db.Column(db.DateTime, nullable=False) updatedAt = db.Column(db.DateTime, nullable=False) def __init__(self, company_id='', service_id=''): self.company_id = company_id self.service_id = service_id self.createdAt = datetime.utcnow() self.updatedAt = datetime.utcnow()
class TaskPhotos(db.Model): __tablename__ = "task_photos" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) album_id = db.Column(db.Integer(), nullable=False) photo_url = db.Column(db.String(255), nullable=False) createdAt = db.Column(db.DateTime, nullable=False) updatedAt = db.Column(db.DateTime, nullable=False) def __init__(self, album_id='', photo_url=''): self.album_id = album_id self.photo_url = photo_url self.createdAt = datetime.utcnow() self.updatedAt = datetime.utcnow()
class Module(db.Model): __tablename__ = 'modules' id = db.Column(db.Integer(), primary_key=True, autoincrement=True) name = db.Column(db.String(50), unique=False) def __init__(self, name): self.name = name
class TaskService(db.Model): __tablename__ = "task_service" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) title = db.Column(db.String(255), nullable=False) is_paid = db.Column(db.Boolean(), nullable=False) payment_status = db.Column(db.Boolean(), nullable=False) assigned_time = db.Column(db.String(255), nullable=False) assigned_location_lattitude = db.Column(db.String(255), nullable=False) assigned_location_longitude = db.Column(db.String(255), nullable=False) assigned_address = db.Column(db.String(255), nullable=False) admin_id = db.Column(db.Integer(), nullable=False) user_id = db.Column(db.Integer(), nullable=False) task_complete_time = db.Column(db.String(255), nullable=True) task_complete_location_lattitude = db.Column(db.String(255), nullable=True) task_complete_location_longitude = db.Column(db.String(255), nullable=True) task_complete_status = db.Column(db.Boolean(), nullable=True) bill_amount = db.Column(db.Float(), nullable=True) billing_address = db.Column(db.String(255), nullable=True) notes = db.Column(db.String(255), nullable=True) album_id = db.Column(db.Integer(), nullable=True) createdAt = db.Column(db.DateTime, nullable=False) updatedAt = db.Column(db.DateTime, nullable=False) def __init__(self, title, is_paid, assigned_time, assigned_location_lattitude, assigned_location_longitude, assigned_address, admin_id, user_id, payment_status=False): self.title = title self.is_paid = is_paid self.assigned_time = assigned_time self.assigned_location_lattitude = assigned_location_lattitude self.assigned_location_longitude = assigned_location_longitude self.assigned_address = assigned_address self.admin_id = admin_id self.user_id = user_id self.payment_status = payment_status self.createdAt = datetime.utcnow() self.updatedAt = datetime.utcnow()
class Services(db.Model): __tablename__ = "services" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) name = db.Column(db.String(255), nullable=False) service_type = db.Column(db.String(255), nullable=True) createdAt = db.Column(db.DateTime, nullable=False) updatedAt = db.Column(db.DateTime, nullable=False) def __init__(self, name='', service_type=''): self.name = name self.service_type = service_type self.createdAt = datetime.utcnow() self.updatedAt = datetime.utcnow()
class Companies(db.Model): __tablename__ = "companies" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) name = db.Column(db.String(255), unique=True, nullable=False) address = db.Column(db.String(255), nullable=False) agreement_file = db.Column(db.String(255), nullable=True) verification_file = db.Column(db.String(255), nullable=True) tin = db.Column(db.String(255), unique=False, nullable=False) def __init__(self, name, address, tin, agreement_file='', verification_file=''): self.name = name self.address = address self.agreement_file = agreement_file self.verification_file = verification_file self.tin = tin
class User(db.Model, UserMixin): """ User Model for storing user related details """ __tablename__ = "users" id = db.Column(db.Integer, primary_key=True, autoincrement=True) registration_id = db.Column(db.Integer, db.ForeignKey('registrations.id')) role_id = db.Column(db.Integer(), db.ForeignKey('roles.id')) password = db.Column(db.String(255), nullable=False) last_active_on = db.Column(db.DateTime, nullable=True) def __init__(self, registration_id, password, role_id): self.registration_id = registration_id self.password = bcrypt.generate_password_hash( password, app.config.get('BCRYPT_LOG_ROUNDS')).decode() self.role_id = role_id def encode_auth_token(self, user_id): """ Generates the Auth Token :return: string """ try: payload = { 'exp': datetime.utcnow() + timedelta(days=0, 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 def get_reset_password_token(self, expires_in=600): return jwt.encode( { 'reset_password': self.id, 'exp': time() + expires_in }, app.config['SECRET_KEY'], algorithm='HS256').decode('utf-8') @staticmethod def verify_reset_password_token(token): try: id = jwt.decode(token, app.config['SECRET_KEY'], algorithms=['HS256'])['reset_password'] except: return return User.query.get(id) @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.get('SECRET_KEY')) 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.'
class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(50), unique=True)
import datetime import jwt from project.server import app, db, bcrypt # Define models users_roles = db.Table( 'user_role', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db.Model): __tablename__ = 'role' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) class User(db.Model): """ User Model for storing user related details """ __tablename__ = "user" id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255), nullable=False) registered_on = db.Column(db.DateTime, nullable=False) admin = db.Column(db.Boolean, nullable=False, default=False) def __init__(self, email, password, admin=False): self.email = email self.password = bcrypt.generate_password_hash( password, app.config.get('BCRYPT_LOG_ROUNDS')).decode()
class Role(db.Model): __tablename__ = 'role' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255))
class Student(db.Model): __tablename__ = 'student' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(100), unique=True)