From dfeca6a325c1e13fe6d6be08d32ad5eaf4b304b0 Mon Sep 17 00:00:00 2001 From: Trent Palmer Date: Wed, 24 Feb 2021 20:13:54 -0800 Subject: [PATCH] initial commit --- .gitignore | 2 + accounts/__init__.py | 0 accounts/admin.py | 3 + accounts/apps.py | 5 + accounts/enable_totp.py | 58 +++++++ accounts/forms.py | 59 ++++++++ accounts/login.py | 58 +++++++ accounts/migrations/0001_initial.py | 30 ++++ accounts/migrations/__init__.py | 0 accounts/models.py | 12 ++ accounts/templates/accounts/totp_form.html | 26 ++++ accounts/tests.py | 3 + accounts/urls.py | 16 ++ accounts/views.py | 48 ++++++ audio/__init__.py | 0 audio/admin.py | 3 + audio/apps.py | 5 + audio/audiorssfeed.py | 92 ++++++++++++ audio/episode_views.py | 54 +++++++ audio/forms.py | 24 +++ audio/migrations/0001_initial.py | 31 ++++ audio/migrations/0002_auto_20210221_2256.py | 28 ++++ audio/migrations/0003_auto_20210221_2256.py | 18 +++ audio/migrations/0004_feed_description.py | 19 +++ audio/migrations/0005_feed_image.py | 19 +++ audio/migrations/0006_auto_20210222_1603.py | 19 +++ audio/migrations/0007_auto_20210222_2100.py | 20 +++ audio/migrations/0008_auto_20210223_0018.py | 42 ++++++ audio/migrations/0009_episode_pub_date.py | 19 +++ .../migrations/0010_episode_episode_number.py | 18 +++ audio/migrations/__init__.py | 0 audio/models.py | 65 ++++++++ audio/templates/audio/feeds.html | 54 +++++++ audio/templates/audio/index.html | 87 +++++++++++ audio/tests.py | 3 + audio/urls.py | 18 +++ audio/views.py | 80 ++++++++++ manage.py | 22 +++ tp/__init__.py | 0 tp/asgi.py | 16 ++ tp/models.py | 9 ++ tp/settings.py | 141 ++++++++++++++++++ tp/storage_backends.py | 18 +++ tp/templates/base.html | 49 ++++++ tp/templates/base_form.html | 54 +++++++ tp/templates/base_heading.html | 35 +++++ tp/templates/base_navbar.html | 20 +++ tp/templates/confirmation.html | 26 ++++ tp/urls.py | 23 +++ tp/wsgi.py | 16 ++ 50 files changed, 1467 insertions(+) create mode 100644 .gitignore create mode 100644 accounts/__init__.py create mode 100644 accounts/admin.py create mode 100644 accounts/apps.py create mode 100644 accounts/enable_totp.py create mode 100644 accounts/forms.py create mode 100644 accounts/login.py create mode 100644 accounts/migrations/0001_initial.py create mode 100644 accounts/migrations/__init__.py create mode 100644 accounts/models.py create mode 100644 accounts/templates/accounts/totp_form.html create mode 100644 accounts/tests.py create mode 100644 accounts/urls.py create mode 100644 accounts/views.py create mode 100644 audio/__init__.py create mode 100644 audio/admin.py create mode 100644 audio/apps.py create mode 100644 audio/audiorssfeed.py create mode 100644 audio/episode_views.py create mode 100644 audio/forms.py create mode 100644 audio/migrations/0001_initial.py create mode 100644 audio/migrations/0002_auto_20210221_2256.py create mode 100644 audio/migrations/0003_auto_20210221_2256.py create mode 100644 audio/migrations/0004_feed_description.py create mode 100644 audio/migrations/0005_feed_image.py create mode 100644 audio/migrations/0006_auto_20210222_1603.py create mode 100644 audio/migrations/0007_auto_20210222_2100.py create mode 100644 audio/migrations/0008_auto_20210223_0018.py create mode 100644 audio/migrations/0009_episode_pub_date.py create mode 100644 audio/migrations/0010_episode_episode_number.py create mode 100644 audio/migrations/__init__.py create mode 100644 audio/models.py create mode 100644 audio/templates/audio/feeds.html create mode 100644 audio/templates/audio/index.html create mode 100644 audio/tests.py create mode 100644 audio/urls.py create mode 100644 audio/views.py create mode 100755 manage.py create mode 100644 tp/__init__.py create mode 100644 tp/asgi.py create mode 100644 tp/models.py create mode 100644 tp/settings.py create mode 100644 tp/storage_backends.py create mode 100644 tp/templates/base.html create mode 100644 tp/templates/base_form.html create mode 100644 tp/templates/base_heading.html create mode 100644 tp/templates/base_navbar.html create mode 100644 tp/templates/confirmation.html create mode 100644 tp/urls.py create mode 100644 tp/wsgi.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..321039d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +db.sqlite3 diff --git a/accounts/__init__.py b/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/admin.py b/accounts/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/accounts/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/accounts/apps.py b/accounts/apps.py new file mode 100644 index 0000000..9b3fc5a --- /dev/null +++ b/accounts/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + name = 'accounts' diff --git a/accounts/enable_totp.py b/accounts/enable_totp.py new file mode 100644 index 0000000..117f5a4 --- /dev/null +++ b/accounts/enable_totp.py @@ -0,0 +1,58 @@ +from django.shortcuts import redirect, render +import qrcode.image.svg +from .forms import EnableTotpForm +from django.contrib import messages +from .models import Account +from io import BytesIO +import pyotp +import qrcode + + +def disable_totp(request): + if not request.user.is_authenticated: + return redirect('audio:home') + if not request.user.account.use_totp: + return redirect('audio:home') + if request.method == "POST": + account = Account.objects.get(user=request.user) + account.use_totp = False + account.totp_key = None + account.save() + messages.success(request, 'Thanks for disabling 2fa!', extra_tags="mb-0") + return(redirect('accounts:edit_profile')) + return render(request, 'confirmation.html', {}) + + +def enable_totp(request): + if not request.user.is_authenticated: + return redirect('audio:home') + qr = get_totp_qr(request.user) + if request.method == "POST": + form = EnableTotpForm(request.POST, instance=request.user.account) + if form.is_valid(): + totp_code = form.cleaned_data['totp_code'] + if pyotp.TOTP(request.user.account.totp_key).verify(int(totp_code), valid_window=5): + account = Account.objects.get(user=request.user) + account.use_totp = True + account.save() + messages.success(request, 'Thanks for enabling 2fa!', extra_tags="mb-0") + return(redirect('accounts:edit_profile')) + else: + messages.error(request, 'Wrong Code, try again?', extra_tags="mb-0") + else: + form = EnableTotpForm(instance=request.user.account) + return render(request, 'accounts/totp_form.html', {'form': form, 'qr': qr}) + + +def get_totp_qr(user): + if user.account.totp_key is None: + account = Account.objects.get(user=user) + account.totp_key = pyotp.random_base32() + account.save() + user.account.totp_key = account.totp_key + + totp_uri = pyotp.totp.TOTP(user.account.totp_key).provisioning_uri(name='audio', issuer_name='trentpalmer.org') + img = qrcode.make(totp_uri, image_factory=qrcode.image.svg.SvgPathImage) + f = BytesIO() + img.save(f) + return(f.getvalue().decode('utf-8')) diff --git a/accounts/forms.py b/accounts/forms.py new file mode 100644 index 0000000..5560241 --- /dev/null +++ b/accounts/forms.py @@ -0,0 +1,59 @@ +from django.contrib.auth.forms import ValidationError, UsernameField # , UserCreationForm +from django.contrib.auth.models import User +from django import forms +from .models import Account + + +class EnableTotpForm(forms.ModelForm): + + totp_code = forms.CharField(max_length=6) + + class Meta: + model = Account + fields = ("totp_code", ) + + +class EditProfileForm(forms.Form): + email = forms.EmailField( + required=True, + label='Email', + max_length=254, + widget=forms.EmailInput(attrs={'autocomplete': 'email'}) + ) + + first_name = UsernameField(required=False) + last_name = UsernameField(required=False) + + password = forms.CharField( + label="confirm password", + strip=False, + widget=forms.PasswordInput(attrs={'autocomplete': 'current-password'}), + ) + + def __init__(self, user, *args, **kwargs): + self.user = user + super(EditProfileForm, self).__init__(*args, **kwargs) + + def clean(self): + email = self.cleaned_data.get('email') + first_name = self.cleaned_data.get('first_name') + last_name = self.cleaned_data.get('last_name') + password = self.cleaned_data["password"] + if not self.user.check_password(password): + raise ValidationError("password is incorrect.") + if email != self.user.email: + if User.objects.filter(email=email).exists(): + raise ValidationError("An account already exists with this email address.") + return { + 'email': email, + 'first_name': first_name, + 'last_name': last_name, + } + + def save(self, commit=True): + self.user.email = self.cleaned_data['email'] + self.user.first_name = self.cleaned_data['first_name'] + self.user.last_name = self.cleaned_data['last_name'] + if commit: + self.user.save() + return self.user diff --git a/accounts/login.py b/accounts/login.py new file mode 100644 index 0000000..1ae7dc5 --- /dev/null +++ b/accounts/login.py @@ -0,0 +1,58 @@ +from django.shortcuts import render, redirect +from django.contrib.auth.forms import AuthenticationForm +from .forms import EnableTotpForm +from django.contrib.auth import login +from .models import Account +from django.contrib.auth.models import User +from django.contrib import messages +import pyotp +from time import sleep + + +def log_in(request): + if request.user.is_authenticated: + return redirect('audio:home') + if request.method == "POST": + form = AuthenticationForm(data=request.POST) + if form.is_valid(): + user = form.get_user() + if not hasattr(user, 'account'): + account = Account(user=user) + account.save() + user.account = account + if user.account.use_totp: + request.session['user_id'] = user.id + request.session['totp_timeout'] = 1 + return redirect('accounts:two_factor_input') + else: + login(request, user) + messages.success(request, 'Successfully logged in!', extra_tags="mb-0") + return redirect('audio:home') + else: + form = AuthenticationForm() + return render(request, 'base_form.html', {'form': form}) + + +def two_factor_input(request): + if request.user.is_authenticated: + return redirect('audio:home') + if 'user_id' not in request.session: + return redirect('audio:home') + user = User.objects.get(id=request.session['user_id']) + if request.method == "POST": + form = EnableTotpForm(request.POST, instance=user.account) + if form.is_valid(): + totp_code = form.cleaned_data['totp_code'] + if pyotp.TOTP(user.account.totp_key).verify(int(totp_code), valid_window=5): + login(request, user) + del request.session['user_id'] + messages.success(request, 'Successfully logged in!', extra_tags="mb-0") + return redirect('audio:home') + else: + form = EnableTotpForm(instance=user.account) + messages.error(request, 'Wrong Code, try again?', extra_tags="mb-0") + sleep(request.session['totp_timeout']) + request.session['totp_timeout'] = request.session['totp_timeout'] * 2 + else: + form = EnableTotpForm(instance=user.account) + return render(request, 'accounts/totp_form.html', {'form': form}) diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py new file mode 100644 index 0000000..15de7b8 --- /dev/null +++ b/accounts/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 3.1.6 on 2021-02-21 22:18 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Account', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('totp_key', models.CharField(max_length=16, null=True)), + ('use_totp', models.BooleanField(default=False)), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/accounts/migrations/__init__.py b/accounts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/models.py b/accounts/models.py new file mode 100644 index 0000000..d0dd793 --- /dev/null +++ b/accounts/models.py @@ -0,0 +1,12 @@ +from django.db import models +from tp.models import UUIDAsIDModel +from django.contrib.auth.models import User + + +class Account(UUIDAsIDModel): + user = models.OneToOneField(User, on_delete=models.CASCADE, unique=True) + totp_key = models.CharField(max_length=16, null=True) + use_totp = models.BooleanField(default=False) + + def __str__(self): + return str(self.user) diff --git a/accounts/templates/accounts/totp_form.html b/accounts/templates/accounts/totp_form.html new file mode 100644 index 0000000..17b90d5 --- /dev/null +++ b/accounts/templates/accounts/totp_form.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% load crispy_forms_tags %} + +{% block content %} + + {% include "base_navbar.html" %} + {% include "base_heading.html" %} +
+
+ + {{ qr | safe }} +
+
+ +
+
+ {% csrf_token %} + {{ form | crispy }} +
+ +
+
+
+ +{% endblock %} diff --git a/accounts/tests.py b/accounts/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/accounts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/accounts/urls.py b/accounts/urls.py new file mode 100644 index 0000000..fd021bf --- /dev/null +++ b/accounts/urls.py @@ -0,0 +1,16 @@ +from django.urls import path +from .enable_totp import enable_totp, disable_totp +from .login import log_in, two_factor_input +from . import views + +app_name = "accounts" + +urlpatterns = [ + path('login/', log_in, name='login'), + path('logout/', views.log_out, name='logout'), + path('edit-profile/', views.edit_profile, name='edit_profile'), + path('password-change/', views.password_change, name='password_change'), + path('enable-totp/', enable_totp, name='enable_totp'), + path('disable-totp/', disable_totp, name='disable_totp'), + path('two-factor-input/', two_factor_input, name='two_factor_input'), +] diff --git a/accounts/views.py b/accounts/views.py new file mode 100644 index 0000000..bbb5032 --- /dev/null +++ b/accounts/views.py @@ -0,0 +1,48 @@ +from django.shortcuts import render, redirect +from django.contrib.auth.forms import PasswordChangeForm +from django.contrib import messages +from django.contrib.auth import logout, update_session_auth_hash +from .forms import EditProfileForm + + +def password_change(request): + if not request.user.is_authenticated: + return redirect('audio:home') + if request.method == "POST": + form = PasswordChangeForm(request.user, request.POST) + if form.is_valid(): + user = form.save() + update_session_auth_hash(request, user) + messages.success(request, 'Your password was successfully updated!', extra_tags="mb-0") + return redirect('accounts:edit_profile') + else: + form = PasswordChangeForm(request.user) + return render(request, 'base_form.html', {'form': form}) + + +def log_out(request): + if not request.user.is_authenticated: + return redirect('audio:home') + if request.method == "POST": + logout(request) + messages.success(request, 'Successfully Logged Out!', extra_tags="mb-0") + return redirect('audio:home') + return render(request, 'confirmation.html', {}) + + +def edit_profile(request): + if not request.user.is_authenticated: + return redirect('audio:home') + if request.method == "POST": + form = EditProfileForm(request.user, request.POST) + if form.is_valid(): + form.save() + messages.success(request, 'Your profile was successfully updated!', extra_tags="mb-0") + return redirect('audio:home') + else: + form = EditProfileForm(request.user, initial={ + 'email': request.user.email, + 'first_name': request.user.first_name, + 'last_name': request.user.last_name, + }) + return render(request, 'base_form.html', {'form': form}) diff --git a/audio/__init__.py b/audio/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/audio/admin.py b/audio/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/audio/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/audio/apps.py b/audio/apps.py new file mode 100644 index 0000000..cda5238 --- /dev/null +++ b/audio/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AudioConfig(AppConfig): + name = 'audio' diff --git a/audio/audiorssfeed.py b/audio/audiorssfeed.py new file mode 100644 index 0000000..7494586 --- /dev/null +++ b/audio/audiorssfeed.py @@ -0,0 +1,92 @@ +from django.contrib.syndication.views import Feed as RSSFeed +from django.contrib.sites.shortcuts import get_current_site +from django.urls import reverse +from django.utils.feedgenerator import Rss201rev2Feed +from tp.settings import IMAGES_URL, MP3_URL +from .models import Feed +from datetime import datetime + + +class AudioRssFeedGenerator(Rss201rev2Feed): + content_type = 'application/xml; charset=utf-8' + + def add_root_elements(self, handler): + super().add_root_elements(handler) + handler.startElement("image", {}) + handler.addQuickElement("url", self.feed['image_url']) + handler.addQuickElement("title", self.feed['image_title']) + handler.addQuickElement("link", self.feed['image_link']) + handler.addQuickElement("description", self.feed['image_desc']) + handler.endElement("image") + + def add_item_elements(self, handler, item): + super().add_item_elements(handler, item) + handler.startElement("image", {}) + handler.addQuickElement("url", item['image_url']) + handler.addQuickElement("title", item['image_title']) + handler.addQuickElement("link", item['image_link']) + handler.addQuickElement("description", item['image_desc']) + handler.endElement("image") + + +class AudioRssFeed(RSSFeed): + + feed_type = AudioRssFeedGenerator + + def get_object(self, request, slug): + obj = Feed.objects.get(slug=slug) + obj.request = request + return obj + + def items(self, obj): + xr = [x for x in obj.episode_set.order_by('pub_date')] + for x in xr: + x.request = obj.request + return xr + + def item_enclosure_url(self, item): + return f'{MP3_URL}{item.mp3}' + + def item_enclosure_length(self, item): + return item.image.size + + def item_enclosure_mime_type(self, item): + return "audio/mpeg" + + def item_pubdate(self, item): + ''' + Need to return datetime.datetime object, + but item.pub_date is an datetime.date object + ''' + return datetime.fromisoformat(item.pub_date.isoformat()) + + def link(self, obj): + return reverse('audio:feed', kwargs={'pk': obj.pk, 'slug': obj.slug}) + + def title(self, obj): + return obj.title + + def description(self, obj): + return obj.description + + def item_link(self, item): + return reverse('audio:episode', kwargs={'pk': item.pk, 'slug': item.slug}) + + def item_title(self, item): + return f'{item.episode_number}: {item.title}' + + def item_extra_kwargs(self, item): + x = {} + x['image_url'] = f'{IMAGES_URL}{item.image.name}' + x['image_title'] = item.title + x['image_link'] = f'{get_current_site(item.request)}{self.item_link(item)}' + x['image_desc'] = f'Image for: {item.title}' + return x + + def feed_extra_kwargs(self, obj): + x = {} + x['image_url'] = f'{IMAGES_URL}{obj.image.name}' + x['image_title'] = obj.title + x['image_link'] = f'{get_current_site(obj.request)}{self.link(obj)}' + x['image_desc'] = f'Image for: {obj.title}' + return x diff --git a/audio/episode_views.py b/audio/episode_views.py new file mode 100644 index 0000000..af84423 --- /dev/null +++ b/audio/episode_views.py @@ -0,0 +1,54 @@ +from django.shortcuts import render, redirect +from .forms import EpisodeForm +from .models import Feed, Episode + + +def edit_episode(request, pk, title_slug): + if not request.user.is_authenticated: + return redirect('audio:home') + episode = Episode.objects.get(id=pk) + if not episode.user == request.user: + return redirect('audio:home') + if request.method == "POST": + form = EpisodeForm(request.POST, request.FILES, instance=episode) + if form.is_valid(): + form.save() + return redirect('audio:home') + else: + form = EpisodeForm(instance=episode) + return render( + request, 'base_form.html', + { + 'form': form, + 'heading': 'Edit Episode?', + 'title': 'Edit Episode?', + 'submit': 'save', + 'form_data': 'TRUE', + }) + + +def new_episode(request, feed_pk, feed_title_slug): + if not request.user.is_authenticated: + return redirect('audio:home') + feed = Feed.objects.get(id=feed_pk) + if not feed.user == request.user: + return redirect('audio:home') + if request.method == "POST": + form = EpisodeForm(request.POST, request.FILES) + if form.is_valid(): + episode = form.save(commit=False) + episode.user = request.user + episode.feed = feed + episode.save() + return redirect('audio:new_feed') + else: + form = EpisodeForm() + return render( + request, 'base_form.html', + { + 'form': form, + 'heading': 'New Episode?', + 'title': 'New Episode?', + 'submit': 'submit', + 'form_data': 'TRUE', + }) diff --git a/audio/forms.py b/audio/forms.py new file mode 100644 index 0000000..1742ac3 --- /dev/null +++ b/audio/forms.py @@ -0,0 +1,24 @@ +from .models import Feed, Episode +from django import forms + + +class FeedForm(forms.ModelForm): + + class Meta: + model = Feed + fields = [ + 'title', 'author', 'description', 'image' + ] + + +class EpisodeForm(forms.ModelForm): + + pub_date = forms.DateField( + widget=forms.TextInput(attrs={'type': 'date'}) + ) + + class Meta: + model = Episode + fields = [ + 'title', 'author', 'pub_date', 'episode_number', 'description', 'image', 'mp3' + ] diff --git a/audio/migrations/0001_initial.py b/audio/migrations/0001_initial.py new file mode 100644 index 0000000..8728a1f --- /dev/null +++ b/audio/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 3.1.6 on 2021-02-22 06:44 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Feed', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('created_on', models.DateTimeField(auto_now_add=True)), + ('title', models.CharField(max_length=120)), + ('author', models.CharField(max_length=120)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/audio/migrations/0002_auto_20210221_2256.py b/audio/migrations/0002_auto_20210221_2256.py new file mode 100644 index 0000000..28c3abb --- /dev/null +++ b/audio/migrations/0002_auto_20210221_2256.py @@ -0,0 +1,28 @@ +# Generated by Django 3.1.6 on 2021-02-22 06:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('audio', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='feed', + name='slug', + field=models.SlugField(max_length=255, null=True, unique=True), + ), + migrations.AlterField( + model_name='feed', + name='author', + field=models.CharField(max_length=255), + ), + migrations.AlterField( + model_name='feed', + name='title', + field=models.CharField(max_length=255), + ), + ] diff --git a/audio/migrations/0003_auto_20210221_2256.py b/audio/migrations/0003_auto_20210221_2256.py new file mode 100644 index 0000000..56460e0 --- /dev/null +++ b/audio/migrations/0003_auto_20210221_2256.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.6 on 2021-02-22 06:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('audio', '0002_auto_20210221_2256'), + ] + + operations = [ + migrations.AlterField( + model_name='feed', + name='slug', + field=models.SlugField(max_length=255, unique=True), + ), + ] diff --git a/audio/migrations/0004_feed_description.py b/audio/migrations/0004_feed_description.py new file mode 100644 index 0000000..ffafb02 --- /dev/null +++ b/audio/migrations/0004_feed_description.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.6 on 2021-02-22 21:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('audio', '0003_auto_20210221_2256'), + ] + + operations = [ + migrations.AddField( + model_name='feed', + name='description', + field=models.TextField(default=''), + preserve_default=False, + ), + ] diff --git a/audio/migrations/0005_feed_image.py b/audio/migrations/0005_feed_image.py new file mode 100644 index 0000000..442288b --- /dev/null +++ b/audio/migrations/0005_feed_image.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.6 on 2021-02-23 00:02 + +from django.db import migrations, models +import tp.storage_backends + + +class Migration(migrations.Migration): + + dependencies = [ + ('audio', '0004_feed_description'), + ] + + operations = [ + migrations.AddField( + model_name='feed', + name='image', + field=models.ImageField(null=True, storage=tp.storage_backends.PublicImageStorage(), upload_to=''), + ), + ] diff --git a/audio/migrations/0006_auto_20210222_1603.py b/audio/migrations/0006_auto_20210222_1603.py new file mode 100644 index 0000000..7aea7ce --- /dev/null +++ b/audio/migrations/0006_auto_20210222_1603.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.6 on 2021-02-23 00:03 + +from django.db import migrations, models +import tp.storage_backends + + +class Migration(migrations.Migration): + + dependencies = [ + ('audio', '0005_feed_image'), + ] + + operations = [ + migrations.AlterField( + model_name='feed', + name='image', + field=models.ImageField(blank=True, null=True, storage=tp.storage_backends.PublicImageStorage(), upload_to=''), + ), + ] diff --git a/audio/migrations/0007_auto_20210222_2100.py b/audio/migrations/0007_auto_20210222_2100.py new file mode 100644 index 0000000..b3bf79d --- /dev/null +++ b/audio/migrations/0007_auto_20210222_2100.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1.6 on 2021-02-23 05:00 + +import audio.models +from django.db import migrations, models +import tp.storage_backends + + +class Migration(migrations.Migration): + + dependencies = [ + ('audio', '0006_auto_20210222_1603'), + ] + + operations = [ + migrations.AlterField( + model_name='feed', + name='image', + field=models.ImageField(blank=True, null=True, storage=tp.storage_backends.PublicImageStorage(), upload_to=audio.models.slugify_file_name), + ), + ] diff --git a/audio/migrations/0008_auto_20210223_0018.py b/audio/migrations/0008_auto_20210223_0018.py new file mode 100644 index 0000000..d1811b0 --- /dev/null +++ b/audio/migrations/0008_auto_20210223_0018.py @@ -0,0 +1,42 @@ +# Generated by Django 3.1.6 on 2021-02-23 08:18 + +import audio.models +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import tp.storage_backends +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('audio', '0007_auto_20210222_2100'), + ] + + operations = [ + migrations.AlterField( + model_name='feed', + name='image', + field=models.ImageField(blank=True, null=True, storage=tp.storage_backends.PublicImageStorage(), upload_to=audio.models.slugify_file_name), + ), + migrations.CreateModel( + name='Episode', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('title', models.CharField(max_length=255)), + ('author', models.CharField(max_length=255)), + ('slug', models.SlugField(max_length=255, unique=True)), + ('description', models.TextField()), + ('created_on', models.DateTimeField(auto_now_add=True)), + ('image', models.ImageField(blank=True, null=True, storage=tp.storage_backends.PublicImageStorage(), upload_to=audio.models.slugify_file_name)), + ('mp3', models.FileField(blank=True, null=True, storage=tp.storage_backends.PublicMP3Storage(), upload_to=audio.models.slugify_file_name)), + ('feed', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='audio.feed')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/audio/migrations/0009_episode_pub_date.py b/audio/migrations/0009_episode_pub_date.py new file mode 100644 index 0000000..ba17fd1 --- /dev/null +++ b/audio/migrations/0009_episode_pub_date.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.6 on 2021-02-23 08:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('audio', '0008_auto_20210223_0018'), + ] + + operations = [ + migrations.AddField( + model_name='episode', + name='pub_date', + field=models.DateField(default=None), + preserve_default=False, + ), + ] diff --git a/audio/migrations/0010_episode_episode_number.py b/audio/migrations/0010_episode_episode_number.py new file mode 100644 index 0000000..d21ea29 --- /dev/null +++ b/audio/migrations/0010_episode_episode_number.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.7 on 2021-02-24 01:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('audio', '0009_episode_pub_date'), + ] + + operations = [ + migrations.AddField( + model_name='episode', + name='episode_number', + field=models.IntegerField(null=True), + ), + ] diff --git a/audio/migrations/__init__.py b/audio/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/audio/models.py b/audio/models.py new file mode 100644 index 0000000..591face --- /dev/null +++ b/audio/models.py @@ -0,0 +1,65 @@ +from django.db import models +from tp.models import UUIDAsIDModel +from django.contrib.auth.models import User +from django.utils.text import slugify +from tp.storage_backends import PublicImageStorage, PublicMP3Storage +import string, random + + +def rand_slug(): + return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8)) + + +def slugify_file_name(instance, filename): + fname, dot, extension = filename.rpartition('.') + slug = slugify(fname) + return f'{slug}.{extension}' + + +class Feed(UUIDAsIDModel): + user = models.ForeignKey(User, on_delete=models.CASCADE) + created_on = models.DateTimeField(auto_now_add=True) + title = models.CharField(max_length=255) + author = models.CharField(max_length=255) + slug = models.SlugField(max_length=255, unique=True) + description = models.TextField(null=False) + image = models.ImageField( + storage=PublicImageStorage(), + upload_to=slugify_file_name, + null=True, blank=True) + + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(rand_slug() + "-" + self.title) + super(Feed, self).save(*args, **kwargs) + + def __str__(self): + return str(self.title) + + +class Episode(UUIDAsIDModel): + user = models.ForeignKey(User, on_delete=models.CASCADE) + feed = models.ForeignKey(Feed, on_delete=models.CASCADE) + title = models.CharField(max_length=255) + author = models.CharField(max_length=255) + slug = models.SlugField(max_length=255, unique=True) + description = models.TextField(null=False) + created_on = models.DateTimeField(auto_now_add=True) + pub_date = models.DateField() + episode_number = models.IntegerField(null=True) + image = models.ImageField( + storage=PublicImageStorage(), + upload_to=slugify_file_name, + null=True, blank=True) + mp3 = models.FileField( + storage=PublicMP3Storage(), + upload_to=slugify_file_name, + null=True, blank=True) + + def save(self, *args, **kwargs): + if not self.slug: + self.slug = slugify(rand_slug() + "-" + self.title) + super(Episode, self).save(*args, **kwargs) + + def __str__(self): + return str(self.title) diff --git a/audio/templates/audio/feeds.html b/audio/templates/audio/feeds.html new file mode 100644 index 0000000..0bfccc5 --- /dev/null +++ b/audio/templates/audio/feeds.html @@ -0,0 +1,54 @@ +{% extends "base.html" %} + +{% block content %} + {% include "base_navbar.html" %} + {% include "base_heading.html" %} + +
+
+
+
+
+ {% for i in feeds %} +
+

+ {{ i.title }} +

+
+
+
+ +
+
+
+

{{ i.created_on }}

+

{{ i.title }}

+

RSS

+

{{ i.description }}

+
+
+
+
+ + {% if user.is_authenticated %} + {% if user == i.user %} +
+ + +
+ {% endif %} + {% endif %} + +
+ {% endfor %} +
+
+
+
+
+ +{% endblock %} diff --git a/audio/templates/audio/index.html b/audio/templates/audio/index.html new file mode 100644 index 0000000..3fba44c --- /dev/null +++ b/audio/templates/audio/index.html @@ -0,0 +1,87 @@ +{% extends "base.html" %} + +{% block content %} + {% include "base_navbar.html" %} + {% include "base_heading.html" %} +
+
+
+
+
+ {% for j in episodes %} +
+

+ {{ j.episode_number }}. {{ j.title }} +

+
+
+
+ +
+
+
+

{{ j.pub_date }}

+

{{ j.title }}

+

RSS

+

{{ j.description }}

+
+
+
+
+
+ +
+ + {% if user.is_authenticated %} + {% if user == j.user %} +
+ +
+ {% endif %} + {% endif %} + +
+ {% endfor %} +
+
+
+
+
+ + +{% endblock %} + + {% for j in episodes %} +
+

+ {{ j.title }} +

+ {{ j.title }} +

+ {{ j.pub_date }} +

+

+ {{ j.description }} +

+
+ +
+ RSS
+ + {% if user.is_authenticated %} + {% if user == j.user %} + + {% endif %} + {% endif %} +
+ {% endfor %} diff --git a/audio/tests.py b/audio/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/audio/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/audio/urls.py b/audio/urls.py new file mode 100644 index 0000000..374b3bf --- /dev/null +++ b/audio/urls.py @@ -0,0 +1,18 @@ +from django.urls import path +from . import views +from .episode_views import new_episode, edit_episode +from .audiorssfeed import AudioRssFeed + +app_name = "audio" + +urlpatterns = [ + path('', views.home, name='home'), + path('new-feed/', views.new_feed, name='new_feed'), + path('feeds/', views.feeds, name='feeds'), + path('edit-feed//', views.edit_feed, name='edit_feed'), + path('new-episode//', new_episode, name='new_episode'), + path('edit-episode//', edit_episode, name='edit_episode'), + path('rss/.xml', AudioRssFeed(), name='rss'), + path('feed//', views.feed, name='feed'), + path('episode//', views.episode, name='episode'), +] diff --git a/audio/views.py b/audio/views.py new file mode 100644 index 0000000..f7662a7 --- /dev/null +++ b/audio/views.py @@ -0,0 +1,80 @@ +from django.shortcuts import render, redirect +from .forms import FeedForm +from .models import Feed, Episode +from tp.settings import IMAGES_URL, MP3_URL + + +def home(request): + episodes = Episode.objects.all() + return render( + request, + 'audio/index.html', + {'episodes': episodes, 'IMAGES_URL': IMAGES_URL, 'MP3_URL': MP3_URL}) + + +def feed(request, pk, slug): + feed = Feed.objects.get(id=pk) + episodes = feed.episode_set.all() + return render( + request, 'audio/index.html', + { + 'episodes': episodes, 'IMAGES_URL': IMAGES_URL, + 'MP3_URL': MP3_URL, 'title': feed.title, 'heading': feed.title + }) + + +def episode(request, pk, slug): + episode = Episode.objects.get(id=pk) + return render( + request, 'audio/index.html', + { + 'episodes': (episode, ), 'IMAGES_URL': IMAGES_URL, + 'MP3_URL': MP3_URL, 'title': episode.title, 'heading': episode.title + }) + + +def feeds(request): + feeds = Feed.objects.all().order_by('-created_on') + return render( + request, + 'audio/feeds.html', + {'feeds': feeds, 'IMAGES_URL': IMAGES_URL}) + + +def new_feed(request): + if not request.user.is_authenticated: + return redirect('audio:home') + if request.method == "POST": + form = FeedForm(request.POST, request.FILES) + if form.is_valid(): + feed = form.save(commit=False) + feed.user = request.user + feed.save() + return redirect('audio:new_feed') + else: + form = FeedForm() + return render(request, 'base_form.html', {'form': form}) + + +def edit_feed(request, pk, title_slug): + if not request.user.is_authenticated: + return redirect('audio:home') + feed = Feed.objects.get(id=pk) + if not feed.user == request.user: + return redirect('audio:home') + if request.method == "POST": + form = FeedForm(request.POST, request.FILES, instance=feed) + if form.is_valid(): + feed.save() + return redirect('audio:new_feed') + else: + form = FeedForm(instance=feed) + return render( + request, 'base_form.html', + { + 'form': form, + 'heading': 'Edit Feed?', + 'title': 'Edit Feed?', + 'submit': 'save', + 'form_data': 'TRUE', + }) diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..bb0944f --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tp.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/tp/__init__.py b/tp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tp/asgi.py b/tp/asgi.py new file mode 100644 index 0000000..9953763 --- /dev/null +++ b/tp/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for tp project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tp.settings') + +application = get_asgi_application() diff --git a/tp/models.py b/tp/models.py new file mode 100644 index 0000000..4115418 --- /dev/null +++ b/tp/models.py @@ -0,0 +1,9 @@ +from django.db import models +import uuid + + +class UUIDAsIDModel(models.Model): + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + + class Meta: + abstract = True diff --git a/tp/settings.py b/tp/settings.py new file mode 100644 index 0000000..7740596 --- /dev/null +++ b/tp/settings.py @@ -0,0 +1,141 @@ +from pathlib import Path +import os +from dotenv import load_dotenv +load_dotenv() + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = str(os.getenv('SECRET_KEY')) + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True if str(os.getenv('DEBUG')) == "True" else False + +ALLOWED_HOSTS = [x for x in os.environ.get('ALLOWED_HOSTS').split(' ')] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'bootstrap4', + 'crispy_forms', + 'audio.apps.AudioConfig', + 'accounts.apps.AccountsConfig', + 'storages', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'tp.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': ['tp/templates'], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'tp.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + +CRISPY_TEMPLATE_PACK = 'bootstrap4' + + +# Password validation +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Los_Angeles' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.1/howto/static-files/ + +# STATIC_URL = '/static/' + +# aws settings +AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID') +AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY') +AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME') +AWS_S3_ENDPOINT_URL = os.getenv('AWS_S3_ENDPOINT_URL') +AWS_DEFAULT_ACL = None +# AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com' +AWS_S3_CUSTOM_DOMAIN = os.getenv('AWS_S3_CUSTOM_DOMAIN') +AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'} +# s3 static settings +STATIC_LOCATION = 'static' +STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{STATIC_LOCATION}/' +STATICFILES_STORAGE = 'tp.storage_backends.StaticStorage' +# s3 public media settings +PUBLIC_MP3_LOCATION = 'mp3' +MP3_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{PUBLIC_MP3_LOCATION}/' +MP3_FILE_STORAGE = 'tp.storage_backends.PublicMP3Storage' +PUBLIC_IMAGES_LOCATION = 'images' +IMAGES_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{PUBLIC_IMAGES_LOCATION}/' +IMAGES_FILE_STORAGE = 'tp.storage_backends.PublicImageStorage' + +STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),) diff --git a/tp/storage_backends.py b/tp/storage_backends.py new file mode 100644 index 0000000..33b8e73 --- /dev/null +++ b/tp/storage_backends.py @@ -0,0 +1,18 @@ +from storages.backends.s3boto3 import S3Boto3Storage +# from django.conf import settings + + +class StaticStorage(S3Boto3Storage): + location = 'static' + default_acl = 'public-read' + + +class PublicMP3Storage(S3Boto3Storage): + location = 'mp3' + default_acl = 'public-read' + # file_overwrite = False + + +class PublicImageStorage(S3Boto3Storage): + location = 'images' + default_acl = 'public-read' diff --git a/tp/templates/base.html b/tp/templates/base.html new file mode 100644 index 0000000..479f1bc --- /dev/null +++ b/tp/templates/base.html @@ -0,0 +1,49 @@ + + + + + + + + {% url 'audio:home' as home_url %} + {% url 'accounts:login' as login_url %} + {% url 'accounts:logout' as logout_url %} + {% url 'accounts:edit_profile' as edit_profile_url %} + {% url 'accounts:password_change' as password_change_url %} + {% url 'accounts:enable_totp' as enable_totp_url %} + {% url 'accounts:disable_totp' as disable_totp_url %} + {% url 'audio:new_feed' as new_feed_url %} + {% url 'audio:feeds' as feeds_url %} + + {% if request.path == home_url %} + Home + {% elif request.path == login_url %} + Login? + {% elif request.path == logout_url %} + Logout? + {% elif request.path == edit_profile_url %} + Edit Profile? + {% elif request.path == password_change_url %} + Change Password? + {% elif request.path == enable_totp_url %} + Enable 2fa? + {% elif request.path == disable_totp_url %} + Disable 2fa? + {% elif request.path == new_feed_url %} + New Feed? + {% elif request.path == feeds_url %} + Feeds + {% endif %} + + {{ title }} + + + {% load bootstrap4 %} + {% bootstrap_css %} + {% bootstrap_messages %} + + + {% block content %}{% endblock content %} + {% bootstrap_javascript jquery='full' %} + + diff --git a/tp/templates/base_form.html b/tp/templates/base_form.html new file mode 100644 index 0000000..bb54be1 --- /dev/null +++ b/tp/templates/base_form.html @@ -0,0 +1,54 @@ +{% extends "base.html" %} + +{% load crispy_forms_tags %} + +{% block content %} + {% url 'accounts:login' as login_url %} + {% url 'accounts:edit_profile' as edit_profile_url %} + {% url 'accounts:password_change' as password_change_url %} + {% url 'audio:new_feed' as new_feed_url %} + + {% if request.path == login_url %} + {% firstof 'Login' as submit %} + {% elif request.path == edit_profile_url %} + {% firstof 'Update' as submit %} + {% elif request.path == password_change_url %} + {% firstof 'Update' as submit %} + {% elif request.path == new_feed_url %} + {% firstof 'Submit' as submit %} + {% endif %} + + {% include "base_navbar.html" %} + {% include "base_heading.html" %} + +
+
+ + {% if request.path == new_feed_url %} +
+ {% elif form_data == "TRUE" %} + + {% else %} + + {% endif %} + {% csrf_token %} + {{ form | crispy }} +
+ +
+

+ {% if request.path == edit_profile_url %} +
+
+ {% if user.account.use_totp %} + Disable 2fa + {% else %} + Enable 2fa + {% endif %} + Change Password +
+
+ {% endif %} +
+
+{% endblock %} diff --git a/tp/templates/base_heading.html b/tp/templates/base_heading.html new file mode 100644 index 0000000..48c3e99 --- /dev/null +++ b/tp/templates/base_heading.html @@ -0,0 +1,35 @@ +
+
+

+ {% url 'accounts:login' as login_url %} + {% url 'accounts:edit_profile' as edit_profile_url %} + {% url 'accounts:password_change' as password_change_url %} + {% url 'accounts:enable_totp' as enable_totp_url %} + {% url 'accounts:disable_totp' as disable_totp_url %} + {% url 'audio:new_feed' as new_feed_url %} + {% url 'audio:feeds' as feeds_url %} + {% url 'audio:home' as home_url %} + + {% if request.path == login_url %} + Login? + {% elif request.path == edit_profile_url %} + Edit Profile? + {% elif request.path == password_change_url %} + Change Password? + {% elif request.path == enable_totp_url %} + Enable 2fa? + {% elif request.path == disable_totp_url %} + Disable 2fa? + {% elif request.path == new_feed_url %} + New Feed? + {% elif request.path == feeds_url %} + Feeds + {% elif request.path == home_url %} + Home + {% endif %} + + {{ heading }} + +

+
+
diff --git a/tp/templates/base_navbar.html b/tp/templates/base_navbar.html new file mode 100644 index 0000000..cbef9a6 --- /dev/null +++ b/tp/templates/base_navbar.html @@ -0,0 +1,20 @@ +
+ +
diff --git a/tp/templates/confirmation.html b/tp/templates/confirmation.html new file mode 100644 index 0000000..36e332a --- /dev/null +++ b/tp/templates/confirmation.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% load crispy_forms_tags %} + +{% block content %} + {% url 'accounts:logout' as logout_url %} + {% url 'accounts:disable_totp' as disable_totp_url %} + + {% if request.path == logout_url %} + {% firstof 'Logout' as submit %} + {% elif request.path == disable_totp_url %} + {% firstof 'OK' as submit %} + {% endif %} + + {% include "base_navbar.html" %} +
+ {% include "base_heading.html" %} +
+
+
+ {% csrf_token %} + +
+
+
+{% endblock %} diff --git a/tp/urls.py b/tp/urls.py new file mode 100644 index 0000000..c32d1f8 --- /dev/null +++ b/tp/urls.py @@ -0,0 +1,23 @@ +"""tp URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('audio.urls')), + path('accounts/', include('accounts.urls')), +] diff --git a/tp/wsgi.py b/tp/wsgi.py new file mode 100644 index 0000000..41b6b4b --- /dev/null +++ b/tp/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for tp project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tp.settings') + +application = get_wsgi_application()