How do I override the flash security login?

I want to do some customization when the user logs in. The problem is that the project uses flash protection, which implicitly processes the user's login. I want to check some user records in the database when users login.

how can I override the flash drive login function?

I saw a similar post but didn't work. Also, this is not exactly what I want to do. Maybe I need to stop the default behavior in case of some users.

So who has this problem? How can i do this?

Thank!

+3


source to share


1 answer


You can override the login form when you configure checkbox-security:

user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore, login_form=CustomLoginForm)

      

Next, create your own login form class that extends the default registration form. And override the validate function to do things before or after the login attempt.



from flask_security.forms import LoginForm

class CustomLoginForm(LoginForm):
    def validate(self):
        # Put code here if you want to do stuff before login attempt

        response = super(CustomLoginForm, self).validate()

        # Put code here if you want to do stuff after login attempt

        return response

      

"reponse" will be True or False based on whether the login was successful or not. If you want to check for possible errors that occurred during the login attempt, see "Self.errors"

Hi? Kevin;)

+4


source







All Articles