I have a site running with djangocms and I need the login and logout capabilities of django-userena, it's easy for me to use this because every user will have a profile page too. The design for the menu in every page states that a simple login form has to be in the top right corner of the menu. I have already done that, but I need the django-userena login to work with it. How can I do it?
I have tried to add the form in my base.html. Also tried with a middleware.py like this
class LoginFormMiddleware(object):
def process_request(self, request):
from userena.forms import AuthenticationForm
if request.method == 'POST' and request.POST.has_key('base-account') and request.POST['base-account'] == 'Login':
form = AuthenticationForm(data=request.POST, prefix="login")
if form.is_valid():
from django.contrib.auth import login
login(request, form.get_user())
request.method = 'GET'
else:
form = AuthenticationForm(request, prefix="login")
request.login_form = form
class LogoutFormMiddleware(object):
def process_request(self, request):
if request.method == 'POST' and request.POST.has_key('base-account') and request.POST['base-account'] == 'Logout':
from userena.views import signout
signout(request)
request.method = 'GET'
base.html
<form class="navbar-form navbar-right login-strip" action="" method="post">
{% csrf_token %}
<p id="login">
{{ request.login_form.non_field_errors }}
{% for field in request.login_form %}
{{ field.errors }}
{{ field.label_tag}}: {{ field }}
{% endfor %}
<input type="submit" name="base-account" value="Login" />
</p>
</form>
{% else %}
<form class="navbar-form navbar-right login-strip" action="" method="post">
{% csrf_token %}
<p id="logout">Logged in as <b>{{ request.user.username }}</b>.
<input type="submit" name="base-account" value="Logout" />
</p>
</form>
{% endif %}
This gives me this error 'WSGIRequest' object has no attribute 'get'
I have tried a lot of thighs in this. Now I'm not using any side django-authetication I just put some code in my menu.html this way I can login and log out as need. My problem was the normal account has no way to logout.
My work around is that:
menu.html
urls.py added this:
url(r'^accounts/', include('django.contrib.auth.urls')),