aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-10-10 12:33:14 -0400
committerBobby <[email protected]>2022-10-10 12:33:14 -0400
commitb2da687b0a39930c64e40223fbbece0d399047fa (patch)
tree945c8a6df8bf14d19c6badb087384d8ab43f1980
parent5749e2db42f2908ef7c62c8ab979def0251673d7 (diff)
downloadthatcomputerscientist-b2da687b0a39930c64e40223fbbece0d399047fa.tar.xz
thatcomputerscientist-b2da687b0a39930c64e40223fbbece0d399047fa.zip
Revert "Moving login and logout functions to subdomains"
This reverts commit 69cba5af4a819ef732e3bbb7918bacf3c020808f.
-rw-r--r--middleware/subdomainmiddleware.py3
-rw-r--r--templates/blog/partials/base.html4
-rw-r--r--templates/blog/partials/sidebar.html3
-rw-r--r--thatcomputerscientist/settings.py8
-rw-r--r--thatcomputerscientist/templatetags/subdomainurls.py29
-rw-r--r--thatcomputerscientist/urls.py2
-rw-r--r--users/urls.py1
-rw-r--r--users/views.py30
8 files changed, 15 insertions, 65 deletions
diff --git a/middleware/subdomainmiddleware.py b/middleware/subdomainmiddleware.py
index b2f39711..479c74d6 100644
--- a/middleware/subdomainmiddleware.py
+++ b/middleware/subdomainmiddleware.py
@@ -24,9 +24,6 @@ class SubdomainURLRouting:
configured_subdomains = getattr(settings, 'CONFIGURED_SUBDOMAINS', {})
if request.subdomain:
if request.subdomain in configured_subdomains:
- if request.META.get('HTTP_REFERER') is None:
- request.META['HTTP_REFERER'] = 'https://{}{}'.format(request.subdomain, settings.HOSTS[0])
-
request.urlconf = configured_subdomains[request.subdomain] + '.urls'
else:
if '*' in configured_subdomains:
diff --git a/templates/blog/partials/base.html b/templates/blog/partials/base.html
index 5ba143b9..e3bf685a 100644
--- a/templates/blog/partials/base.html
+++ b/templates/blog/partials/base.html
@@ -9,7 +9,6 @@
name="description"
content="Welcome to the home of That Computer Scientist. I am Kumar Priyansh. This is my personal website where I share all of my thoughts, ideas, and experiences."
/>
- <meta name="referrer" content="{{ request.get_host }}" />
<title>That Computer Scientist - {{ title }}</title>
<link preload rel="stylesheet" href="{% static 'css/fonts.css' %}" />
<link preload rel="stylesheet" href="{% static 'css/main.css' %}" />
@@ -44,8 +43,7 @@
Source Code
</a></li>
{% if user.is_authenticated %}
- {% load subdomainurls %}
- <li><a href="{% subdomain_url 'users:logout' 'accounts' request.build_absolute_uri %}">Logout</a></li>
+ <li><a href="{% url 'users:logout' %}">Logout</a></li>
{% endif %}
</ul>
<hr>
diff --git a/templates/blog/partials/sidebar.html b/templates/blog/partials/sidebar.html
index c9bfcfae..8bf55602 100644
--- a/templates/blog/partials/sidebar.html
+++ b/templates/blog/partials/sidebar.html
@@ -6,13 +6,12 @@
<!-- Login Box -->
</a> {% endcomment %}
<div class="lgn-area">
- {% load subdomainurls %}
<div>
{% if user.is_authenticated %}
{% else %}
<fieldset>
<legend>Login Area</legend>
- <form method="post" action="{% subdomain_url 'users:login' 'accounts' request.build_absolute_uri %}">
+ <form method="post" action="{% url 'users:login' %} ">
{% csrf_token %}
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Username" autocomplete="off">
diff --git a/thatcomputerscientist/settings.py b/thatcomputerscientist/settings.py
index 304c8815..479fbd5d 100644
--- a/thatcomputerscientist/settings.py
+++ b/thatcomputerscientist/settings.py
@@ -31,10 +31,9 @@ SECRET_KEY = os.getenv('AUTHORIZATION_STRING')
DEBUG = os.getenv('ENVIRONMENT') == 'development' or False
ALLOWED_HOSTS = ["*"]
-HOSTS = [".vcap.me"] if os.getenv('ENVIRONMENT') == 'development' else ".thatcomputerscientist.com"
-CSRF_TRUSTED_ORIGINS = ['http://*.localhost', 'https://*.thatcomputerscientist.com', 'https://*.thatcomputerscientist.fly.dev/', 'http://*.vcap.me']
-SESSION_COOKIE_DOMAIN = ".vcap.me" if os.getenv('ENVIRONMENT') == 'development' else ".thatcomputerscientist.com"
-DOMAIN_NAME = "vcap.me" if os.getenv('ENVIRONMENT') == 'development' else "thatcomputerscientist.com"
+CSRF_TRUSTED_ORIGINS = ['http://*.localhost', 'https://*.thatcomputerscientist.com', 'https://*.thatcomputerscientist.fly.dev/']
+SESSION_COOKIE_DOMAIN = "localhost" if os.getenv('ENVIRONMENT') == 'development' else ".thatcomputerscientist.com"
+DOMAIN_NAME = "localhost" if os.getenv('ENVIRONMENT') == 'development' else "thatcomputerscientist.com"
# Application definition
@@ -69,7 +68,6 @@ MIDDLEWARE = [
CONFIGURED_SUBDOMAINS = {
'': 'thatcomputerscientist',
- 'accounts': 'users',
'*': 'userpages',
}
diff --git a/thatcomputerscientist/templatetags/subdomainurls.py b/thatcomputerscientist/templatetags/subdomainurls.py
deleted file mode 100644
index fa8af0b0..00000000
--- a/thatcomputerscientist/templatetags/subdomainurls.py
+++ /dev/null
@@ -1,29 +0,0 @@
-from django.template import Library
-from django.urls import reverse
-from django.conf import settings
-
-register = Library()
-
-def subdomain_url(view_name, subdomain = None, referrer = None, *args, **kwargs):
- if subdomain == 'www':
- subdomain = None
-
- if subdomain is None:
- return reverse(view_name, args=args, kwargs=kwargs)
-
- if referrer:
- return '{}://{}{}{}?referrer={}'.format(
- 'https' if settings.SECURE_SSL_REDIRECT else 'http',
- subdomain,
- settings.HOSTS[0],
- reverse(view_name, args=args, kwargs=kwargs),
- referrer
- )
-
- return '{}://{}{}{}'.format(
- 'https' if settings.SECURE_SSL_REDIRECT else 'http',
- subdomain,
- settings.HOSTS[0],
- reverse(view_name, args=args, kwargs=kwargs)
- )
diff --git a/thatcomputerscientist/urls.py b/thatcomputerscientist/urls.py
index 05799c33..92828e7c 100644
--- a/thatcomputerscientist/urls.py
+++ b/thatcomputerscientist/urls.py
@@ -21,7 +21,7 @@ from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('blog.urls', namespace='blog')),
- path('', include(('users.urls', 'users'), namespace='users')),
+ path('users/', include('users.urls', namespace='users')),
path('blog-admin/', include('blog_admin.urls', namespace='blog-admin')),
path('', include(('userpages.urls', 'userpages'), namespace='userpages')),
path('source/', include(('dev_status.urls', 'dev_status'), namespace='dev_status')),
diff --git a/users/urls.py b/users/urls.py
index 3589c7e0..c09d7e01 100644
--- a/users/urls.py
+++ b/users/urls.py
@@ -4,7 +4,6 @@ from django.contrib import admin
app_name = 'users'
urlpatterns = [
- path('', views.home, name='home'),
path('login', views.login_user, name='login'),
path('logout', views.logout_user, name='logout'),
path('update', views.update_user, name='update'),
diff --git a/users/views.py b/users/views.py
index f1a6300b..de762863 100644
--- a/users/views.py
+++ b/users/views.py
@@ -1,4 +1,4 @@
-from django.http import HttpResponseRedirect, HttpResponse
+from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout, update_session_auth_hash
from django.contrib import messages
@@ -14,28 +14,17 @@ from django.contrib.sites.shortcuts import get_current_site
from .tokens import account_activation_token, EmailChangeTokenGenerator
from django.utils.http import urlsafe_base64_decode
import django.contrib.auth.password_validation as validators
-from django.views.decorators.csrf import csrf_exempt
-def get_ref(request):
- referrer = request.META.get('QUERY_STRING').split('referrer=')[1].split('?')[0]
- return referrer or request.META.get('HTTP_REFERER')
-
-def home(request):
- if request.user.is_authenticated:
- return HttpResponse('Hello, {}! You are logged in!'.format(request.user))
- else:
- return HttpResponse('Hello, World! You are not logged in!')
-
-@csrf_exempt
# Create your views here.
def login_user(request):
- referrer = get_ref(request)
+ # pass
+ next = request.POST.get('next', 'blog:home')
username = request.POST['username']
password = request.POST['password']
print (username, password)
if username == '' or password == '':
- messages.error(request, 'Please fill in all fields.', extra_tags='loginError')
- return HttpResponseRedirect(referrer)
+ messages.error(request, 'Please fill in all fields.')
+ return HttpResponseRedirect(next + '?username=' + username)
else:
# check if email is verified
user = authenticate(request, username=username, password=password)
@@ -43,18 +32,17 @@ def login_user(request):
email_verified = UserProfile.objects.get(user=user.pk).email_verified
if email_verified:
login(request, user)
- return HttpResponseRedirect(referrer)
+ return HttpResponseRedirect(next)
else:
messages.error(request, 'EVERR', extra_tags='loginError')
- return HttpResponseRedirect(referrer + '?username=' + username)
+ return HttpResponseRedirect(next + '?username=' + username)
else:
messages.error(request, 'Invalid username or password.', extra_tags='loginError')
- return HttpResponseRedirect(referrer + '?username=' + username)
+ return HttpResponseRedirect(next + '?username=' + username)
def logout_user(request):
- referrer = get_ref(request)
logout(request)
- return HttpResponseRedirect(referrer)
+ return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def update_user(request):
username = request.user