2018-10-18 15:57:43 +02:00
|
|
|
from mailu import models
|
2017-09-24 12:00:39 +02:00
|
|
|
from mailu.ui import ui, forms, access
|
2016-03-19 21:37:48 +02:00
|
|
|
|
2021-02-07 19:08:58 +02:00
|
|
|
from flask import current_app as app
|
2016-03-19 21:37:48 +02:00
|
|
|
import flask
|
2016-08-13 20:51:54 +02:00
|
|
|
import flask_login
|
2016-11-10 11:48:37 +02:00
|
|
|
|
2016-03-19 21:37:48 +02:00
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/', methods=["GET"])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.authenticated
|
2016-03-19 21:37:48 +02:00
|
|
|
def index():
|
2016-03-20 16:36:56 +02:00
|
|
|
return flask.redirect(flask.url_for('.user_settings'))
|
2016-03-19 21:37:48 +02:00
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/login', methods=['GET', 'POST'])
|
2016-03-19 21:37:48 +02:00
|
|
|
def login():
|
|
|
|
form = forms.LoginForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
user = models.User.login(form.email.data, form.pw.data)
|
|
|
|
if user:
|
2021-02-22 21:43:52 +02:00
|
|
|
flask.session.regenerate()
|
2016-03-19 21:37:48 +02:00
|
|
|
flask_login.login_user(user)
|
2017-12-03 18:53:12 +02:00
|
|
|
endpoint = flask.request.args.get('next', '.index')
|
2017-09-17 18:55:54 +02:00
|
|
|
return flask.redirect(flask.url_for(endpoint)
|
|
|
|
or flask.url_for('.index'))
|
2016-03-19 21:37:48 +02:00
|
|
|
else:
|
2016-05-01 20:04:40 +02:00
|
|
|
flask.flash('Wrong e-mail or password', 'error')
|
2016-03-19 21:37:48 +02:00
|
|
|
return flask.render_template('login.html', form=form)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/logout', methods=['GET'])
|
2016-08-29 19:24:39 +02:00
|
|
|
@access.authenticated
|
2016-03-19 21:37:48 +02:00
|
|
|
def logout():
|
|
|
|
flask_login.logout_user()
|
2021-02-22 21:43:52 +02:00
|
|
|
flask.session.destroy()
|
2016-03-20 16:36:56 +02:00
|
|
|
return flask.redirect(flask.url_for('.index'))
|
2016-04-24 19:17:40 +02:00
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/announcement', methods=['GET', 'POST'])
|
2016-11-10 11:48:37 +02:00
|
|
|
@access.global_admin
|
|
|
|
def announcement():
|
|
|
|
form = forms.AnnouncementForm()
|
|
|
|
if form.validate_on_submit():
|
2017-11-10 12:56:43 +02:00
|
|
|
for user in models.User.query.all():
|
|
|
|
user.sendmail(form.announcement_subject.data,
|
|
|
|
form.announcement_body.data)
|
2016-11-10 11:48:37 +02:00
|
|
|
# Force-empty the form
|
|
|
|
form.announcement_subject.data = ''
|
|
|
|
form.announcement_body.data = ''
|
|
|
|
flask.flash('Your announcement was sent', 'success')
|
2017-11-10 12:56:43 +02:00
|
|
|
return flask.render_template('announcement.html', form=form)
|
2018-04-11 21:45:17 +02:00
|
|
|
|
2021-02-06 18:23:05 +02:00
|
|
|
@ui.route('/webmail', methods=['GET'])
|
|
|
|
def webmail():
|
|
|
|
return flask.redirect(app.config['WEB_WEBMAIL'])
|
2018-04-11 21:45:17 +02:00
|
|
|
|
|
|
|
@ui.route('/client', methods=['GET'])
|
|
|
|
def client():
|
|
|
|
return flask.render_template('client.html')
|
2021-09-02 22:49:36 +02:00
|
|
|
|
|
|
|
@ui.route('/antispam', methods=['GET'])
|
|
|
|
def antispam():
|
|
|
|
return flask.render_template('antispam.html')
|
|
|
|
|