diff --git a/example/app.py b/example/app.py index 0bf4b3f..f67baf1 100644 --- a/example/app.py +++ b/example/app.py @@ -56,17 +56,6 @@ def create_app(auth_config): def index(): return render_template('index.html', content='Home Page') - @app.route('/login') - def login(): - if app.config['SECURITY_PASSWORDLESS']: - form = PasswordlessLoginForm() - template = 'passwordless_login' - else: - form = LoginForm() - template = 'login' - - return render_template(template + '.html', content='Login Page', form=form) - @app.route('/custom_login') def custom_login(): return render_template('login.html', content='Custom Login Page', form=LoginForm()) diff --git a/example/templates/_nav.html b/example/templates/_nav.html index 7dd1347..4c71709 100644 --- a/example/templates/_nav.html +++ b/example/templates/_nav.html @@ -14,7 +14,7 @@ {%- if current_user.is_authenticated() -%} Log out {%- else -%} - Log in + Log in {%- endif -%} \ No newline at end of file diff --git a/flask_security/core.py b/flask_security/core.py index b810ac1..07986ef 100644 --- a/flask_security/core.py +++ b/flask_security/core.py @@ -37,6 +37,7 @@ _default_config = { 'PASSWORD_SALT': None, 'PASSWORD_HMAC': False, 'AUTH_URL': '/auth', + 'LOGIN_URL': '/login', 'LOGOUT_URL': '/logout', 'REGISTER_URL': '/register', 'RESET_URL': '/reset', diff --git a/flask_security/templates/security/login.html b/flask_security/templates/security/login.html index 9d9c26f..2e171cd 100644 --- a/flask_security/templates/security/login.html +++ b/flask_security/templates/security/login.html @@ -1,7 +1,7 @@ {% from "security/_macros.html" import render_field_with_errors, render_field %} {% include "security/_messages.html" %}

Login

-
+ {{ login_form.hidden_tag() }} {{ render_field_with_errors(login_form.email) }} {{ render_field_with_errors(login_form.password) }} diff --git a/flask_security/views.py b/flask_security/views.py index d7f6e86..9fe14cd 100644 --- a/flask_security/views.py +++ b/flask_security/views.py @@ -93,6 +93,12 @@ def authenticate(): return redirect(request.referrer or _security.login_manager.login_view) +def login(): + form = PasswordlessLoginForm() if _security.passwordless else LoginForm() + template = 'send_login' if _security.passwordless else 'login' + return render_template('security/%s.html' % template, login_form=form) + + def logout(): """View function which handles a logout request.""" @@ -288,6 +294,9 @@ def create_blueprint(app, name, import_name, **kwargs): methods=['POST'], endpoint='authenticate')(authenticate) + bp.route(config_value('LOGIN_URL', app=app), + endpoint='login')(login) + bp.route(config_value('LOGOUT_URL', app=app), endpoint='logout')(login_required(logout)) diff --git a/tests/functional_tests.py b/tests/functional_tests.py index d96b847..80df7fd 100644 --- a/tests/functional_tests.py +++ b/tests/functional_tests.py @@ -36,7 +36,7 @@ class DefaultSecurityTests(SecurityTest): def test_login_view(self): r = self._get('/login') - self.assertIn('Login Page', r.data) + self.assertIn('

Login

', r.data) def test_authenticate(self): r = self.authenticate()