Exemplo n.º 1
0
    def post(self, request: Request):
        uid = request.user.id
        if not uid:
            return HttpResponseForbidden("Missing user ID")

        body = request.data
        if not body:
            return HttpResponseBadRequest("Missing request body")

        (steps_key_id, steps_enc) = self.encrypt_steps(body["steps"])

        db_app = Application(
            last_updated=body.get("lastUpdate"),
            last_printed=body.get("lastPrinted"),
            app_type=body.get("type"),
            current_step=body.get("currentStep"),
            all_completed=body.get("allCompleted"),
            steps=steps_enc,
            user_type=body.get("userType"),
            applicant_name=body.get("applicantName"),
            user_name=body.get("userName"),
            key_id=steps_key_id,
            respondent_name=body.get("respondentName"),
            protected_party_name=body.get("protectedPartyName"),
            protected_child_name=body.get("protectedChildName"),
            application_location=body.get("applicationLocation"),
            user_id=uid)

        db_app.save()
        return Response({"app_id": db_app.pk})
Exemplo n.º 2
0
    def obj_create(self, bundle, request=None, **kwargs):
        registrationForm = bundle.data['registrationForm']

        tenantDetails = registrationForm['personalDetails']
        ownerDetails = registrationForm['otherParty']
        leaseApplicationDetails = registrationForm['leaseApplicationDetails']
        depositDetails = registrationForm['depositDetails']

        tenant_first_name = tenantDetails['firstName']
        tenant_last_name = tenantDetails['lastName']
        owner_first_name = ownerDetails['firstName']
        owner_last_name = ownerDetails['lastName']

        try:  ##try to find if registrant user exist
            tenant = User.objects.get(email=tenantDetails['email'])
            generated_tenant_id = tenant.account_id
        except User.DoesNotExist:  ##if doesn't exist create a new object

            ##excuse my shit way of doing this, randomly generating user_id
            random_uid = str(uuid.uuid4().hex)
            generated_tenant_id = random_uid
            #generated_tenant_id = str(tenant_first_name)[0] + str(tenant_last_name)[0] + random_uid[0] + random_uid[1] + random_uid[2] + random_uid[3]
            generated_tenant_password = random_uid[4] + random_uid[
                5] + random_uid[6] + random_uid[7] + str(
                    tenant_first_name)[0] + str(tenant_last_name)[0]
            name = generate_random_username()
            print('tenant username: '******'tenant password: '******'phoneNumber'],
                          email=tenantDetails['email'],
                          username=name)
            tenant.set_password(generated_tenant_password)
            tenant.save()

            send_account_creation_email(tenant, generated_tenant_password)

            ##Log the event
            registrationEvent = Event(
                referenceid=generated_tenant_id,
                what="TENANT REGISTRATION",
                who=generated_tenant_id,
                #when=bundle.data['createdAt']
            )
            registrationEvent.save()

        try:  ##try to find if owner user exist
            owner = User.objects.get(email=ownerDetails['email'])

            generated_owner_id = owner.account_id
        except User.DoesNotExist:  ##if doesn't exist create a new object

            random_uid = str(uuid.uuid4().hex)
            generated_owner_id = random_uid
            #generated_owner_id = str(owner_first_name)[0] + str(owner_last_name)[0] + random_uid[0] + random_uid[1] + random_uid[2] + random_uid[3]
            generated_owner_password = random_uid[4] + random_uid[
                5] + random_uid[6] + random_uid[7] + str(
                    owner_first_name)[0] + str(owner_last_name)[0]
            name = generate_random_username()
            print('owner username: '******'owner password: '******'firstName'],
                         last_name=ownerDetails['lastName'],
                         contact_number=ownerDetails['phoneNumber'],
                         email=ownerDetails['email'],
                         username=name)
            owner.set_password(generated_owner_password)
            owner.save()
            send_account_creation_email(owner, generated_owner_password)

            ##Log the event
            registrationEvent = Event(
                referenceid=generated_owner_id,
                what="OWNER REGISTRATION",
                who=generated_owner_id,
            )
            registrationEvent.save()

        try:  ##try to find if application allready exist
            owner = Application.objects.get(
                ejari_no=leaseApplicationDetails['contractNo'])
        except Application.DoesNotExist:  ##if doesn't exist create a new object
            random_uid = str(uuid.uuid4().hex)
            #generated_application_id = str(owner_first_name)[0] + str(tenant_first_name)[0] + \
            #                           random_uid[0] + random_uid[1] + random_uid[2] + random_uid[3]
            generated_application_id = random_uid
            new_application = Application(
                ejari_no=leaseApplicationDetails['contractNo'],
                premis_no=leaseApplicationDetails['premiseNo'],
                total_contract_value=leaseApplicationDetails[
                    'securityDepositAmount'],
                address=leaseApplicationDetails['address'],
                start_date=leaseApplicationDetails['contractStartDate'],
                end_date=leaseApplicationDetails['contractEndDate'],
                annual_rent=leaseApplicationDetails['annualRent'],
                property_size=leaseApplicationDetails['propertySize'],
                property_usage=leaseApplicationDetails['propertyUsage'],
                currency_type=leaseApplicationDetails['currencyType'],
                deposit_term=depositDetails['term'],
                deposit_amount=depositDetails['amount'],
                term_percent=depositDetails['termPercent'],
                internal_id=generated_application_id,
                tenant_id=generated_tenant_id,
                owner_id=generated_owner_id)
            new_application.save()

            ##Log the event
            registrationEvent = Event(
                referenceid=generated_application_id,
                what="APPLICATION REGISTRATION",
                who=generated_tenant_id,
            )
            registrationEvent.save()
            send_application_confirm_email(tenant, owner, new_application)