def process_view(self, request, view, args, kwargs): view_name = view.__name__ is_logged_in = request.user.is_authenticated() login_url = reverse('auth_login') if koboform.active and koboform.autoredirect: login_url = koboform.redirect_url(login_url) if view_name is 'login': return HttpResponseRedirect( koboform.login_url(next_kobocat_url='/')) if view_name is 'logout': return HttpResponseRedirect( koboform.redirect_url('/accounts/logout/')) if view_name is 'FHRegistrationView': return HttpResponseRedirect( koboform.redirect_url('/accounts/register/')) if view_name in DISABLED_VIEWS: if is_logged_in: redirect_to = reverse( 'onadata.apps.main.views.profile', kwargs={'username': request.user.username}) else: if koboform.active and koboform.autoredirect: redirect_to = koboform.login_url( next_kobocat_url=request.path) else: redirect_to = login_url # redirect_to = '%s?next=/kobocat%s' % (login_url, request.path) return HttpResponseRedirect(redirect_to) elif not is_logged_in and (view_name in REDIRECT_IF_NOT_LOGGED_IN): return HttpResponseRedirect(login_url) pass
def process_view(self, request, view, args, kwargs): view_name = view.__name__ is_logged_in = request.user.is_authenticated() login_url = reverse('auth_login') if koboform.active and koboform.autoredirect: login_url = koboform.redirect_url(login_url) if view_name is 'login': return HttpResponseRedirect(koboform.login_url(next_kobocat_url='/')) if view_name is 'logout': return HttpResponseRedirect(koboform.redirect_url('/accounts/logout/')) if view_name is 'FHRegistrationView': return HttpResponseRedirect(koboform.redirect_url('/accounts/register/')) if view_name in DISABLED_VIEWS: if is_logged_in: redirect_to = reverse('onadata.apps.main.views.profile', kwargs={'username': request.user.username}) else: if koboform.active and koboform.autoredirect: redirect_to = koboform.login_url(next_kobocat_url=request.path) else: redirect_to = login_url # redirect_to = '%s?next=/kobocat%s' % (login_url, request.path) return HttpResponseRedirect(redirect_to) elif not is_logged_in and (view_name in REDIRECT_IF_NOT_LOGGED_IN): return HttpResponseRedirect(login_url) pass
def test_redirect_to_login_if_user_does_not_exist(self): response = self.client.get(reverse(profile, kwargs={'username': '******'})) self.assertEqual(response.status_code, 302) login_url = reverse('login') if koboform.active and koboform.autoredirect: redirect_to = koboform.login_url() else: redirect_to = login_url self.assertEqual(response.url, redirect_to)
def test_dl_xls_redirect_to_login_to_anon_if_public(self): self.xform.shared = True self.xform.save() response = self.anon.get(reverse(download_xlsform, kwargs={ 'username': self.user.username, 'id_string': self.xform.id_string })) login_url = reverse('login') if koboform.active and koboform.autoredirect: redirect_to = koboform.login_url() else: redirect_to = login_url self.assertEqual(response.url, redirect_to) self.assertEqual(response.status_code, 302)