mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-04 17:20:07 +08:00
Add login to security blueprint
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
{%- if current_user.is_authenticated() -%}
|
||||
<a href="{{ url_for('security.logout') }}">Log out</a>
|
||||
{%- else -%}
|
||||
<a href="{{ url_for('login') }}">Log in</a>
|
||||
<a href="{{ url_for('security.login') }}">Log in</a>
|
||||
{%- endif -%}
|
||||
</li>
|
||||
</ul>
|
||||
@@ -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',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% from "security/_macros.html" import render_field_with_errors, render_field %}
|
||||
{% include "security/_messages.html" %}
|
||||
<h1>Login</h1>
|
||||
<form action="{{ url_for_security('authenticate') }}" method="POST" name="login_form">
|
||||
<form action="{{ url_for_security('login') }}" method="POST" name="login_form">
|
||||
{{ login_form.hidden_tag() }}
|
||||
{{ render_field_with_errors(login_form.email) }}
|
||||
{{ render_field_with_errors(login_form.password) }}
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class DefaultSecurityTests(SecurityTest):
|
||||
|
||||
def test_login_view(self):
|
||||
r = self._get('/login')
|
||||
self.assertIn('Login Page', r.data)
|
||||
self.assertIn('<h1>Login</h1>', r.data)
|
||||
|
||||
def test_authenticate(self):
|
||||
r = self.authenticate()
|
||||
|
||||
Reference in New Issue
Block a user