예제 #1
0
def register_public_key_server(request):
    if request.method == 'POST':
        form = RegisteredDevicePublicKeyForm(request.user, data=request.POST)
        if form.is_valid():
            form.save()
            zone_id = form.data["zone"]
            org_id = Zone.objects.get(id=zone_id).get_org().id

            callback_url = form.cleaned_data.get("callback_url", None)
            if callback_url:
                # New style: go directly to the origin page, which will force a sync to occur (no reason to ping refresh)
                #   This is better for the current force_job
                return HttpResponseRedirect(callback_url)
            else:
                # Old style, for clients that don't send a callback url
                messages.success(
                    request,
                    _("The device's public key has been successfully registered. You may now close this window."
                      ))
                return HttpResponseRedirect(
                    reverse("zone_management",
                            kwargs={
                                'org_id': org_id,
                                'zone_id': zone_id
                            }))

    else:
        # This is hackish--we now create default organizations and zones for users, based on their
        #   registration information.  For previous users, however, we don't.  And we don't
        #   give any links / instructions for creating zones when they get here.
        # So, rather than block them, let's create an org and zone for them, so that
        #   at least they can proceed directly.
        if request.user.organization_set.count() == 0:
            # Localizing central-only import
            from central.models import Organization
            org = Organization(name="Your organization", owner=request.user)
            org.save()
            org.add_member(request.user)
            org.save()
        if not sum(
            [org.zones.count()
             for org in request.user.organization_set.all()]):
            org = request.user.organization_set.all()[0]
            zone = Zone(name="Default zone")
            zone.save()
            org.add_zone(zone)

        # callback_url: 0.10.3 and higher (distributed server)
        # prev: 0.10.3 and higher (central server)
        #
        # Note: can't use referer, because this breaks if the user is redirected
        #   to the central server login page--gets confusing.
        form = RegisteredDevicePublicKeyForm(
            request.user,
            callback_url=request.REQUEST.get("callback_url")
            or request.REQUEST.get("prev"),
        )
    return {
        "form": form,
    }
예제 #2
0
파일: views.py 프로젝트: kanyanat3/ka-lite
def register_public_key_server(request):

    if request.method == "POST":
        form = RegisteredDevicePublicKeyForm(request.user, data=request.POST)
        if form.is_valid():
            form.save()
            zone_id = form.data["zone"]

            callback_url = form.cleaned_data.get("callback_url", None)
            if callback_url:
                # New style: go directly to the origin page, which will force a sync to occur (no reason to ping refresh)
                #   This is better for the current force_job
                return HttpResponseRedirect(callback_url)
            else:
                # Old style, for clients that don't send a callback url
                messages.success(
                    request,
                    _("The device's public key has been successfully registered. You may now close this window."),
                )
                return HttpResponseRedirect(reverse("zone_management", kwargs={"zone_id": zone_id}))

    else:
        # This is hackish--we now create default organizations and zones for users, based on their
        #   registration information.  For previous users, however, we don't.  And we don't
        #   give any links / instructions for creating zones when they get here.
        # So, rather than block them, let's create an org and zone for them, so that
        #   at least they can proceed directly.
        if request.user.organization_set.count() == 0:
            # Localizing central-only import
            from central.models import Organization

            org = Organization(name="Your organization", owner=request.user)
            org.save()
            org.add_member(request.user)
            org.save()
        if not sum([org.zones.count() for org in request.user.organization_set.all()]):
            org = request.user.organization_set.all()[0]
            zone = Zone(name="Default zone")
            zone.save()
            org.add_zone(zone)

        # callback_url: 0.10.3 and higher (distributed server)
        # prev: 0.10.3 and higher (central server)
        #
        # Note: can't use referer, because this breaks if the user is redirected
        #   to the central server login page--gets confusing.
        form = RegisteredDevicePublicKeyForm(
            request.user, callback_url=request.REQUEST.get("callback_url") or request.REQUEST.get("prev")
        )
    return {"form": form}
예제 #3
0
class OrganizationManagementTestCase(KALiteCentralBrowserTestCase):
    USER_EMAIL = "*****@*****.**"
    USER_PASSWORD = "******"
    ORG_NAME = "test org"
    ZONE_NAME = "test zone"
    FACILITY_NAME = "test facility"

    def setUp(self):
        super(OrganizationManagementTestCase, self).setUp()
        self.user = User(username=self.USER_EMAIL, email=self.USER_EMAIL)
        self.user.set_password(self.USER_PASSWORD)
        self.user.save()
        self.org = Organization(name=self.ORG_NAME, owner=self.user)
        self.org.save()
        self.org.add_member(self.user)
        self.org.save()
예제 #4
0
파일: browser_tests.py 프로젝트: louhow/lex
class OrganizationManagementTestCase(KALiteCentralBrowserTestCase):
    USER_EMAIL = "*****@*****.**"
    USER_PASSWORD = "******"
    ORG_NAME = "test org"
    ZONE_NAME = "test zone"
    FACILITY_NAME = "test facility"

    def setUp(self):
        super(OrganizationManagementTestCase, self).setUp()
        self.user = User(username=self.USER_EMAIL, email=self.USER_EMAIL)
        self.user.set_password(self.USER_PASSWORD)
        self.user.save()
        self.org = Organization(name=self.ORG_NAME, owner=self.user)
        self.org.save()
        self.org.add_member(self.user)
        self.org.save()