I currently have a login page that sends all authenticated users to a main page. How do I configure my code such that one group of users are sent to a specific url (custom main page), and other groups are sent to other urls?
The grouping of users would be done according the company they work for. Each group of company’s employees would be directed to an area of the site where they could see records from their company, but not others.
The existing login view is very simple:
def login_page(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect("main_page.html")
else:
return HttpResponseRedirect('/')
else:
return HttpResponseRedirect('/')
A relatively simple way to do it would be to create a field in the user profile to indicate that the user is a part of the special group of users you want to redirect to the special page.
Then, upon logging in, check for the flag in the user’s profile and redirect accordingly.