2021-09-02 13:36:42 +02:00
|
|
|
from mailu import models
|
|
|
|
from mailu.sso import sso, forms
|
2021-09-02 17:08:50 +02:00
|
|
|
from mailu.ui import access
|
2021-09-02 13:36:42 +02:00
|
|
|
|
|
|
|
from flask import current_app as app
|
|
|
|
import flask
|
|
|
|
import flask_login
|
|
|
|
|
|
|
|
@sso.route('/login', methods=['GET', 'POST'])
|
|
|
|
def login():
|
|
|
|
form = forms.LoginForm()
|
2021-09-02 17:08:50 +02:00
|
|
|
endpoint = flask.request.args.get('next', 'ui.index')
|
2021-09-03 13:01:09 +02:00
|
|
|
|
|
|
|
if endpoint == 'ui.webmail':
|
|
|
|
endpoint = 'ui.webmail'
|
|
|
|
else:
|
|
|
|
endpoint = 'ui.index'
|
2021-09-02 13:36:42 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
user = models.User.login(form.email.data, form.pw.data)
|
|
|
|
if user:
|
|
|
|
flask.session.regenerate()
|
2021-09-03 13:01:09 +02:00
|
|
|
flask_login.login_user(user)
|
|
|
|
return flask.redirect(flask.url_for(endpoint))
|
2021-09-02 13:36:42 +02:00
|
|
|
else:
|
|
|
|
flask.flash('Wrong e-mail or password', 'error')
|
2021-09-02 17:08:50 +02:00
|
|
|
return flask.render_template('login.html', form=form, endpoint=endpoint)
|
|
|
|
|