2 # Copyright (C) 2018 rubenwardy
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 from flask_user import *
20 from flask_gravatar import Gravatar
21 import flask_menu as menu
22 from flask_mail import Mail
23 from flask_github import GitHub
24 from flask_wtf.csrf import CSRFProtect
25 from flask_flatpages import FlatPages
26 from flask_babel import Babel
29 app = Flask(__name__, static_folder="public/static")
30 app.config["FLATPAGES_ROOT"] = "flatpages"
31 app.config["FLATPAGES_EXTENSION"] = ".md"
32 app.config.from_pyfile(os.environ["FLASK_CONFIG"])
34 r = redis.Redis.from_url(app.config["REDIS_URL"])
38 csrf = CSRFProtect(app)
40 pages = FlatPages(app)
42 gravatar = Gravatar(app,
51 from .sass import sass
55 if not app.debug and app.config["MAIL_UTILS_ERROR_SEND_TO"]:
56 from .maillogger import register_mail_error_handler
57 register_mail_error_handler(app, mail)
60 from .markdown import init_app
63 # @babel.localeselector
65 # return request.accept_languages.best_match(app.config['LANGUAGES'].keys())
67 from . import models, tasks, template_filters
69 from .blueprints import create_blueprints
70 create_blueprints(app)
72 from flask_login import logout_user
74 @app.route("/uploads/<path:path>")
75 def send_upload(path):
76 return send_from_directory(app.config['UPLOAD_DIR'], path)
78 @menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
79 @app.route('/<path:path>/')
81 page = pages.get_or_404(path)
82 template = page.meta.get('template', 'flatpage.html')
83 return render_template(template, page=page)
87 if current_user.is_authenticated:
88 if current_user.rank == models.UserRank.BANNED:
89 flash("You have been banned.", "danger")
91 return redirect(url_for('user.login'))
92 elif current_user.rank == models.UserRank.NOT_JOINED:
93 current_user.rank = models.UserRank.MEMBER
94 models.db.session.commit()