mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-12-22 18:00:17 +00:00
add basic usermanagement and login functionality
This commit is contained in:
parent
401aa6c2f8
commit
3d0859ceec
2
run.sh
2
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 &
|
||||
|
@ -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/"
|
||||
|
@ -26,8 +26,9 @@
|
||||
<h2>Your Self Hosted YouTube Media Server</h2>
|
||||
<form action="/login/" method="POST" name="login">
|
||||
{% csrf_token %}
|
||||
<input type="text" name="user" id="user" placeholder="Username"><br>
|
||||
<input type="password" name="password" id="password" placeholder="Password"><br>
|
||||
{% for field in form %}
|
||||
{{ field }}<br>
|
||||
{% endfor %}
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
<p class="login-links"><span><a href="https://github.com/bbilly1/tubearchivist" target="_blank">Github</a></span> <span><a href="https://github.com/bbilly1/tubearchivist#donate" target="_blank">Donate</a></span></p>
|
||||
|
@ -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/<slug:channel_id_detail>/",
|
||||
ChannelIdView.as_view(),
|
||||
login_required(ChannelIdView.as_view()),
|
||||
name="channel_id",
|
||||
),
|
||||
path("video/<slug:video_id>/", VideoView.as_view(), name="video"),
|
||||
path(
|
||||
"video/<slug:video_id>/",
|
||||
login_required(VideoView.as_view()),
|
||||
name="video",
|
||||
),
|
||||
]
|
||||
|
@ -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"""
|
||||
|
Loading…
Reference in New Issue
Block a user