Initial implementation for standalone sso page

master
Diman0 3 years ago
parent 7e86f5cb57
commit 9fac3d7ad3

@ -31,6 +31,7 @@ RUN apk add --no-cache openssl curl postgresql-libs mariadb-connector-c \
&& apk del --no-cache build-dep
COPY --from=assets static ./mailu/ui/static
COPY --from=assets static ./mailu/sso/static
COPY mailu ./mailu
COPY migrations ./migrations
COPY start.py /start.py

@ -48,10 +48,10 @@ def create_app_from_config(config):
)
# Import views
from mailu import ui, internal
from mailu import ui, internal, sso
app.register_blueprint(ui.ui, url_prefix='/ui')
app.register_blueprint(internal.internal, url_prefix='/internal')
app.register_blueprint(sso.sso, url_prefix='/sso')
return app

@ -0,0 +1,6 @@
from flask import Blueprint
sso = Blueprint('sso', __name__, static_folder='static', template_folder='templates')
from mailu.sso.views import *

@ -0,0 +1,14 @@
from wtforms import validators, fields, widgets
from wtforms_components import fields as fields_
from flask_babel import lazy_gettext as _
import flask_login
import flask_wtf
import re
class LoginForm(flask_wtf.FlaskForm):
class Meta:
csrf = False
email = fields.StringField(_('E-mail'), [validators.Email()])
pw = fields.PasswordField(_('Password'), [validators.DataRequired()])
submit = fields.SubmitField(_('Sign in'))

@ -0,0 +1,51 @@
{% import "macros.html" as macros %}
{% import "bootstrap/utils.html" as utils %}
<!doctype html>
<html>
<head>
<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>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<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>
</a>
<a>
<span class="logo-lg"></span>
</a>
</div>
</header>
<div class="content-wrapper">
<section class="content-header">
<div class="pull-right">
{% block main_action %}
{% endblock %}
</div>
<h1>
{% block title %}{% endblock %}
<small>{% block subtitle %}{% endblock %}</small>
</h1>
</section>
<section class="content">
{{ utils.flashed_messages(container=False) }}
{% block content %}{% endblock %}
</section>
</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>
</footer>
</div>
<script src="{{ url_for('static', filename='vendor.js') }}"></script>
<script src="{{ url_for('static', filename='app.js') }}"></script>
</body>
</html>

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

@ -0,0 +1,9 @@
{% extends "form_sso.html" %}
{% block title %}
{% trans %}Sign in{% endtrans %}
{% endblock %}
{% block subtitle %}
{% trans %}to access IF statement for switch text for loggin in what the administration tools{% endtrans %}
{% endblock %}

@ -0,0 +1,3 @@
__all__ = [
'base', 'hello'
]

@ -0,0 +1,30 @@
from mailu import models
from mailu.sso import sso, forms
from flask import current_app as app
import flask
import flask_login
@sso.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.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)
"""
@ui.route('/logout', methods=['GET'])
@access.authenticated
def logout():
flask_login.logout_user()
flask.session.destroy()
return flask.redirect(flask.url_for('.index'))
"""

@ -0,0 +1,6 @@
from mailu.sso import sso
from flask import current_app as app
@sso.route("/")
def hello_world():
return "<p>Hello, World!</p>"

@ -44,14 +44,14 @@ class MultipleEmailAddressesVerify(object):
class ConfirmationForm(flask_wtf.FlaskForm):
submit = fields.SubmitField(_('Confirm'))
"""
class LoginForm(flask_wtf.FlaskForm):
class Meta:
csrf = False
email = fields.StringField(_('E-mail'), [validators.Email()])
pw = fields.PasswordField(_('Password'), [validators.DataRequired()])
submit = fields.SubmitField(_('Sign in'))
"""
class DomainForm(flask_wtf.FlaskForm):
name = fields.StringField(_('Domain name'), [validators.DataRequired()])

@ -1,9 +0,0 @@
{% extends "form.html" %}
{% block title %}
{% trans %}Sign in{% endtrans %}
{% endblock %}
{% block subtitle %}
{% trans %}to access the administration tools{% endtrans %}
{% endblock %}

@ -12,6 +12,7 @@ def index():
return flask.redirect(flask.url_for('.user_settings'))
"""
@ui.route('/login', methods=['GET', 'POST'])
def login():
form = forms.LoginForm()
@ -26,7 +27,7 @@ def login():
else:
flask.flash('Wrong e-mail or password', 'error')
return flask.render_template('login.html', form=form)
"""
@ui.route('/logout', methods=['GET'])
@access.authenticated

@ -28,13 +28,13 @@ from werkzeug.contrib import fixers
# Login configuration
login = flask_login.LoginManager()
login.login_view = "ui.login"
login.login_view = "sso.login"
@login.unauthorized_handler
def handle_needs_login():
""" redirect unauthorized requests to login page """
return flask.redirect(
flask.url_for('ui.login', next=flask.request.endpoint)
flask.url_for('sso.login', next=flask.request.endpoint)
)
# Rate limiter

Loading…
Cancel
Save