Flask-Security Register Redirect

user592419

I have my login and register on the main page, index. When the user logs in or registers successfully, everything's gravy.

However, when there's an error, Flask-Security redirects the user to a different page, /login and /register respectively. I don't see a need to include these separate pages. How do I have Flask-Security not redirect and instead show the errors right there on the index page?

I've tried setting SECURITY_{REGISTER,LOGIN}_USER_TEMPLATE='/index.html' but that did not work.

Doobeh

SECURITY_{REGISTER,LOGIN}_USER_TEMPLATE requires a template, you're specifying a URL. So if you change it to SECURITY_REGISTER_USER_TEMPLATE='index.html' it'll try and render the template you mention.

But what I think you really should do, is use JSON to manage your login features since you're squidging them into a single page.

Flask-Security's login and register views look out for JSON requests, and so if you send it some, it'll in turn respond with JSON, and in the case of a bad password/bad email etc, it'll include the errors in the JSON return data, so you could then handle your logins purely via Ajax.

You can see how the login watches for JSON in the source and how the returned data is rendered

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related