general: add possibility to redirect unloggued users (#15814)
This commit is contained in:
parent
ea08a76477
commit
1b29b385a0
|
@ -278,6 +278,13 @@ def page(request):
|
|||
profile.save()
|
||||
return HttpResponseRedirect(settings.COMBO_INITIAL_LOGIN_PAGE_PATH)
|
||||
|
||||
if parts == ['index'] and settings.COMBO_WELCOME_PAGE_PATH and (
|
||||
not request.user or request.user.is_anonymous()):
|
||||
if not request.session.setdefault('visited', False):
|
||||
# first visit, the user is not logged in.
|
||||
request.session['visited'] = True
|
||||
return HttpResponseRedirect(settings.COMBO_WELCOME_PAGE_PATH)
|
||||
|
||||
try:
|
||||
page = Page.objects.get(slug=parts[-1])
|
||||
except Page.DoesNotExist:
|
||||
|
|
|
@ -270,6 +270,8 @@ JSON_CELL_TYPES = {}
|
|||
# page to redirect the first time the user logs in.
|
||||
COMBO_INITIAL_LOGIN_PAGE_PATH = None
|
||||
|
||||
# page to redirect on the first visit, to suggest user to log in.
|
||||
COMBO_WELCOME_PAGE_PATH = None
|
||||
|
||||
local_settings_file = os.environ.get('COMBO_SETTINGS_FILE',
|
||||
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
|
||||
|
|
|
@ -260,3 +260,26 @@ def test_initial_login_page(app, admin_user):
|
|||
|
||||
# visit again
|
||||
resp = app.get('/', status=200)
|
||||
|
||||
|
||||
def test_welcome_page(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='Home', slug='index', template_name='standard')
|
||||
page.save()
|
||||
page = Page(title='Welcome', slug='welcome', template_name='standard')
|
||||
page.save()
|
||||
|
||||
with override_settings(COMBO_WELCOME_PAGE_PATH='/welcome/'):
|
||||
app.cookiejar.clear()
|
||||
resp = app.get('/', status=302)
|
||||
assert resp.location == 'http://testserver/welcome/'
|
||||
|
||||
resp = app.get('/', status=200)
|
||||
|
||||
app.cookiejar.clear()
|
||||
resp = app.get('/', status=302)
|
||||
assert resp.location == 'http://testserver/welcome/'
|
||||
|
||||
app.cookiejar.clear()
|
||||
app = login(app)
|
||||
resp = app.get('/', status=200)
|
||||
|
|
Loading…
Reference in New Issue