Refactoring for flask-login