2018-05-17 16:18:20 +02:00
|
|
|
# Content DB
|
|
|
|
# Copyright (C) 2018 rubenwardy
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2018-03-18 18:43:30 +01:00
|
|
|
from flask import *
|
|
|
|
from flask_user import *
|
2018-12-22 21:13:43 +01:00
|
|
|
from flask_gravatar import Gravatar
|
2018-03-18 19:05:53 +01:00
|
|
|
import flask_menu as menu
|
2018-05-14 01:40:34 +02:00
|
|
|
from flask_mail import Mail
|
2018-03-18 19:05:53 +01:00
|
|
|
from flask_github import GitHub
|
2020-01-23 01:19:04 +01:00
|
|
|
from flask_wtf.csrf import CSRFProtect
|
2018-05-14 15:46:41 +02:00
|
|
|
from flask_flatpages import FlatPages
|
2019-07-29 22:44:39 +02:00
|
|
|
from flask_babel import Babel
|
2019-11-18 22:42:56 +01:00
|
|
|
import os, redis
|
2018-03-18 18:43:30 +01:00
|
|
|
|
2018-05-25 16:23:55 +02:00
|
|
|
app = Flask(__name__, static_folder="public/static")
|
2018-05-14 15:46:41 +02:00
|
|
|
app.config["FLATPAGES_ROOT"] = "flatpages"
|
|
|
|
app.config["FLATPAGES_EXTENSION"] = ".md"
|
2018-03-24 03:36:14 +01:00
|
|
|
app.config.from_pyfile(os.environ["FLASK_CONFIG"])
|
2018-03-18 18:43:30 +01:00
|
|
|
|
2019-11-18 22:42:56 +01:00
|
|
|
r = redis.Redis.from_url(app.config["REDIS_URL"])
|
|
|
|
|
2018-03-18 19:05:53 +01:00
|
|
|
menu.Menu(app=app)
|
|
|
|
github = GitHub(app)
|
2020-01-23 01:19:04 +01:00
|
|
|
csrf = CSRFProtect(app)
|
2018-05-14 01:40:34 +02:00
|
|
|
mail = Mail(app)
|
2018-05-14 15:46:41 +02:00
|
|
|
pages = FlatPages(app)
|
2019-07-29 22:44:39 +02:00
|
|
|
babel = Babel(app)
|
2018-12-22 21:13:43 +01:00
|
|
|
gravatar = Gravatar(app,
|
|
|
|
size=58,
|
|
|
|
rating='g',
|
|
|
|
default='mp',
|
|
|
|
force_default=False,
|
|
|
|
force_lower=False,
|
|
|
|
use_ssl=True,
|
|
|
|
base_url=None)
|
2018-03-18 19:05:53 +01:00
|
|
|
|
2019-11-16 00:51:42 +01:00
|
|
|
from .sass import sass
|
|
|
|
sass(app)
|
|
|
|
|
|
|
|
|
2019-11-14 23:24:37 +01:00
|
|
|
if not app.debug and app.config["MAIL_UTILS_ERROR_SEND_TO"]:
|
2018-07-06 23:52:19 +02:00
|
|
|
from .maillogger import register_mail_error_handler
|
|
|
|
register_mail_error_handler(app, mail)
|
|
|
|
|
2019-07-29 22:44:39 +02:00
|
|
|
|
2020-01-22 23:10:02 +01:00
|
|
|
from .markdown import init_app
|
|
|
|
init_app(app)
|
|
|
|
|
2020-01-22 23:11:01 +01:00
|
|
|
# @babel.localeselector
|
|
|
|
# def get_locale():
|
|
|
|
# return request.accept_languages.best_match(app.config['LANGUAGES'].keys())
|
2019-11-16 00:51:42 +01:00
|
|
|
|
|
|
|
from . import models, tasks, template_filters
|
|
|
|
|
|
|
|
from .blueprints import create_blueprints
|
|
|
|
create_blueprints(app)
|
|
|
|
|
|
|
|
from flask_login import logout_user
|
|
|
|
|
|
|
|
@app.route("/uploads/<path:path>")
|
|
|
|
def send_upload(path):
|
2020-01-18 02:20:32 +01:00
|
|
|
return send_from_directory(app.config['UPLOAD_DIR'], path)
|
2019-07-29 22:44:39 +02:00
|
|
|
|
2019-11-16 00:51:42 +01:00
|
|
|
@menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
|
|
|
|
@app.route('/<path:path>/')
|
|
|
|
def flatpage(path):
|
|
|
|
page = pages.get_or_404(path)
|
|
|
|
template = page.meta.get('template', 'flatpage.html')
|
|
|
|
return render_template(template, page=page)
|
2019-07-29 22:44:39 +02:00
|
|
|
|
2019-11-16 00:51:42 +01:00
|
|
|
@app.before_request
|
|
|
|
def check_for_ban():
|
|
|
|
if current_user.is_authenticated:
|
|
|
|
if current_user.rank == models.UserRank.BANNED:
|
2020-01-24 19:15:09 +01:00
|
|
|
flash("You have been banned.", "danger")
|
2019-11-16 00:51:42 +01:00
|
|
|
logout_user()
|
|
|
|
return redirect(url_for('user.login'))
|
|
|
|
elif current_user.rank == models.UserRank.NOT_JOINED:
|
|
|
|
current_user.rank = models.UserRank.MEMBER
|
|
|
|
models.db.session.commit()
|