Esempio n. 1
0
def register_franchise(request, plan_id=1):
    plan = Plan.search(plan_id)
    if not plan:
        messages.error(request, "No existe el plan buscado")
        return redirect("home")

    if request.method == "POST":
        form_franchise = FranchiseForm(request.POST)
        form_user = SignUpForm(request.POST)
        if form_franchise.is_valid() and form_user.is_valid():

            from django.db import connection
            try:
                user, user_response = signup(request, user_type='admin')
                franchise = form_franchise.save(commit=False)
                franchise.client = user
                franchise.plan = plan
                franchise.save()
                domain = Domain(
                    domain=f"{franchise.schema_name}.{settings.DOMAIN}",
                    is_primary=True,
                    tenant=franchise,
                )
                domain.save()
                connection.set_tenant(franchise)
                User.initial_user(email=franchise.client.email,
                                  hash_password=franchise.client.password)
                connection.set_schema_to_public()
                messages.success(request,
                                 "La franquicia ha sido creada exitosamente")
                return redirect("franchise_list")
            except:
                messages.error(
                    request,
                    "No se pudo registrar la franquicia, contacte al soporte")
        else:
            messages.error(
                request,
                "No se pudo registrar la franquicia, contacte al soporte")
    else:
        form_franchise = FranchiseForm()
        form_user = SignUpForm()

    return render(
        request,
        "franchises/registry_franchises.html",
        {
            "form_franchise":
            form_franchise,
            "form_user":
            form_user,
            "title":
            "Franchise registry",
            "domains":
            Domain.objects.exclude(
                tenant__schema_name="public").select_related("tenant").all(),
            "domain":
            settings.DOMAIN,
        },
    )
Esempio n. 2
0
    def mutate(self, info, input: CreateClientInput):
        input = vars(input)
        client = Client(email=input.pop('email'),
                        password=input.pop('password'),
                        is_alternative=input.pop('is_alternative'))
        input['user'] = client
        contact = Contact(**input)
        client.save()
        contact.save()
        if (client.password != 'deliver-food-2021'):
            signup(client)
        else:

            client = Client.objects.get(email=client.email)
            client.is_active = True
            client.save()

        return CreateClient(client=client)
Esempio n. 3
0
 def test_signup(self):
     username = "******"
     firstname = "graham"
     lastname = "haroldson"
     email = "*****@*****.**"
     password = "******"
     phone = "999999999"
     address = "address"
     province = "BC"
     city = "city"
     request = HttpRequest()
     request.method = "POST"
     request.__setattr__("username", username)
     request.__setattr__("firstname", firstname)
     request.__setattr__("lastname", lastname)
     request.__setattr__("email", email)
     request.__setattr__("password", password)
     request.__setattr__("phone", phone)
     request.__setattr__("address", address)
     request.__setattr__("province", province)
     request.__setattr__("city", city)
     signup(request)
     try:
         user = Users(username=username)
         userprofile = UserProfile(username=username)
         verificationapp = VerificationApp(username=username)
         self.assertTrue(userprofile.firstname == firstname)
         self.assertTrue(userprofile.lastname == lastname)
         self.assertTrue(userprofile.email == email)
         self.assertTrue(userprofile.phone == phone)
         self.assertTrue(userprofile.address == address)
         self.assertTrue(userprofile.province == province)
         self.assertTrue(userprofile.city == city)
         user.delete()
         userprofile.delete()
         verificationapp.delete()
         return True
     except:
         return False
Esempio n. 4
0
 def test_signup(self):
     username = "******"
     firstname = "graham"
     lastname = "haroldson"
     email = "*****@*****.**"
     password = "******"
     phone = "999999999"
     address = "address"
     province = "BC"
     city = "city"
     request = HttpRequest()
     request.method = 'POST'
     request.__setattr__('username', username)
     request.__setattr__('firstname', firstname)
     request.__setattr__('lastname', lastname)
     request.__setattr__('email', email)
     request.__setattr__('password', password)
     request.__setattr__('phone', phone)
     request.__setattr__('address', address)
     request.__setattr__('province', province)
     request.__setattr__('city', city)
     signup(request)
     try:
         user = Users(username=username)
         userprofile = UserProfile(username=username)
         verificationapp = VerificationApp(username=username)
         self.assertTrue(userprofile.firstname == firstname)
         self.assertTrue(userprofile.lastname == lastname)
         self.assertTrue(userprofile.email == email)
         self.assertTrue(userprofile.phone == phone)
         self.assertTrue(userprofile.address == address)
         self.assertTrue(userprofile.province == province)
         self.assertTrue(userprofile.city == city)
         user.delete()
         userprofile.delete()
         verificationapp.delete()
         return True
     except:
         return False
Esempio n. 5
0
 def test_signup_correct_template(self):
     request = HttpRequest()
     response_signup = signup(request)
     self.assertTemplateUsed('signup.html')
Esempio n. 6
0
    def test_editAccount(self):
        username = "******"
        firstname = "graham"
        lastname = "haroldson"
        email = "*****@*****.**"
        password = "******"
        phone = "999999999"
        address = "address"
        province = "BC"
        city = "city"

        password = "******"
        firstname2 = "sean"
        lastname2 = "slipetz"
        email2 = "*****@*****.**"
        phone2 = "11111111"
        address2 = "newaddress"
        province2 = "BC"
        city2 = "newcity"

        request = HttpRequest()
        request.method = "POST"
        request.__setattr__("username", username)
        request.__setattr__("firstname", firstname)
        request.__setattr__("lastname", lastname)
        request.__setattr__("email", email)
        request.__setattr__("password", password)
        request.__setattr__("phone", phone)
        request.__setattr__("address", address)
        request.__setattr__("province", province)
        request.__setattr__("city", city)
        signup(request)
        try:
            user = Users(username=username)
            userprofile = UserProfile(username=username)

            self.assertTrue(user.password == password)
            self.assertTrue(user.firstname == firstname)
            self.assertTrue(user.lastname == lastname)
            self.assertTrue(user.email == email)
            self.assertTrue(user.phone == phone)
            self.assertTrue(user.address == address)
            self.assertTrue(user.province == province)
            self.assertTrue(user.city == city)

            request.__setattr__("firstname", firstname2)
            request.__setattr__("lastname", lastname2)
            request.__setattr__("email", email2)
            request.__setattr__("phone", phone2)
            request.__setattr__("address", address2)
            request.__setattr__("province", province2)
            request.__setattr__("city", city2)
            request.__setattr__("password", password2)
            editaccount(request)

            user = Users(username=username)
            userprofile = UserProfile(username=username)

            self.assertTrue(user.password == password2)
            self.assertTrue(user.firstname == firstname2)
            self.assertTrue(user.lastname == lastname2)
            self.assertTrue(user.email == email2)
            self.assertTrue(user.phone == phone2)
            self.assertTrue(user.address == address2)
            self.assertTrue(user.province == province2)
            self.assertTrue(user.city == city2)

            user.delete()
            userprofile.delete()
            verificationapp.delete()
            return True
        except:
            return False
Esempio n. 7
0
    def test_editAccount(self):
        username = "******"
        firstname = "graham"
        lastname = "haroldson"
        email = "*****@*****.**"
        password = "******"
        phone = "999999999"
        address = "address"
        province = "BC"
        city = "city"

        password = "******"
        firstname2 = "sean"
        lastname2 = "slipetz"
        email2 = "*****@*****.**"
        phone2 = "11111111"
        address2 = "newaddress"
        province2 = "BC"
        city2 = "newcity"

        request = HttpRequest()
        request.method = 'POST'
        request.__setattr__('username', username)
        request.__setattr__('firstname', firstname)
        request.__setattr__('lastname', lastname)
        request.__setattr__('email', email)
        request.__setattr__('password', password)
        request.__setattr__('phone', phone)
        request.__setattr__('address', address)
        request.__setattr__('province', province)
        request.__setattr__('city', city)
        signup(request)
        try:
            user = Users(username=username)
            userprofile = UserProfile(username=username)

            self.assertTrue(user.password == password)
            self.assertTrue(user.firstname == firstname)
            self.assertTrue(user.lastname == lastname)
            self.assertTrue(user.email == email)
            self.assertTrue(user.phone == phone)
            self.assertTrue(user.address == address)
            self.assertTrue(user.province == province)
            self.assertTrue(user.city == city)

            request.__setattr__('firstname', firstname2)
            request.__setattr__('lastname', lastname2)
            request.__setattr__('email', email2)
            request.__setattr__('phone', phone2)
            request.__setattr__('address', address2)
            request.__setattr__('province', province2)
            request.__setattr__('city', city2)
            request.__setattr__('password', password2)
            editaccount(request)

            user = Users(username=username)
            userprofile = UserProfile(username=username)

            self.assertTrue(user.password == password2)
            self.assertTrue(user.firstname == firstname2)
            self.assertTrue(user.lastname == lastname2)
            self.assertTrue(user.email == email2)
            self.assertTrue(user.phone == phone2)
            self.assertTrue(user.address == address2)
            self.assertTrue(user.province == province2)
            self.assertTrue(user.city == city2)

            user.delete()
            userprofile.delete()
            verificationapp.delete()
            return True
        except:
            return False
Esempio n. 8
0
 def test_signup_correct_template(self):
     request = HttpRequest()
     request.user = User.objects.create(is_teacher=True)
     response_signup = signup(request)
     self.assertTemplateUsed('signup.html')
Esempio n. 9
0
 def test_signup(self, rf):
     req = rf.get('signup/')
     req.session = {}
     resp = views.signup(req)
     assert resp.status_code == 200
     assert 'Реєстрація'.encode() in resp.content