allow redirect /accounts/ to an external page (fixes #21770)

New setting is A2_ACCOUNTS_URL.
This commit is contained in:
Benjamin Dauvergne 2018-02-19 17:00:02 +01:00
parent 740b0ad4b2
commit 666d016b91
3 changed files with 15 additions and 0 deletions

View File

@ -190,6 +190,7 @@ default_settings = dict(
A2_SET_RANDOM_PASSWORD_ON_RESET=Setting(
default=True,
definition='Set a random password on request to reset the password from the front-office'),
A2_ACCOUNTS_URL=Setting(default=None, definition='IdP has no account page, redirect to this one.'),
)
app_settings = AppSettings(default_settings)

View File

@ -370,6 +370,11 @@ homepage = Homepage.as_view()
class ProfileView(cbv.TemplateNamesMixin, TemplateView):
template_names = ['idp/account_management.html', 'authentic2/accounts.html']
def dispatch(self, request, *args, **kwargs):
if app_settings.A2_ACCOUNTS_URL:
return utils.redirect(request, app_settings.A2_ACCOUNTS_URL)
return super(ProfileView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
ctx = super(ProfileView, self).get_context_data(**kwargs)
frontends = utils.get_backends('AUTH_FRONTENDS')

View File

@ -35,3 +35,12 @@ def test_account_delete(app, simple_user):
def test_login_invalid_next(app):
app.get(reverse('auth_login') + '?next=plop')
def test_custom_account(settings, app, simple_user):
response = login(app, simple_user, path=reverse('account_management'))
assert response.status_code == 200
settings.A2_ACCOUNTS_URL = 'http://combo/account/'
response = app.get(reverse('account_management'))
assert response.status_code == 302
assert response['Location'] == settings.A2_ACCOUNTS_URL