diff --git a/run.sh b/run.sh
index e1eb4b7..c85f5f2 100644
--- a/run.sh
+++ b/run.sh
@@ -13,7 +13,9 @@ until curl "$ES_URL" -fs; do
sleep 5
done
+python manage.py makemigrations
python manage.py migrate
+python manage.py createsuperuser --noinput
python manage.py collectstatic --noinput -c
nginx &
celery -A home.tasks worker --loglevel=INFO &
diff --git a/tubearchivist/config/settings.py b/tubearchivist/config/settings.py
index 655a385..b49a2d0 100644
--- a/tubearchivist/config/settings.py
+++ b/tubearchivist/config/settings.py
@@ -142,3 +142,5 @@ STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
+
+LOGIN_URL = "/login/"
diff --git a/tubearchivist/home/templates/home/login.html b/tubearchivist/home/templates/home/login.html
index ea625d7..d7bfed5 100644
--- a/tubearchivist/home/templates/home/login.html
+++ b/tubearchivist/home/templates/home/login.html
@@ -26,8 +26,9 @@
Your Self Hosted YouTube Media Server
Github Donate
diff --git a/tubearchivist/home/urls.py b/tubearchivist/home/urls.py
index b10a947..8fb6a01 100644
--- a/tubearchivist/home/urls.py
+++ b/tubearchivist/home/urls.py
@@ -1,5 +1,6 @@
""" all home app urls """
+from django.contrib.auth.decorators import login_required
from django.urls import path
from home.views import (
AboutView,
@@ -10,23 +11,29 @@ from home.views import (
LoginView,
SettingsView,
VideoView,
+ process,
+ progress,
)
-from . import views
-
urlpatterns = [
- path("", HomeView.as_view(), name="home"),
+ path("", login_required(HomeView.as_view()), name="home"),
path("login/", LoginView.as_view(), name="login"),
path("about/", AboutView.as_view(), name="about"),
- path("downloads/", DownloadView.as_view(), name="downloads"),
- path("settings/", SettingsView.as_view(), name="settings"),
- path("process/", views.process, name="process"),
- path("downloads/progress/", views.progress, name="progress"),
- path("channel/", ChannelView.as_view(), name="channel"),
+ path(
+ "downloads/", login_required(DownloadView.as_view()), name="downloads"
+ ),
+ path("settings/", login_required(SettingsView.as_view()), name="settings"),
+ path("process/", login_required(process), name="process"),
+ path("downloads/progress/", login_required(progress), name="progress"),
+ path("channel/", login_required(ChannelView.as_view()), name="channel"),
path(
"channel//",
- ChannelIdView.as_view(),
+ login_required(ChannelIdView.as_view()),
name="channel_id",
),
- path("video//", VideoView.as_view(), name="video"),
+ path(
+ "video//",
+ login_required(VideoView.as_view()),
+ name="video",
+ ),
]
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py
index b1c6fd9..0f568d5 100644
--- a/tubearchivist/home/views.py
+++ b/tubearchivist/home/views.py
@@ -8,6 +8,10 @@ import json
import urllib.parse
from time import sleep
+from django import forms
+from django.contrib.auth import login
+from django.contrib.auth.forms import AuthenticationForm
+from django.forms.widgets import PasswordInput, TextInput
from django.http import JsonResponse
from django.shortcuts import redirect, render
from django.utils.http import urlencode
@@ -126,6 +130,17 @@ class HomeView(View):
return redirect(search_url, permanent=True)
+class CustomAuthForm(AuthenticationForm):
+ """better styled login form"""
+
+ username = forms.CharField(
+ widget=TextInput(attrs={"placeholder": "Username"}), label=False
+ )
+ password = forms.CharField(
+ widget=PasswordInput(attrs={"placeholder": "Password"}), label=False
+ )
+
+
class LoginView(View):
"""resolves to /login/
Greeting and login page
@@ -134,11 +149,23 @@ class LoginView(View):
def get(self, request):
"""handle get requests"""
colors = self.read_config()
+ form = CustomAuthForm()
context = {
"colors": colors,
+ "form": form,
}
return render(request, "home/login.html", context)
+ @staticmethod
+ def post(request):
+ """handle login post request"""
+ form = AuthenticationForm(data=request.POST)
+ if form.is_valid():
+ user = form.get_user()
+ login(request, user)
+
+ return redirect("/")
+
@staticmethod
def read_config():
"""read needed values from redis"""