From 40d4a22240875ffebdcc0c8d9f23b526d24b74d4 Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Sun, 20 Mar 2016 15:36:56 +0100 Subject: [PATCH] Switched to blueprints for the main app --- admin/freeposte/__init__.py | 22 ++------ admin/freeposte/admin/__init__.py | 28 ++++++++++ admin/freeposte/{ => admin}/forms.py | 0 admin/freeposte/{ => admin}/models.py | 13 +++-- .../static/adminlte/css/AdminLTE.min.css | 0 .../static/adminlte/css/skin-blue.min.css | 0 .../{ => admin}/static/adminlte/js/app.min.js | 0 .../static/bootstrap/css/bootstrap.css.map | 0 .../static/bootstrap/css/bootstrap.min.css | 0 .../fonts/glyphicons-halflings-regular.eot | Bin .../fonts/glyphicons-halflings-regular.svg | 0 .../fonts/glyphicons-halflings-regular.ttf | Bin .../fonts/glyphicons-halflings-regular.woff | Bin .../fonts/glyphicons-halflings-regular.woff2 | Bin .../static/bootstrap/js/bootstrap.min.js | 0 .../static/jquery/js/jquery-2.2.2.min.js | 0 .../{ => admin}/templates/admin/admins.html | 0 .../{ => admin}/templates/admin/status.html | 0 .../{ => admin}/templates/alias/create.html | 0 .../{ => admin}/templates/alias/edit.html | 0 .../{ => admin}/templates/alias/list.html | 6 +- .../freeposte/{ => admin}/templates/base.html | 6 +- .../{ => admin}/templates/domain/admins.html | 0 .../{ => admin}/templates/domain/create.html | 0 .../{ => admin}/templates/domain/edit.html | 0 .../{ => admin}/templates/domain/list.html | 12 ++-- .../freeposte/{ => admin}/templates/form.html | 0 .../{ => admin}/templates/helpers.html | 0 .../{ => admin}/templates/index.html | 0 .../{ => admin}/templates/login.html | 0 .../{ => admin}/templates/sidebar.html | 20 +++---- .../{ => admin}/templates/user/create.html | 0 .../{ => admin}/templates/user/edit.html | 0 .../{ => admin}/templates/user/fetchmail.html | 0 .../{ => admin}/templates/user/forward.html | 0 .../freeposte/admin/templates/user/list.html | 52 ++++++++++++++++++ .../{ => admin}/templates/user/password.html | 0 .../{ => admin}/templates/user/reply.html | 0 .../{ => admin}/templates/user/settings.html | 0 .../{ => admin}/templates/working.html | 0 admin/freeposte/{ => admin}/utils.py | 2 +- .../views/administrators.py} | 2 +- admin/freeposte/{ => admin}/views/aliases.py | 12 ++-- admin/freeposte/{ => admin}/views/base.py | 8 +-- admin/freeposte/{ => admin}/views/domains.py | 8 +-- admin/freeposte/{ => admin}/views/users.py | 24 ++++---- admin/freeposte/templates/user/list.html | 52 ------------------ admin/freeposte/views/__init__.py | 1 - 48 files changed, 146 insertions(+), 122 deletions(-) create mode 100644 admin/freeposte/admin/__init__.py rename admin/freeposte/{ => admin}/forms.py (100%) rename admin/freeposte/{ => admin}/models.py (90%) rename admin/freeposte/{ => admin}/static/adminlte/css/AdminLTE.min.css (100%) rename admin/freeposte/{ => admin}/static/adminlte/css/skin-blue.min.css (100%) rename admin/freeposte/{ => admin}/static/adminlte/js/app.min.js (100%) rename admin/freeposte/{ => admin}/static/bootstrap/css/bootstrap.css.map (100%) rename admin/freeposte/{ => admin}/static/bootstrap/css/bootstrap.min.css (100%) rename admin/freeposte/{ => admin}/static/bootstrap/fonts/glyphicons-halflings-regular.eot (100%) rename admin/freeposte/{ => admin}/static/bootstrap/fonts/glyphicons-halflings-regular.svg (100%) rename admin/freeposte/{ => admin}/static/bootstrap/fonts/glyphicons-halflings-regular.ttf (100%) rename admin/freeposte/{ => admin}/static/bootstrap/fonts/glyphicons-halflings-regular.woff (100%) rename admin/freeposte/{ => admin}/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 (100%) rename admin/freeposte/{ => admin}/static/bootstrap/js/bootstrap.min.js (100%) rename admin/freeposte/{ => admin}/static/jquery/js/jquery-2.2.2.min.js (100%) rename admin/freeposte/{ => admin}/templates/admin/admins.html (100%) rename admin/freeposte/{ => admin}/templates/admin/status.html (100%) rename admin/freeposte/{ => admin}/templates/alias/create.html (100%) rename admin/freeposte/{ => admin}/templates/alias/edit.html (100%) rename admin/freeposte/{ => admin}/templates/alias/list.html (67%) rename admin/freeposte/{ => admin}/templates/base.html (88%) rename admin/freeposte/{ => admin}/templates/domain/admins.html (100%) rename admin/freeposte/{ => admin}/templates/domain/create.html (100%) rename admin/freeposte/{ => admin}/templates/domain/edit.html (100%) rename admin/freeposte/{ => admin}/templates/domain/list.html (55%) rename admin/freeposte/{ => admin}/templates/form.html (100%) rename admin/freeposte/{ => admin}/templates/helpers.html (100%) rename admin/freeposte/{ => admin}/templates/index.html (100%) rename admin/freeposte/{ => admin}/templates/login.html (100%) rename admin/freeposte/{ => admin}/templates/sidebar.html (72%) rename admin/freeposte/{ => admin}/templates/user/create.html (100%) rename admin/freeposte/{ => admin}/templates/user/edit.html (100%) rename admin/freeposte/{ => admin}/templates/user/fetchmail.html (100%) rename admin/freeposte/{ => admin}/templates/user/forward.html (100%) create mode 100644 admin/freeposte/admin/templates/user/list.html rename admin/freeposte/{ => admin}/templates/user/password.html (100%) rename admin/freeposte/{ => admin}/templates/user/reply.html (100%) rename admin/freeposte/{ => admin}/templates/user/settings.html (100%) rename admin/freeposte/{ => admin}/templates/working.html (100%) rename admin/freeposte/{ => admin}/utils.py (96%) rename admin/freeposte/{views/admin.py => admin/views/administrators.py} (86%) rename admin/freeposte/{ => admin}/views/aliases.py (84%) rename admin/freeposte/{ => admin}/views/base.py (74%) rename admin/freeposte/{ => admin}/views/domains.py (89%) rename admin/freeposte/{ => admin}/views/users.py (86%) delete mode 100644 admin/freeposte/templates/user/list.html delete mode 100644 admin/freeposte/views/__init__.py diff --git a/admin/freeposte/__init__.py b/admin/freeposte/__init__.py index 6f2cb066..96e6d564 100644 --- a/admin/freeposte/__init__.py +++ b/admin/freeposte/__init__.py @@ -10,7 +10,7 @@ import os app = Flask(__name__) default_config = { - 'SQLALCHEMY_DATABASE_URI': 'sqlite:////tmp/freeposte.db', + 'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/freeposte.db', 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SECRET_KEY': "changeMe", 'DEBUG': False @@ -20,24 +20,12 @@ default_config = { for key, value in default_config.items(): app.config[key] = os.environ.get(key, value) -# Setup Bootstrap +# Setup components Bootstrap(app) - -# Create the database db = SQLAlchemy(app) - -# Import models once the database is ready -from freeposte import models - -# Setup Flask-login login_manager = flask_login.LoginManager() login_manager.init_app(app) -login_manager.login_view = "login" -login_manager.user_loader(models.User.get_by_email) -@app.context_processor -def inject_user(): - return dict(current_user=flask_login.current_user) - -# Finally import view -from freeposte import views +# Finally setup the blueprint +from freeposte import admin +app.register_blueprint(admin.app, url_prefix='/admin') diff --git a/admin/freeposte/admin/__init__.py b/admin/freeposte/admin/__init__.py new file mode 100644 index 00000000..92aa50a2 --- /dev/null +++ b/admin/freeposte/admin/__init__.py @@ -0,0 +1,28 @@ +from flask import Blueprint +from flask.ext import login as flask_login +from freeposte import login_manager, db + + +app = Blueprint( + 'admin', __name__, + template_folder='templates', + static_folder='static') + +# Import models +from freeposte.admin import models + +# Register the login components +login_manager.login_view = "admin.login" +login_manager.user_loader(models.User.get_by_email) + +@app.context_processor +def inject_user(): + return dict(current_user=flask_login.current_user) + +# Import views +from freeposte.admin.views import \ + administrators, \ + base, \ + aliases, \ + users, \ + domains diff --git a/admin/freeposte/forms.py b/admin/freeposte/admin/forms.py similarity index 100% rename from admin/freeposte/forms.py rename to admin/freeposte/admin/forms.py diff --git a/admin/freeposte/models.py b/admin/freeposte/admin/models.py similarity index 90% rename from admin/freeposte/models.py rename to admin/freeposte/admin/models.py index 4e92a2ba..d1464eab 100644 --- a/admin/freeposte/models.py +++ b/admin/freeposte/admin/models.py @@ -1,9 +1,11 @@ -from freeposte import db +from freeposte.admin import db from sqlalchemy.ext import declarative from passlib import context from datetime import datetime +import re + # Many-to-many association table for domain administrators admins = db.Table('admin', @@ -89,13 +91,16 @@ class User(Address): is_active = True is_anonymous = False - pw_context = context.CryptContext(["sha512_crypt", "sha256_crypt"]) + pw_context = context.CryptContext( + ["sha512_crypt", "sha256_crypt", "md5_crypt"] + ) def check_password(self, password): - return User.pw_context.verify(password, self.password) + reference = re.match('({[^}]+})?(.*)', self.password).group(2) + return User.pw_context.verify(password, reference) def set_password(self, password): - self.password = User.pw_context.encrypt(password) + self.password = '{SHA512-CRYPT}' + User.pw_context.encrypt(password) def get_managed_domains(self): if self.global_admin: diff --git a/admin/freeposte/static/adminlte/css/AdminLTE.min.css b/admin/freeposte/admin/static/adminlte/css/AdminLTE.min.css similarity index 100% rename from admin/freeposte/static/adminlte/css/AdminLTE.min.css rename to admin/freeposte/admin/static/adminlte/css/AdminLTE.min.css diff --git a/admin/freeposte/static/adminlte/css/skin-blue.min.css b/admin/freeposte/admin/static/adminlte/css/skin-blue.min.css similarity index 100% rename from admin/freeposte/static/adminlte/css/skin-blue.min.css rename to admin/freeposte/admin/static/adminlte/css/skin-blue.min.css diff --git a/admin/freeposte/static/adminlte/js/app.min.js b/admin/freeposte/admin/static/adminlte/js/app.min.js similarity index 100% rename from admin/freeposte/static/adminlte/js/app.min.js rename to admin/freeposte/admin/static/adminlte/js/app.min.js diff --git a/admin/freeposte/static/bootstrap/css/bootstrap.css.map b/admin/freeposte/admin/static/bootstrap/css/bootstrap.css.map similarity index 100% rename from admin/freeposte/static/bootstrap/css/bootstrap.css.map rename to admin/freeposte/admin/static/bootstrap/css/bootstrap.css.map diff --git a/admin/freeposte/static/bootstrap/css/bootstrap.min.css b/admin/freeposte/admin/static/bootstrap/css/bootstrap.min.css similarity index 100% rename from admin/freeposte/static/bootstrap/css/bootstrap.min.css rename to admin/freeposte/admin/static/bootstrap/css/bootstrap.min.css diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.eot b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.eot rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.eot diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.svg b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.svg rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.svg diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.ttf b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.ttf rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.ttf diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.woff b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.woff rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.woff diff --git a/admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 b/admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from admin/freeposte/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 rename to admin/freeposte/admin/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 diff --git a/admin/freeposte/static/bootstrap/js/bootstrap.min.js b/admin/freeposte/admin/static/bootstrap/js/bootstrap.min.js similarity index 100% rename from admin/freeposte/static/bootstrap/js/bootstrap.min.js rename to admin/freeposte/admin/static/bootstrap/js/bootstrap.min.js diff --git a/admin/freeposte/static/jquery/js/jquery-2.2.2.min.js b/admin/freeposte/admin/static/jquery/js/jquery-2.2.2.min.js similarity index 100% rename from admin/freeposte/static/jquery/js/jquery-2.2.2.min.js rename to admin/freeposte/admin/static/jquery/js/jquery-2.2.2.min.js diff --git a/admin/freeposte/templates/admin/admins.html b/admin/freeposte/admin/templates/admin/admins.html similarity index 100% rename from admin/freeposte/templates/admin/admins.html rename to admin/freeposte/admin/templates/admin/admins.html diff --git a/admin/freeposte/templates/admin/status.html b/admin/freeposte/admin/templates/admin/status.html similarity index 100% rename from admin/freeposte/templates/admin/status.html rename to admin/freeposte/admin/templates/admin/status.html diff --git a/admin/freeposte/templates/alias/create.html b/admin/freeposte/admin/templates/alias/create.html similarity index 100% rename from admin/freeposte/templates/alias/create.html rename to admin/freeposte/admin/templates/alias/create.html diff --git a/admin/freeposte/templates/alias/edit.html b/admin/freeposte/admin/templates/alias/edit.html similarity index 100% rename from admin/freeposte/templates/alias/edit.html rename to admin/freeposte/admin/templates/alias/edit.html diff --git a/admin/freeposte/templates/alias/list.html b/admin/freeposte/admin/templates/alias/list.html similarity index 67% rename from admin/freeposte/templates/alias/list.html rename to admin/freeposte/admin/templates/alias/list.html index 8b5aab90..342b1558 100644 --- a/admin/freeposte/templates/alias/list.html +++ b/admin/freeposte/admin/templates/alias/list.html @@ -9,7 +9,7 @@ Alias list {% endblock %} {% block main_action %} -Add alias +Add alias {% endblock %} {% block box %} @@ -26,8 +26,8 @@ Alias list {% for alias in domain.aliases %} -   - +   + {{ alias }} {{ alias.destination or '-' }} diff --git a/admin/freeposte/templates/base.html b/admin/freeposte/admin/templates/base.html similarity index 88% rename from admin/freeposte/templates/base.html rename to admin/freeposte/admin/templates/base.html index af17c131..9f348bc9 100644 --- a/admin/freeposte/templates/base.html +++ b/admin/freeposte/admin/templates/base.html @@ -5,8 +5,8 @@ {% block styles %} {{super()}} - - + + {% endblock %} {% block body_attribs %} @@ -68,7 +68,7 @@ class="hold-transition skin-blue sidebar-mini" {% block scripts %} {{super()}} - + {% endblock %} {% endblock %} diff --git a/admin/freeposte/templates/domain/admins.html b/admin/freeposte/admin/templates/domain/admins.html similarity index 100% rename from admin/freeposte/templates/domain/admins.html rename to admin/freeposte/admin/templates/domain/admins.html diff --git a/admin/freeposte/templates/domain/create.html b/admin/freeposte/admin/templates/domain/create.html similarity index 100% rename from admin/freeposte/templates/domain/create.html rename to admin/freeposte/admin/templates/domain/create.html diff --git a/admin/freeposte/templates/domain/edit.html b/admin/freeposte/admin/templates/domain/edit.html similarity index 100% rename from admin/freeposte/templates/domain/edit.html rename to admin/freeposte/admin/templates/domain/edit.html diff --git a/admin/freeposte/templates/domain/list.html b/admin/freeposte/admin/templates/domain/list.html similarity index 55% rename from admin/freeposte/templates/domain/list.html rename to admin/freeposte/admin/templates/domain/list.html index adc34a27..e8ef15ea 100644 --- a/admin/freeposte/templates/domain/list.html +++ b/admin/freeposte/admin/templates/domain/list.html @@ -6,7 +6,7 @@ Domain list {% block main_action %} {% if current_user.global_admin %} -New domain +New domain {% endif %} {% endblock %} @@ -25,11 +25,11 @@ Domain list {% for domain in current_user.get_managed_domains() %} -   -   -   -   - +   +   +   +   + {{ domain.name }} {{ domain.users | count }} / {{ domain.max_users or '∞' }} diff --git a/admin/freeposte/templates/form.html b/admin/freeposte/admin/templates/form.html similarity index 100% rename from admin/freeposte/templates/form.html rename to admin/freeposte/admin/templates/form.html diff --git a/admin/freeposte/templates/helpers.html b/admin/freeposte/admin/templates/helpers.html similarity index 100% rename from admin/freeposte/templates/helpers.html rename to admin/freeposte/admin/templates/helpers.html diff --git a/admin/freeposte/templates/index.html b/admin/freeposte/admin/templates/index.html similarity index 100% rename from admin/freeposte/templates/index.html rename to admin/freeposte/admin/templates/index.html diff --git a/admin/freeposte/templates/login.html b/admin/freeposte/admin/templates/login.html similarity index 100% rename from admin/freeposte/templates/login.html rename to admin/freeposte/admin/templates/login.html diff --git a/admin/freeposte/templates/sidebar.html b/admin/freeposte/admin/templates/sidebar.html similarity index 72% rename from admin/freeposte/templates/sidebar.html rename to admin/freeposte/admin/templates/sidebar.html index b0369576..efe049f6 100644 --- a/admin/freeposte/templates/sidebar.html +++ b/admin/freeposte/admin/templates/sidebar.html @@ -4,51 +4,51 @@