miguelgrinberg / flasky

Companion code to my O'Reilly book "Flask Web Development", second edition.
MIT License
8.52k stars 4.2k forks source link

Redirect issue in Example 8-23 #554

Closed samuelerickson977 closed 1 year ago

samuelerickson977 commented 1 year ago

In Example 8-23 we see that resend_confirmation function redirects the user to 'main.index'. However, the application will not allow this, because in Example 8-22 we see that there is an auth.before_request decorator which will redirect this request because it is outside of the auth blueprint.

miguelgrinberg commented 1 year ago

What is the issue? The redirect is allowed. It will be intercepted by the before_request handler in the auth blueprint, which will in tern redirect to the unconfirmed page. The alert that tells the user that the confirmation email was resent will appear just fine. Or is it not appearing for you?

samuelerickson977 commented 1 year ago

The application works fine. I was just wondering why you chose to do it this as opposed to redirecting to the unconfirmed page.

miguelgrinberg commented 1 year ago

This is based on the idea that one part of the application should not know how another part works. The least coupling there is, your application is more robust and is able to better adapt to changes. For example, if you wanted to remove the unconfirmed feature, and you have several places in the application that redirect to the unconfirmed page because they know this page exists, then you will have to go through all those places and fix the code. In the way that I've done it, the knowledge of the unconfirmed use is only in one place, the before request handler.

samuelerickson977 commented 1 year ago

That makes so much sense. Thank you for answering my question!