Redirect to configured ENV VAR for Admin/Webmail, further simplify nginx config.

master
Dimitri Huisman 3 years ago
parent f1a60aa6ea
commit bdcc183165

@ -1,3 +1,4 @@
from werkzeug.utils import redirect
from mailu import models from mailu import models
from mailu.sso import sso, forms from mailu.sso import sso, forms
from mailu.ui import access from mailu.ui import access
@ -22,14 +23,16 @@ def login():
if form.validate_on_submit(): if form.validate_on_submit():
if str(form.target.data) == 'Admin': if str(form.target.data) == 'Admin':
endpoint = 'ui.index' endpoint = 'ui.index'
destination = app.config['WEB_ADMIN']
elif str(form.target.data) == 'Webmail': elif str(form.target.data) == 'Webmail':
endpoint = 'ui.webmail' endpoint = 'ui.webmail'
destination = app.config['WEB_WEBMAIL']
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.session.regenerate() flask.session.regenerate()
flask_login.login_user(user) flask_login.login_user(user)
return flask.redirect(flask.url_for(endpoint)) return flask.redirect(destination)
else: else:
flask.flash('Wrong e-mail or password', 'error') flask.flash('Wrong e-mail or password', 'error')
client_ip = flask.request.headers["X-Real-IP"] if 'X-Real-IP' in flask.request.headers else flask.request.remote_addr client_ip = flask.request.headers["X-Real-IP"] if 'X-Real-IP' in flask.request.headers else flask.request.remote_addr

@ -184,20 +184,10 @@ http {
location @webmail_login { location @webmail_login {
return 302 /sso/login?next=ui.webmail; return 302 /sso/login?next=ui.webmail;
} }
location ^~ /ui/webmail {
include /etc/nginx/proxy.conf;
return 302 {{ WEB_WEBMAIL }};
}
{% else %} {% else %}
{% endif %} {% endif %}
{% if ADMIN == 'true' %} {% if ADMIN == 'true' %}
location ^~ /ui {
include /etc/nginx/proxy.conf;
rewrite ^/ui/(.*) {{ WEB_ADMIN }}/ui/$1 redirect;
}
location {{ WEB_ADMIN }} { location {{ WEB_ADMIN }} {
return 301 {{ WEB_ADMIN }}/ui; return 301 {{ WEB_ADMIN }}/ui;
} }

Loading…
Cancel
Save