Repository: django-wiki/django-wiki

Issue:
New registered user login causes too many redirects
I' m setting up the wiki (from repo) with Django 1.5 on Ubuntu 12.10, python 2.7.3 .
Following the installation directions in the readme I get the following issue:

If I click on `sign up`, sign up a new user and in the following form try to login as this new signed-up user, I am getting:

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

( I get an analogous error message by chromium)

If I only use the user created by `syncdb`, everything is fine.



Discussion:
Thanks for the report! I am unable to reproduce this, also trying out recursive patterns like `?next=/_accounts/login/`. On these occasions, there should be a single redirect back to the login page, which will then HTTP redirect the agent to `settings.LOGIN_REDIRECT_URL`.

Can you check your `settings.LOGIN_REDIRECT_URL` that it's not set to your LOGIN_URL? And what is the value of `?next` URL param when you're logging in?

Hi, thanks for the fast answer.
1. My settings:

```
>>> from wiki.conf import settings
>>> settings.ACCOUNT_HANDLING
True
>>> settings.LOGIN_URL
<django.utils.functional.__proxy__ object at 0x24c84d0>
```

The login page is: `http://localhost:8000/wiki/_accounts/login/?next=/wiki/` . Today, it works (Maybe because there is a root article?). The strange thing is now. If I click to register a new user the login mask after registration redirects me to 
`http://localhost:8000/accounts/profile/` .

**_Now, I got the way to reproduce it:**_
1. `python manage.py flush`
2. I go to `http://localhost:8000/wiki` and I am getting redirected to `http://localhost:8000/wiki/_accounts/login/?next=/wiki/create-root/` ( *\* Which maybe has got to do with the error *\* , but seems fine, as after the flush there is no root)
3. goto sign up ( I get to `http://localhost:8000/wiki/_accounts/sign-up/` )
4. after clicking `sign me up` I am redirected to `http://localhost:8000/wiki/_accounts/login/`
5. using the user created in step 3. login: i get `http://localhost:8000/accounts/profile/` ( _which is not in_ `urls.py`)
6. when now typing in `localhost:8000/wiki/` I am getting redirected to `http://localhost:8000/wiki/_accounts/login/?next=/wiki/create-root/` and firefox gives me `The page isn't redirecting properly`

Hope, it helps
My `urls.py` :

```
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
urlpatterns += patterns('',
    (r'^wiki/notify/', get_notify_pattern()),
    (r'^wiki/', get_wiki_pattern())
```

)

Hi!

I think I understand the problem then :) Thanks for explaining it!

Login Page -> Successfully logged in (but no root article) -> Create Root (but user is not superuser) -> Login Page (is already logged in so forwarding to Create Root)

So basically, it will work if you always login with the superuser first time. I'll find a fix for this.

Thank you for coding :+1:  Great software so far


Resolving patch:
diff --git a/wiki/urls.py b/wiki/urls.py
--- a/wiki/urls.py
+++ b/wiki/urls.py
@@ -55,6 +55,7 @@ def get_root_urls(self):
         urlpatterns = patterns('',
             url('^$', self.article_view_class.as_view(), name='root', kwargs={'path': ''}),
             url('^create-root/$', article.CreateRootView.as_view(), name='root_create'),
+            url('^missing-root/$', article.MissingRootView.as_view(), name='root_missing'),
             url('^_search/$', get_class_from_str(self.search_view_class).as_view(), name='search'),
             url('^_revision/diff/(?P<revision_id>\d+)/$', self.article_diff_view, name='diff'),
        )
diff --git a/wiki/views/article.py b/wiki/views/article.py
--- a/wiki/views/article.py
+++ b/wiki/views/article.py
@@ -720,8 +720,8 @@ class CreateRootView(FormView):
     template_name = 'wiki/create_root.html'
 
     def dispatch(self, request, *args, **kwargs):
-        if not request.user.is_superuser:
-            return redirect(settings.LOGIN_URL + "?next=" + reverse("wiki:root_create"))
+        if not self.request.user.is_superuser:
+            return redirect("wiki:root_missing")
 
         try:
             root = models.URLPath.root()
@@ -748,3 +748,7 @@ def get_context_data(self, **kwargs):
         data = super(CreateRootView, self).get_context_data(**kwargs)
         data['editor'] = editors.getEditor()
         return data
+
+
+class MissingRootView(TemplateView):
+    template_name = 'wiki/root_missing.html'


Test patch: