Merge master. Make sso login working for admin.

master
Diman0 3 years ago
parent 1cfc9ee1c4
commit 8868aec0dc

@ -51,6 +51,7 @@ DEFAULT_CONFIG = {
# Web settings
'SITENAME': 'Mailu',
'WEBSITE': 'https://mailu.io',
'ADMIN' : 'none',
'WEB_ADMIN': '/admin',
'WEB_WEBMAIL': '/webmail',
'WEBMAIL': 'none',

@ -6,6 +6,8 @@ import flask_login
import flask_wtf
import re
LOCALPART_REGEX = "^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*$"
class LoginForm(flask_wtf.FlaskForm):
class Meta:
csrf = False

@ -6,46 +6,53 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('.static', filename='vendor.css') }}">
<link rel="stylesheet" href="{{ url_for('.static', filename='app.css') }}">
<title>Mailu-login - {{ config["SITENAME"] }}</title>
<title>Mailu - {{ config["SITENAME"] }}</title>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">
<header class="main-header">
<div class="logo">
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
<span class="sr-only">Toggle navigation</span>
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
</li>
</ul>
</nav>
<aside class="main-sidebar sidebar-dark-primary">
<a class="brand-link">
<span class="brand-text font-weight-light">{{ config["SITENAME"] }}</span>
</a>
<a>
<span class="logo-lg"></span>
</a>
</div>
</header>
{% block sidebar %}
{% include "sidebar_sso.html" %}
{% endblock %}
</aside>
<div class="content-wrapper">
<section class="content-header">
<div class="pull-right">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0">{% block title %}{% endblock %}</h1>
<small>{% block subtitle %}{% endblock %}</small>
</div>
<div class="col-sm-6">
{% block main_action %}
{% endblock %}
</div>
<h1>
{% block title %}{% endblock %}
<small>{% block subtitle %}{% endblock %}</small>
</h1>
</div>
</div>
</section>
<section class="content">
<div class="content">
{{ utils.flashed_messages(container=False) }}
{% block content %}{% endblock %}
</section>
</div>
</div>
<footer class="main-footer">
Built with <i class="fa fa-heart"></i> using <a class="white-text" href="http://flask.pocoo.org/">Flask</a> and
<a class="white-text" href="https://almsaeedstudio.com/preview">AdminLTE</a>
<span class="pull-right"><i class="fa fa-code-fork"></i> on <a class="white-text" href="https://github.com/Mailu/Mailu">Github</a></a></span>
<a class="white-text" href="https://adminlte.io/themes/v3/index3.html">AdminLTE</a>
<span class="pull-right"><i class="fa fa-code-fork"></i>on <a class="white-text" href="https://github.com/Mailu/Mailu">Github</a></a></span>
</footer>
</div>
<script src="{{ url_for('static', filename='vendor.js') }}"></script>
<script src="{{ url_for('static', filename='app.js') }}"></script>
<script src="{{ url_for('.static', filename='vendor.js') }}"></script>
<script src="{{ url_for('.static', filename='app.js') }}"></script>
</body>
</html>

@ -1,7 +1,7 @@
{% extends "base_sso.html" %}
{% block content %}
{% call macros.box() %}
{% call macros.card() %}
{{ macros.form(form) }}
{% endcall %}
{% endblock %}

@ -5,5 +5,9 @@
{% endblock %}
{% block subtitle %}
{% trans %}to access IF statement for switch text for loggin in what the administration tools{% endtrans %}
{% if endpoint == 'ui.index' %}
{% trans %}to access the configuration page{% endtrans %}
{% elif endpoint == 'ui.webmail' %}
{% trans %}to access the webmail page{% endtrans %}
{% endif %}
{% endblock %}

@ -0,0 +1,60 @@
<div class="sidebar">
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" role="menu">
{% if config['ADMIN'] %}
<li class="nav-item">
<a href="{{ url_for('ui.client') }}" class="nav-link">
<i class="nav-icon fa fa-laptop"></i>
<p class="text">{% trans %}Client setup{% endtrans %}</p>
</a>
</li>
<li class="nav-item">
<a href="https://mailu.io" target="_blank" class="nav-link">
<i class="nav-icon fa fa-life-ring"></i>
<p class="text">{% trans %}Help{% endtrans %}</p>
</a>
</li>
{% endif %}
{% if False %}
<!-- Domain self-registration is only available when
- Admin is available
- Domain Self-registration is enabled
- The current user is not logged on
-->
{% endif %}
{% if config['DOMAIN_REGISTRATION'] %}
{% if not current_user.is_authenticated %}
{% if config['ADMIN'] %}
<li class="nav-item">
<a href="{{ url_for('ui.domain_signup') }}" class="nav-link">
<i class="nav-icon fa fa-plus-square"></i>
<p class="text">{% trans %}Register a domain{% endtrans %}</p>
</a>
</li>
{% endif %}
{% endif %}
{% endif %}
{% if False %}
<!-- User self-registration is only available when
- Admin is available
- Self-registration is enabled
- The current user is not logged on
-->
{% endif %}
{% if not current_user.is_authenticated %}
{% if signup_domains %}
{% if config['ADMIN'] %}
<li class="nav-item">
<a href="{{ url_for('ui.user_signup') }}" class="nav-link">
<i class="nav-icon fa fa-user-plus"></i>
<p class="text">{% trans %}Sign up{% endtrans %}</p>
</a>
</li>
{% endif %}
{% endif %}
{% endif %}
</ul>
</nav>
</div>

@ -1,5 +1,6 @@
from mailu import models
from mailu.sso import sso, forms
from mailu.ui import access
from flask import current_app as app
import flask
@ -8,23 +9,15 @@ import flask_login
@sso.route('/login', methods=['GET', 'POST'])
def login():
form = forms.LoginForm()
endpoint = flask.request.args.get('next', 'ui.index')
if form.validate_on_submit():
user = models.User.login(form.email.data, form.pw.data)
if user:
flask.session.regenerate()
flask_login.login_user(user)
endpoint = flask.request.args.get('next', 'ui.index')
return flask.redirect(flask.url_for(endpoint)
or flask.url_for('ui.index'))
else:
flask.flash('Wrong e-mail or password', 'error')
return flask.render_template('login.html', form=form)
return flask.render_template('login.html', form=form, endpoint=endpoint)
"""
@ui.route('/logout', methods=['GET'])
@access.authenticated
def logout():
flask_login.logout_user()
flask.session.destroy()
return flask.redirect(flask.url_for('.index'))
"""

@ -125,7 +125,7 @@
</li>
{% else %}
<li class="nav-item">
<a href="{{ url_for('.login') }}" class="nav-link">
<a href="{{ url_for('sso.login') }}" class="nav-link">
<i class="nav-icon fas fa-sign-in-alt"></i>
<p class="text">{% trans %}Sign in{% endtrans %}</p>
</a>

@ -117,6 +117,12 @@ http {
include /overrides/*.conf;
# Actual logic
location /sso {
include /etc/nginx/proxy.conf;
proxy_set_header Host $host;
proxy_pass http://$admin/sso;
}
{% if WEB_WEBMAIL != '/' and WEBROOT_REDIRECT != 'none' %}
location / {
{% if WEBROOT_REDIRECT %}
@ -158,7 +164,7 @@ http {
}
location @webmail_login {
return 302 {{ WEB_ADMIN }}/ui/login?next=ui.webmail;
return 302 {{ WEB_ADMIN }}/sso/login?next=ui.webmail;
}
{% else %}
}

Loading…
Cancel
Save