|
5 | 5 | Flask-Security views module |
6 | 6 |
|
7 | 7 | :copyright: (c) 2012 by Matt Wright. |
8 | | -:copyright: (c) 2019-2025 by J. Christopher Wagner (jwag). |
| 8 | +:copyright: (c) 2019-2026 by J. Christopher Wagner (jwag). |
9 | 9 | :license: MIT, see LICENSE for more details. |
10 | 10 |
|
11 | 11 | CSRF is tricky. By default all our forms have CSRF protection built in via |
|
105 | 105 | check_and_update_authn_fresh, |
106 | 106 | check_and_get_token_status, |
107 | 107 | config_value as cv, |
| 108 | + confirm_redirect, |
108 | 109 | do_flash, |
109 | 110 | get_identity_attributes, |
110 | 111 | get_message, |
@@ -217,21 +218,9 @@ def login() -> ResponseValue: |
217 | 218 | } |
218 | 219 | return base_render_json(form, additional=payload) |
219 | 220 |
|
220 | | - if ( |
221 | | - form.requires_confirmation |
222 | | - and cv("REQUIRES_CONFIRMATION_ERROR_VIEW") |
223 | | - and not cv("RETURN_GENERIC_RESPONSES") |
224 | | - ): |
225 | | - # Validation failed BECAUSE user needs to confirm |
226 | | - assert form.user_authenticated |
227 | | - assert form.email.data # email_required validator |
228 | | - do_flash(*get_message("CONFIRMATION_REQUIRED")) |
229 | | - return redirect( |
230 | | - get_url( |
231 | | - cv("REQUIRES_CONFIRMATION_ERROR_VIEW"), |
232 | | - qparams={"email": form.email.data}, |
233 | | - ) |
234 | | - ) |
| 221 | + if rurl := confirm_redirect(form, "email"): |
| 222 | + return rurl |
| 223 | + |
235 | 224 | return _security.render_template( |
236 | 225 | cv("LOGIN_USER_TEMPLATE"), |
237 | 226 | login_user_form=form, |
@@ -552,18 +541,8 @@ def forgot_password(): |
552 | 541 | # Never include user info since this is an anonymous endpoint. |
553 | 542 | return base_render_json(form, include_user=False) |
554 | 543 |
|
555 | | - if ( |
556 | | - form.requires_confirmation |
557 | | - and cv("REQUIRES_CONFIRMATION_ERROR_VIEW") |
558 | | - and not cv("RETURN_GENERIC_RESPONSES") |
559 | | - ): |
560 | | - do_flash(*get_message("CONFIRMATION_REQUIRED")) |
561 | | - return redirect( |
562 | | - get_url( |
563 | | - cv("REQUIRES_CONFIRMATION_ERROR_VIEW"), |
564 | | - qparams={"email": form.email.data}, |
565 | | - ) |
566 | | - ) |
| 544 | + if rurl := confirm_redirect(form, "email"): |
| 545 | + return rurl |
567 | 546 |
|
568 | 547 | if is_user_authenticated(current_user): |
569 | 548 | form.email.data = current_user.email |
@@ -1198,6 +1177,9 @@ def recover_username(): |
1198 | 1177 | if _security._want_json(request): |
1199 | 1178 | return base_render_json(form, include_user=False) |
1200 | 1179 |
|
| 1180 | + if rurl := confirm_redirect(form, "email"): |
| 1181 | + return rurl |
| 1182 | + |
1201 | 1183 | return _security.render_template( |
1202 | 1184 | cv("USERNAME_RECOVERY_TEMPLATE"), |
1203 | 1185 | username_recovery_form=form, |
|
0 commit comments