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 # Web settings
'SITENAME': 'Mailu', 'SITENAME': 'Mailu',
'WEBSITE': 'https://mailu.io', 'WEBSITE': 'https://mailu.io',
'ADMIN' : 'none',
'WEB_ADMIN': '/admin', 'WEB_ADMIN': '/admin',
'WEB_WEBMAIL': '/webmail', 'WEB_WEBMAIL': '/webmail',
'WEBMAIL': 'none', 'WEBMAIL': 'none',

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

@ -6,46 +6,53 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <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='vendor.css') }}">
<link rel="stylesheet" href="{{ url_for('.static', filename='app.css') }}"> <link rel="stylesheet" href="{{ url_for('.static', filename='app.css') }}">
<title>Mailu-login - {{ config["SITENAME"] }}</title> <title>Mailu - {{ config["SITENAME"] }}</title>
</head> </head>
<body class="hold-transition skin-blue sidebar-mini"> <body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper"> <div class="wrapper">
<header class="main-header"> <nav class="main-header navbar navbar-expand navbar-white navbar-light">
<div class="logo"> <ul class="navbar-nav">
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button"> <li class="nav-item">
<span class="sr-only">Toggle navigation</span> <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
</a> </li>
</ul>
<a> </nav>
<span class="logo-lg"></span> <aside class="main-sidebar sidebar-dark-primary">
</a> <a class="brand-link">
</div> <span class="brand-text font-weight-light">{{ config["SITENAME"] }}</span>
</header> </a>
{% block sidebar %}
{% include "sidebar_sso.html" %}
{% endblock %}
</aside>
<div class="content-wrapper"> <div class="content-wrapper">
<section class="content-header"> <section class="content-header">
<div class="pull-right"> <div class="container-fluid">
{% block main_action %} <div class="row mb-2">
{% endblock %} <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>
</div>
</div> </div>
<h1>
{% block title %}{% endblock %}
<small>{% block subtitle %}{% endblock %}</small>
</h1>
</section> </section>
<section class="content"> <div class="content">
{{ utils.flashed_messages(container=False) }} {{ utils.flashed_messages(container=False) }}
{% block content %}{% endblock %} {% block content %}{% endblock %}
</section> </div>
</div> </div>
<footer class="main-footer"> <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 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> <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> <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> </footer>
</div> </div>
<script src="{{ url_for('static', filename='vendor.js') }}"></script> <script src="{{ url_for('.static', filename='vendor.js') }}"></script>
<script src="{{ url_for('static', filename='app.js') }}"></script> <script src="{{ url_for('.static', filename='app.js') }}"></script>
</body> </body>
</html> </html>

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

@ -5,5 +5,9 @@
{% endblock %} {% endblock %}
{% block subtitle %} {% 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 %} {% 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 import models
from mailu.sso import sso, forms from mailu.sso import sso, forms
from mailu.ui import access
from flask import current_app as app from flask import current_app as app
import flask import flask
@ -8,23 +9,15 @@ 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')
if form.validate_on_submit(): if form.validate_on_submit():
user = models.User.login(form.email.data, form.pw.data) user = models.User.login(form.email.data, form.pw.data)
if user: if user:
flask.session.regenerate() flask.session.regenerate()
flask_login.login_user(user) flask_login.login_user(user)
endpoint = flask.request.args.get('next', 'ui.index')
return flask.redirect(flask.url_for(endpoint) return flask.redirect(flask.url_for(endpoint)
or flask.url_for('ui.index')) or flask.url_for('ui.index'))
else: else:
flask.flash('Wrong e-mail or password', 'error') 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> </li>
{% else %} {% else %}
<li class="nav-item"> <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> <i class="nav-icon fas fa-sign-in-alt"></i>
<p class="text">{% trans %}Sign in{% endtrans %}</p> <p class="text">{% trans %}Sign in{% endtrans %}</p>
</a> </a>

@ -117,6 +117,12 @@ http {
include /overrides/*.conf; include /overrides/*.conf;
# Actual logic # 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' %} {% if WEB_WEBMAIL != '/' and WEBROOT_REDIRECT != 'none' %}
location / { location / {
{% if WEBROOT_REDIRECT %} {% if WEBROOT_REDIRECT %}
@ -158,7 +164,7 @@ http {
} }
location @webmail_login { location @webmail_login {
return 302 {{ WEB_ADMIN }}/ui/login?next=ui.webmail; return 302 {{ WEB_ADMIN }}/sso/login?next=ui.webmail;
} }
{% else %} {% else %}
} }

Loading…
Cancel
Save