1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-16 10:59:53 +02:00
Mailu/admin/freeposte/admin/views/base.py

45 lines
1.4 KiB
Python
Raw Normal View History

2016-04-24 19:17:40 +02:00
from freeposte import dockercli
from freeposte.admin import app, db, models, forms, access
2016-03-19 21:37:48 +02:00
import flask
2016-08-13 20:51:54 +02:00
import flask_login
2016-03-19 21:37:48 +02:00
@app.route('/', methods=["GET"])
@access.authenticated
2016-03-19 21:37:48 +02:00
def index():
return flask.redirect(flask.url_for('.user_settings'))
2016-03-19 21:37:48 +02:00
@app.route('/login', methods=['GET', 'POST'])
def login():
form = forms.LoginForm()
if form.validate_on_submit():
user = models.User.login(form.email.data, form.pw.data)
if user:
flask_login.login_user(user)
return flask.redirect(flask.url_for('.index'))
2016-03-19 21:37:48 +02:00
else:
flask.flash('Wrong e-mail or password', 'error')
2016-03-19 21:37:48 +02:00
return flask.render_template('login.html', form=form)
@app.route('/logout', methods=['GET'])
@access.authenticated
2016-03-19 21:37:48 +02:00
def logout():
flask_login.logout_user()
return flask.redirect(flask.url_for('.index'))
2016-04-24 19:17:40 +02:00
@app.route('/services', methods=['GET'])
@access.global_admin
2016-04-24 19:17:40 +02:00
def services():
containers = {}
for brief in dockercli.containers(all=True):
if brief['Image'].startswith('freeposte/'):
container = dockercli.inspect_container(brief['Id'])
container['Image'] = dockercli.inspect_image(container['Image'])
name = container['Config']['Labels']['com.docker.compose.service']
containers[name] = container
return flask.render_template('services.html', containers=containers)