Make header translatable. More finishing touches.

master
Diman0 3 years ago
parent fbe0a446b9
commit f4cde61148

@ -11,7 +11,7 @@ LOCALPART_REGEX = "^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`
class LoginForm(flask_wtf.FlaskForm): class LoginForm(flask_wtf.FlaskForm):
class Meta: class Meta:
csrf = False csrf = False
target = fields.SelectField( u'Go to' ) target = fields.SelectField( _('Go to') )
email = fields.StringField(_('E-mail'), [validators.Email()]) email = fields.StringField(_('E-mail'), [validators.Email()])
pw = fields.PasswordField(_('Password'), [validators.DataRequired()]) pw = fields.PasswordField(_('Password'), [validators.DataRequired()])
submit = fields.SubmitField(_('Sign in')) submit = fields.SubmitField(_('Sign in'))

@ -3,11 +3,3 @@
{%- block title %} {%- block title %}
{% trans %}Sign in{% endtrans %} {% trans %}Sign in{% endtrans %}
{%- endblock %} {%- endblock %}
{%- block subtitle %}
{%- if endpoint == 'ui.index' %}
{% trans %}to access the configuration page{% endtrans %}
{%- elif endpoint == 'ui.webmail' %}
{% trans %}to access the webmail page{% endtrans %}
{%- endif %}
{%- endblock %}

@ -12,18 +12,18 @@ def login():
endpoint = flask.request.args.get('next', 'ui.index') endpoint = flask.request.args.get('next', 'ui.index')
if str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper != 'NONE' and endpoint != 'ui.webmail': if str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper != 'NONE' and endpoint != 'ui.webmail':
form.target.choices = [('Configuration page', 'Configuration page'), ('Webmail', 'Webmail')] form.target.choices = [('Admin', 'Admin'), ('Webmail', 'Webmail')]
elif str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper != 'NONE' and endpoint == 'ui.webmail': elif str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper != 'NONE' and endpoint == 'ui.webmail':
form.target.choices = [('Webmail', 'Webmail'), ('Configuration page', 'Configuration page')] form.target.choices = [('Webmail', 'Webmail'), ('Admin', 'Admin')]
elif str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper == 'NONE': elif str(app.config['WEBMAIL']).upper != 'NONE' and str(app.config['ADMIN']).upper == 'NONE':
form.target.choices = [('Webmail', 'Webmail')] form.target.choices = [('Webmail', 'Webmail')]
elif str(app.config['WEBMAIL']).upper == 'NONE' and str(app.config['ADMIN']).upper != 'NONE': elif str(app.config['WEBMAIL']).upper == 'NONE' and str(app.config['ADMIN']).upper != 'NONE':
form.target.choices = [('Configuration page', 'Configuration page')] form.target.choices = [('Admin', 'Admin')]
if form.validate_on_submit(): if form.validate_on_submit():
if form.target.data == 'Configuration page': if str(form.target.data) == 'Admin':
endpoint = 'ui.index' endpoint = 'ui.index'
elif form.target.data == 'webmail': elif str(form.target.data) == 'Webmail':
endpoint = 'ui.webmail' endpoint = 'ui.webmail'
user = models.User.login(form.email.data, form.pw.data) user = models.User.login(form.email.data, form.pw.data)
@ -33,5 +33,7 @@ def login():
return flask.redirect(flask.url_for(endpoint)) return flask.redirect(flask.url_for(endpoint))
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
flask.current_app.logger.warn(f'Login failed for {str(form.email.data)} from {client_ip}.')
return flask.render_template('login.html', form=form, endpoint=endpoint) return flask.render_template('login.html', form=form, endpoint=endpoint)

@ -136,21 +136,26 @@ http {
include /etc/nginx/proxy.conf; include /etc/nginx/proxy.conf;
return 302 {{ WEB_WEBMAIL }}; return 302 {{ WEB_WEBMAIL }};
} }
{% if ADMIN == 'true' %}
location ^~ /ui { location ^~ /ui {
include /etc/nginx/proxy.conf; include /etc/nginx/proxy.conf;
rewrite ^/ui/(.*) {{ WEB_ADMIN }}/ui/$1 redirect; rewrite ^/ui/(.*) {{ WEB_ADMIN }}/ui/$1 redirect;
#return 302 {{ WEB_ADMIN }}/ui/;
} }
{% endif %}
{% if ADMIN == 'true' or WEBMAIL != 'none' %}
location ^~ /sso { location ^~ /sso {
include /etc/nginx/proxy.conf; include /etc/nginx/proxy.conf;
proxy_pass http://$admin; proxy_pass http://$admin;
} }
# location ^~ /(ui|static) { location ^~ /ui/language {
# rewrite ^{{ WEB_ADMIN }}/(.*) /$1 break; include /etc/nginx/proxy.conf;
# include /etc/nginx/proxy.conf; proxy_set_header X-Forwarded-Prefix {{ WEB_ADMIN }};
# proxy_set_header X-Forwarded-Prefix {{ WEB_ADMIN }}; proxy_pass http://$admin;
# proxy_pass http://$admin; expires $expires;
# } }
{% endif %}
{% if WEB_WEBMAIL != '/' and WEBROOT_REDIRECT != 'none' %} {% if WEB_WEBMAIL != '/' and WEBROOT_REDIRECT != 'none' %}
location / { location / {

Loading…
Cancel
Save