Fix the behavior during login

master
kaiyou 7 years ago
parent bb8c4e86c1
commit f615af4a88

@ -34,7 +34,7 @@ default_config = {
'FRONTEND': 'none', 'FRONTEND': 'none',
'TLS_FLAVOR': 'cert', 'TLS_FLAVOR': 'cert',
'CERTS_PATH': '/certs', 'CERTS_PATH': '/certs',
'PASSWORD_SCHEME': 'SHA512-CRYPT' 'PASSWORD_SCHEME': 'SHA512-CRYPT',
} }
# Load configuration from the environment if available # Load configuration from the environment if available
@ -71,9 +71,29 @@ login_manager = flask_login.LoginManager()
login_manager.init_app(app) login_manager.init_app(app)
login_manager.login_view = ".login" login_manager.login_view = ".login"
@login_manager.unauthorized_handler
def handle_needs_login():
return flask.redirect(
flask.url_for('.login', next=flask.request.endpoint)
)
@app.context_processor @app.context_processor
def inject_user(): def inject_user():
return dict(current_user=flask_login.current_user) return dict(current_user=flask_login.current_user)
# Import views # Import views
from mailu.views import * from mailu.views import *
# Create the prefix middleware
class PrefixMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
prefix = environ.get('HTTP_X_FORWARDED_PREFIX', '')
if prefix:
environ['SCRIPT_NAME'] = prefix
return self.app(environ, start_response)
app.wsgi_app = PrefixMiddleware(app.wsgi_app)

@ -21,11 +21,9 @@ def login():
user = models.User.login(form.email.data, form.pw.data) user = models.User.login(form.email.data, form.pw.data)
if user: if user:
flask_login.login_user(user) flask_login.login_user(user)
redirect = flask.request.args.get('next') endpoint = flask.request.args.get('next')
parsed_redirect = parse.urlparse(redirect) return flask.redirect(flask.url_for(endpoint)
if parsed_redirect.scheme or parsed_redirect.netloc: or flask.url_for('.index'))
return flask.abort(400)
return flask.redirect(redirect or flask.url_for('.index'))
else: else:
flask.flash('Wrong e-mail or password', 'error') flask.flash('Wrong e-mail or password', 'error')
return flask.render_template('login.html', form=form) return flask.render_template('login.html', form=form)

@ -90,7 +90,7 @@ services:
image: mailu/admin:$VERSION image: mailu/admin:$VERSION
labels: labels:
- traefik.enable=true - traefik.enable=true
- traefik.admin.frontend.rule=Host:$HOSTNAME;PathPrefix:/admin/ - traefik.admin.frontend.rule=Host:$HOSTNAME;PathPrefixStrip:/admin/
- traefik.admin.port=80 - traefik.admin.port=80
- traefik.home.frontend.rule=Host:$HOSTNAME;Path:/ - traefik.home.frontend.rule=Host:$HOSTNAME;Path:/
- traefik.home.port=80 - traefik.home.port=80

Loading…
Cancel
Save