Redirect user to profile on first login.

see #596
This commit is contained in:
Antoine Nguyen
2015-11-16 14:12:16 +01:00
parent 7446bdb6af
commit 64ca18891e
3 changed files with 43 additions and 7 deletions
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.contrib.auth.models
class Migration(migrations.Migration):
dependencies = [
('core', '0006_auto_20151114_1518'),
]
operations = [
migrations.AlterModelManagers(
name='user',
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.AlterField(
model_name='user',
name='groups',
field=models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', verbose_name='groups'),
),
migrations.AlterField(
model_name='user',
name='last_login',
field=models.DateTimeField(null=True, verbose_name='last login', blank=True),
),
]
+1 -1
View File
@@ -59,7 +59,7 @@ class User(PermissionsMixin):
)
password = models.CharField(ugettext_lazy('password'), max_length=256)
last_login = models.DateTimeField(
ugettext_lazy('last login'), default=timezone.now
ugettext_lazy('last login'), blank=True, null=True
)
language = models.CharField(
+11 -6
View File
@@ -23,6 +23,10 @@ def dologin(request):
user = authenticate(username=form.cleaned_data["username"],
password=form.cleaned_data["password"])
if user and user.is_active:
nextlocation = None
if not user.last_login:
# Redirect to profile on first login
nextlocation = reverse("core:user_index")
login(request, user)
if not form.cleaned_data["rememberme"]:
request.session.set_expiry(0)
@@ -38,12 +42,13 @@ def dologin(request):
form.cleaned_data["username"],
form.cleaned_data["password"])
nextlocation = request.POST.get("next", None)
if nextlocation is None or nextlocation == "None":
if user.group == "SimpleUsers":
nextlocation = reverse("topredirection")
else:
nextlocation = reverse("admin:domain_list")
if nextlocation is None:
nextlocation = request.POST.get("next", None)
if nextlocation is None or nextlocation == "None":
if user.group == "SimpleUsers":
nextlocation = reverse("topredirection")
else:
nextlocation = reverse("admin:domain_list")
return HttpResponseRedirect(nextlocation)
error = _(
"Your username and password didn't match. Please try again.")