from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib import messages
from mezzanine.accounts.forms import ProfileForm, LoginForm
from mezzanine.accounts.views import login, logout
# from account_management.forms import UserRegistrationForm
from account_management.models import UserAccount
from account_management.registration import User_Registration
def LoginRequest(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
else:
if request.method == 'POST':
username = request.POST.get('email')
password = request.POST.get('password')
current_user = LoginForm(username,password)
if current_user is not None:
login(request, current_user)
# Building a session for the authenticated
user
request.session['current_user'] =
UserAccount.objects.get(email=username)
# account_type is a string !! dont forget!
if request.session['current_user'].account_type
== "1":
return HttpResponseRedirect (
'/userhome/')
# account_type is a string !! dont
forget!
elif
request.session['current_user'].account_type
== "2":
return HttpResponseRedirect (
'/businesshome/')
else :
return HttpResponseRedirect (
'/no_account_type/')
else :
return HttpResponseRedirect(
'Account_login_error')
else:
return render_to_response("login.html", locals(),
context_instance=RequestContext(request))
We are trying to build a login page view which will detect if the user is
logged in, if so, it would redirect the user to the profile page; If the
user is not logged in, it would load the login form.
The problem is that, even if the user is logged in, the request.user will
be shown as anonymous user. Thanks.
Note: I have used ACCOUNTS_NO_USERNAME = True in settings.py file of my
root project.
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.