diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f73f84e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3 + +RUN useradd --system --gid root --uid 1001 uwsgi +RUN pip install uwsgi psycopg2_binary + +RUN mkdir -p /app +COPY . /app +WORKDIR /app +RUN pip install . + +EXPOSE 3031 +CMD ["uwsgi", "--master", "--workers", "4", "--socket", "0.0.0.0:3031", "--protocol", "uwsgi", \ + "--plugin", "python3", "--uid", "uwsgi", "--wsgi", "libertywiki.wsgi"] diff --git a/docker-compose.local.yaml b/docker-compose.local.yaml new file mode 100644 index 0000000..8b6db8f --- /dev/null +++ b/docker-compose.local.yaml @@ -0,0 +1,21 @@ +version: '3' +services: + wiki: + build: + context: . + environment: + - SQLALCHEMY_DATABASE_URI=postgresql://wiki:wiki@postgres/wiki + - SECRET_KEY=super-secret-key-replace-me + - SECURITY_PASSWORD_SALT=password-salt-replace-me + postgres: + image: postgres:14 + environment: + - POSTGRES_USER=wiki + - POSTGRES_PASSWORD=wiki + - POSTGRES_DB=wiki + nginx: + image: nginx + volumes: + - "./nginx.conf:/etc/nginx/conf.d/default.conf:ro" + ports: + - "8000:80" diff --git a/libertywiki/decorators.py b/libertywiki/decorators.py index 9311098..9cb391f 100644 --- a/libertywiki/decorators.py +++ b/libertywiki/decorators.py @@ -4,7 +4,7 @@ from flask import current_app, request from flask_login import current_user from flask_login.config import EXEMPT_METHODS -from libertywiki.utils import AccessType, WikiMode +from libertywiki.utils import WikiMode, needs_authentication def check_access(access_type): @@ -21,12 +21,10 @@ def check_access(access_type): if request.method in EXEMPT_METHODS or \ current_app.config.get('LOGIN_DISABLED'): pass - elif (wiki_mode == WikiMode.PRIVATE - or (wiki_mode == WikiMode.PUBLIC and access_type == AccessType.READ)) \ + elif needs_authentication(wiki_mode, access_type) \ and not current_user.is_authenticated: return current_app.login_manager.unauthorized() try: - # current_app.ensure_sync available in Flask >= 2.0 return current_app.ensure_sync(func)(*args, **kwargs) except AttributeError: return func(*args, **kwargs) diff --git a/libertywiki/templates/admin/base.html b/libertywiki/templates/admin/base.html new file mode 100644 index 0000000..d67565e --- /dev/null +++ b/libertywiki/templates/admin/base.html @@ -0,0 +1,104 @@ +{% import 'admin/layout.html' as layout with context -%} +{% import 'admin/static.html' as admin_static with context %} + + +
+- Authentication -
-- This example shows how you can use Flask-Security for authentication. -
+You can register as a regular user, or log in as a superuser with the following credentials: -