From 577a3a8110bfdcd04f8bb4457492d2e9b8f741df Mon Sep 17 00:00:00 2001 From: Mathijs de Bruin Date: Thu, 3 Jul 2014 15:21:03 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Enable=20=E2=80=98next=E2=80=99=20redirecti?= =?UTF-8?q?on=20after=20registration.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flask_security/forms.py | 8 ++++++-- flask_security/utils.py | 4 ++-- flask_security/views.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/flask_security/forms.py b/flask_security/forms.py index 44db7a7..8367549 100644 --- a/flask_security/forms.py +++ b/flask_security/forms.py @@ -244,8 +244,12 @@ class ConfirmRegisterForm(Form, RegisterFormMixin, pass -class RegisterForm(ConfirmRegisterForm, PasswordConfirmFormMixin): - pass +class RegisterForm(ConfirmRegisterForm, PasswordConfirmFormMixin, + NextFormMixin): + def __init__(self, *args, **kwargs): + super(RegisterForm, self).__init__(*args, **kwargs) + if not self.next.data: + self.next.data = request.args.get('next', '') class ResetPasswordForm(Form, NewPasswordFormMixin, PasswordConfirmFormMixin): diff --git a/flask_security/utils.py b/flask_security/utils.py index f519b3d..1fd7614 100644 --- a/flask_security/utils.py +++ b/flask_security/utils.py @@ -234,8 +234,8 @@ def get_post_login_redirect(declared=None): return get_post_action_redirect('SECURITY_POST_LOGIN_VIEW', declared) -def get_post_register_redirect(): - return get_post_action_redirect('SECURITY_POST_REGISTER_VIEW') +def get_post_register_redirect(declared=None): + return get_post_action_redirect('SECURITY_POST_REGISTER_VIEW', declared) def find_redirect(key): diff --git a/flask_security/views.py b/flask_security/views.py index be80372..4786af3 100644 --- a/flask_security/views.py +++ b/flask_security/views.py @@ -122,7 +122,7 @@ def register(): login_user(user) if not request.json: - return redirect(get_post_register_redirect()) + return redirect(get_post_register_redirect(form.next.data)) return _render_json(form, include_auth_token=True) if request.json: From d1ec38ea18deca57ba7e67c500c97d512c89bd2e Mon Sep 17 00:00:00 2001 From: Mathijs de Bruin Date: Thu, 3 Jul 2014 15:22:56 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Keep=20value=20of=20=E2=80=98next=E2=80=99?= =?UTF-8?q?=20in=20menu=20links.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows moving from the login to registration (and vice versa) while keeping the redirection URL, enabling a much smoother user experience. --- flask_security/templates/security/_menu.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flask_security/templates/security/_menu.html b/flask_security/templates/security/_menu.html index 5291f80..1917b72 100644 --- a/flask_security/templates/security/_menu.html +++ b/flask_security/templates/security/_menu.html @@ -1,9 +1,9 @@ {% if security.registerable or security.recoverable or security.confirmabled %}

Menu