general: add possibility to redirect to an "initial login" page (#6705)

This commit is contained in:
Frédéric Péters 2017-04-10 14:17:45 +02:00
parent 8e1ff3597c
commit ea08a76477
7 changed files with 81 additions and 0 deletions

View File

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('initial_login_view_timestamp', models.DateTimeField(null=True)),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
],
),
]

View File

23
combo/profile/models.py Normal file
View File

@ -0,0 +1,23 @@
# combo - content management system
# Copyright (C) 2014-2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
from django.db import models
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL)
initial_login_view_timestamp = models.DateTimeField(null=True)

View File

@ -29,6 +29,7 @@ from django.http import (Http404, HttpResponse, HttpResponseRedirect,
HttpResponsePermanentRedirect)
from django.shortcuts import render, resolve_url
from django.template import RequestContext, loader
from django.utils import timezone
if django.VERSION >= (1, 8):
from django.utils import lorem_ipsum
@ -46,6 +47,7 @@ else:
get_idps = lambda: []
from combo.data.models import CellBase, Page, ParentContentCell, TextCell
from combo.profile.models import Profile
from combo.apps.search.models import SearchCell
from combo import utils
@ -266,6 +268,16 @@ def page(request):
return HttpResponsePermanentRedirect('/')
if not parts:
parts = ['index']
if parts == ['index'] and settings.COMBO_INITIAL_LOGIN_PAGE_PATH and (
request.user and not request.user.is_anonymous()):
profile, created = Profile.objects.get_or_create(user=request.user)
if not profile.initial_login_view_timestamp:
# first connection of user, record that and redirect to welcome URL
profile.initial_login_view_timestamp = timezone.now()
profile.save()
return HttpResponseRedirect(settings.COMBO_INITIAL_LOGIN_PAGE_PATH)
try:
page = Page.objects.get(slug=parts[-1])
except Page.DoesNotExist:

View File

@ -60,6 +60,7 @@ INSTALLED_APPS = (
'gadjo',
'cmsplugin_blurp',
'combo.data',
'combo.profile',
'combo.manager',
'combo.public',
'combo.apps.wcs',
@ -266,6 +267,9 @@ LINGO_NO_ONLINE_PAYMENT_REASONS = {}
JSON_CELL_TYPES = {}
# page to redirect the first time the user logs in.
COMBO_INITIAL_LOGIN_PAGE_PATH = None
local_settings_file = os.environ.get('COMBO_SETTINGS_FILE',
os.path.join(os.path.dirname(__file__), 'local_settings.py'))

View File

@ -241,3 +241,22 @@ def test_ajax_cell(app):
resp = app.get(reverse('combo-public-ajax-page-cell',
kwargs={'page_pk': page.id, 'cell_reference': cell.get_reference()}),
status=403)
def test_initial_login_page(app, admin_user):
Page.objects.all().delete()
page = Page(title='Home', slug='index', template_name='standard')
page.save()
page = Page(title='Initial Login', slug='initial-login', template_name='standard', public=False)
page.save()
with override_settings(COMBO_INITIAL_LOGIN_PAGE_PATH='/initial-login/'):
resp = app.get('/', status=200)
# first visit
app = login(app)
resp = app.get('/', status=302)
assert resp.location == 'http://testserver/initial-login/'
# visit again
resp = app.get('/', status=200)