|
|
@ -10,22 +10,20 @@ import flask_login
|
|
|
|
@sso.route('/login', methods=['GET', 'POST'])
|
|
|
|
@sso.route('/login', methods=['GET', 'POST'])
|
|
|
|
def login():
|
|
|
|
def login():
|
|
|
|
form = forms.LoginForm()
|
|
|
|
form = forms.LoginForm()
|
|
|
|
endpoint = flask.request.args.get('next', 'ui.index')
|
|
|
|
form.submitAdmin.label.text = form.submitAdmin.label.text + ' Admin'
|
|
|
|
|
|
|
|
form.submitWebmail.label.text = form.submitWebmail.label.text + ' Webmail'
|
|
|
|
form.target.choices = []
|
|
|
|
|
|
|
|
|
|
|
|
fields = []
|
|
|
|
if str(app.config["ADMIN"]).upper() != "FALSE":
|
|
|
|
if str(app.config["ADMIN"]).upper() != "FALSE":
|
|
|
|
form.target.choices += [("Admin", "Admin")]
|
|
|
|
fields.append(form.submitAdmin)
|
|
|
|
if str(app.config["WEBMAIL"]).upper() != "NONE":
|
|
|
|
if str(app.config["WEBMAIL"]).upper() != "NONE":
|
|
|
|
form.target.choices += [("Webmail", "Webmail")]
|
|
|
|
fields.append(form.submitWebmail)
|
|
|
|
if endpoint == "ui.webmail":
|
|
|
|
fields = tuple(fields)
|
|
|
|
form.target.choices.reverse()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
if form.validate_on_submit():
|
|
|
|
if str(form.target.data) == 'Admin':
|
|
|
|
if form.submitAdmin.data:
|
|
|
|
endpoint = 'ui.user_settings'
|
|
|
|
|
|
|
|
destination = app.config['WEB_ADMIN']
|
|
|
|
destination = app.config['WEB_ADMIN']
|
|
|
|
elif str(form.target.data) == 'Webmail':
|
|
|
|
elif form.submitWebmail.data:
|
|
|
|
endpoint = 'ui.webmail'
|
|
|
|
|
|
|
|
destination = app.config['WEB_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)
|
|
|
@ -37,7 +35,7 @@ def login():
|
|
|
|
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
|
|
|
|
flask.current_app.logger.warn(f'Login failed for {str(form.email.data)} from {client_ip}.')
|
|
|
|
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, fields=fields)
|
|
|
|
|
|
|
|
|
|
|
|
@sso.route('/logout', methods=['GET'])
|
|
|
|
@sso.route('/logout', methods=['GET'])
|
|
|
|
@access.authenticated
|
|
|
|
@access.authenticated
|
|
|
|