hiding, I mean, sophisticatifying the instance url checking

This commit is contained in:
autocommit 2020-05-30 08:10:52 +00:00 committed by user
parent acaf2f62c1
commit 98caf2ab84
No known key found for this signature in database
GPG Key ID: F66D599380F88521
2 changed files with 46 additions and 37 deletions

View File

@ -200,41 +200,49 @@ SESSION_SERIALIZER = "django.contrib.sessions.serializers.PickleSerializer"
# URL to redirect users to when not logged in
ANONYMOUS_HOME_URL = "about"
# URL to redirect gab users to
GAB_RICKROLL_URL = "https://invidio.us/watch?v=dQw4w9WgXcQ"
# URL to redirect galaxy brain users to
RICKROLL_URL = "https://invidio.us/watch?v=dQw4w9WgXcQ"
# Function to check if trying to add an account should trigger a special response
def CHECK_INSTANCE_URL(url, redirect):
if "gab.com" in url:
return redirect(RICKROLL_URL)
elif "shitposter.club" in url:
return redirect(RICKROLL_URL)
# Version number displayed on about page
BRUTALDON_VERSION = "2.14.1"
# Load custom settings outside repository tracked files, so you don't have to publish your passwords and hosts to github.com for all to see
# Load custom settings outside repository tracked files, so private settings
# don't get added to the repository
import sys
def paths():
sys.path.append('???')
try:
from xdg import XDG_CONFIG_HOME, XDG_CONFIG_DIRS
except ImportError:
try:
from pathlib import Path
except ImportError:
home = os.environ['home']
else:
home = Path.home()
sys.path[-1] = os.path.join(home, ".config")
yield
sys.path[-1] = home
yield
else:
sys.path[-1] = XDG_CONFIG_HOME
yield
for directory in XDG_CONFIG_DIRS:
sys.path[-1] = directory
yield
finally:
sys.path.pop(-1)
sys.path.append('???')
try:
from xdg import XDG_CONFIG_HOME, XDG_CONFIG_DIRS
except ImportError:
try:
from pathlib import Path
except ImportError:
home = os.environ['home']
else:
home = Path.home()
sys.path[-1] = os.path.join(home, ".config")
yield
sys.path[-1] = home
yield
else:
sys.path[-1] = XDG_CONFIG_HOME
yield
for directory in XDG_CONFIG_DIRS:
sys.path[-1] = directory
yield
finally:
sys.path.pop(-1)
for _ in paths():
try:
from brutaldon_settings import *
except ImportError: pass
else:
break
try:
from brutaldon_settings import *
except ImportError: pass
else:
break

View File

@ -393,8 +393,9 @@ def login(request):
redirect_uris = request.build_absolute_uri(reverse("oauth_callback"))
if form.is_valid():
api_base_url = form.cleaned_data["instance"]
if "gab.com" in api_base_url:
return redirect(django_settings.GAB_RICKROLL_URL)
resp = django_settings.CHECK_INSTANCE_URL(api_base_url, redirect)
if resp is not None:
return resp
tmp_base = parse.urlparse(api_base_url.lower())
if tmp_base.netloc == "":
api_base_url = parse.urlunparse(
@ -772,10 +773,10 @@ def settings(request):
if request.method == "POST":
form = PreferencesForm(request.POST)
if form.is_valid():
for field in account.preferences._fields:
if field in form.cleaned_data:
setattr(account.preferences, field,
form.cleaned_data[field])
for field in account.preferences._fields:
if field in form.cleaned_data:
setattr(account.preferences, field,
form.cleaned_data[field])
request.session["timezone"] = account.preferences.timezone
account.preferences.save()
account.save()