示例#1
0
    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)

        if self.tenant_set.count() == 0:
            t = Tenant()
            t.save()
            t.users.add(self)
            mail_admins("New User: "******"")
示例#2
0
def main(domain_name):
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'saleor.settings')
    import django
    from django.core.management.commands.runserver import Command as runserver
    from django.core.management import execute_from_command_line
    django.setup()
    from tenants.models import Tenant, Domain

    Tenant.objects.all()
    tenant = Tenant(schema_name='public', name='admin tenant')
    tenant.save()

    domain = Domain()
    domain.domain = domain_name
    domain.tenant = tenant
    domain.is_primary = True
    domain.save()
示例#3
0
    def setUp(self):
        Tenant.create(
            name='Test Tenant',
            first_name='John',
            last_name='Doe',
            email='*****@*****.**',
            password='******')

        Integration.create(
            tenant=Tenant.objects.filter(name='Test Tenant').first(),
            name=BASE_TEST_INTEGRATION_NAME,
            notes='Test Notes')

        DeviceKind.objects.create(
            name='OTP',
            module='devices.modules.otp.OTPDeviceKindModule',
            description='OTP Devices',
            configuration={
                'issuer_name': 'pymfa',
                'digits': 6,
                'algorithm': OTPConfiguration.ALGORITHM_SHA1,
                'secret_length': 32,
                'valid_window': 1,
                'interval': 30,
            })

        Module.objects.create(
            name='contrib.communications.DjangoSMTPMailer', configuration={})

        DeviceKind.objects.create(
            name='Email',
            module='devices.modules.email.EmailDeviceKindModule',
            description='Email Devices',
            configuration={
                'from_email': '*****@*****.**',
                'subject': 'Your 2fa access token',
                'message': 'Your 2fa access token is `{token}`',
                'html_message': 'Your 2fa access token is `{token}`',
                'communication_module':
                    'contrib.communications.DjangoSMTPMailer',
                'communication_module_settings': {},
            })
示例#4
0
def tenant_creation_handler(sender, instance, created, **kwargs):
    if created:

        server = None
        uid = instance.uid
        try:
            server = DatabaseServer.objects.get(id=1)
        except DatabaseServer.DoesNotExist:
            print('DatabaseServer objects DoesNotExist')

        # Create and store tenant definition
        if not server:
            raise Exception('Server must be defined for tenant creation')

        db_name = ''.join(
            [chr for chr in str(uid).replace('-', '') if chr.isalpha()])
        db_user = credentials_generator()
        db_password = credentials_generator()
        alias = db_name
        tenant = Tenant(application=instance,
                        db_server=server,
                        db_name=db_name,
                        db_user=db_user,
                        db_password=db_password,
                        alias=alias)
        tenant.save()

        TenantLog.objects.create(
            tenant=tenant,
            message=_('Tenant object created for app {uid}'.format(
                uid=instance.uid)))

        #Create database and sql Credentials
        tenant_manager = TenantManager(tenant)
        tenant_manager.create_database()
        tenant_manager.create_db_user()
        tenant_manager.grant_privileges()
        tenant_manager.sync_database()
示例#5
0
    def handle(self, *args, **options):
        user = User.objects.filter(username=os.getenv('OSS2FA_ADMIN_USERNAME')).first()

        if user:
            return

        if not user:
            _ = User.objects.create_superuser(
                os.getenv('OSS2FA_ADMIN_USERNAME'),
                os.getenv('OSS2FA_ADMIN_EMAIL'),
                os.getenv('OSS2FA_ADMIN_PASSWORD')
            )

        DeviceKind.objects.create(
            name='OTP',
            module='devices.modules.otp.OTPDeviceKindModule',
            description='OTP Devices',
            configuration={
                'issuer_name': otp.OTPConfiguration.DEFAULT_ISSUER,
                'digits': otp.OTPConfiguration.DEFAULT_DIGITS,
                'algorithm': otp.OTPConfiguration.ALGORITHM_SHA1,
                'secret_length': otp.OTPConfiguration.DEFAULT_SECRET_LENGTH,
                'valid_window': otp.OTPConfiguration.DEFAULT_VALID_WINDOW,
                'interval': otp.OTPConfiguration.DEFAULT_INTERVAL,
            })

        tenant = Tenant.create(
            name=Tenant.DEFAULT_TENANT_NAME,
            email=os.getenv('OSS2FA_ADMIN_EMAIL'),
            password=os.getenv('OSS2FA_ADMIN_PASSWORD'),
        )

        integration = Integration.create(
            tenant=tenant,
            name=Integration.DEFAULT_INTEGRATION_NAME,
            notes='Default Integration'
        )

        message = '''
===> OSS2FA bootstrap complete!
===> To get you started, we have created a default tenant and integration.
===> Integration (name=`{0}`, access_key=`{1}`, secret_key=`{2}`)
'''
        self.stdout.write(
            self.style.SUCCESS(message.format(
                integration.name,
                integration.access_key,
                integration.secret_key
            )))
示例#6
0
文件: routes.py 项目: bkalika/cursor
 def post(self):
     data = request.json
     parser.parse_args(strict=True)
     for tenant in json_data:
         if tenant.get("passport_id") == data["passport_id"]:
             return "Tenant already ordered room"
     else:
         tenants_data.append(
             Tenant(
                 data["name"],
                 data["passport_id"],
                 data["age"],
                 data["sex"],
                 data["city"],
                 data["street"],
                 data["room_number"],
             ).to_dict())
         write_data(tenants_data, json_file)
         return "Tenant added"
示例#7
0
    def start(self):
        with open(str(self.input_path), newline="") as csvfile:
            reader = csv.DictReader(csvfile)
            for row in tqdm(reader):
                people: List[Person] = []

                # Handle multiple tenants in one room
                if " and " in row["Tenancy"]:
                    tenancy0: str = row["Tenancy"].split(" and ")[0]
                    tenancy1: str = row["Tenancy"].split(" and ")[1]
                    email0: Optional[str] = None
                    email1: Optional[str] = None
                    if row["Email"]:
                        email0 = row["Email"].split(",")[0].strip()
                        email1 = row["Email"].split(",")[1].strip()

                    people.append(self._create_person(tenancy0, email0))
                    people.append(self._create_person(tenancy1, email1))
                else:
                    people.append(
                        self._create_person(row["Tenancy"], row["Email"]))

                unit_n: int = int(
                    list(filter(None, re.split("[U,R,/]",
                                               row["Property"])))[0])
                room_n: int = int(
                    list(filter(None, re.split("[U,R,/]",
                                               row["Property"])))[1])

                room = Room.objects.get(number=room_n, unit__number=unit_n)

                lease_start: date = dateutil.parser.parse(row["Lease Start"])
                lease_end: date = dateutil.parser.parse(row["Lease End"])

                tenant = Tenant(room=room,
                                lease_start=lease_start,
                                lease_end=lease_end)
                tenant.save()
                tenant.people.set(people)
                tenant.save()
示例#8
0
# This script create a public and a private tenant for testing

from tenants.models import Tenant
tenant = Tenant(domain_url='localhost',
                schema_name='public',
                name='public',
                paid_until='2018-12-05',
                on_trial=False)
tenant.save()

tenant = Tenant(domain_url='tenant.localhost',
                schema_name='tenant',
                name='Tenant One',
                paid_until='2018-12-05',
                on_trial=True)
tenant.save()