From a7e6bdeb4275b2d6db48facf1770c7ef3500cecd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 26 Jan 2019 14:02:37 +0100 Subject: [PATCH] Make it run again[tm] --- dal/dal/settings.py | 1 - dal/dal/templates/base_short.html | 5 +---- dal/dal/templates/hosting_login.html | 2 +- dal/dal/templates/landing.html | 8 +++---- dal/dal/views.py | 32 ++++++++++++++-------------- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/dal/dal/settings.py b/dal/dal/settings.py index 3fa0168..05abe0f 100644 --- a/dal/dal/settings.py +++ b/dal/dal/settings.py @@ -71,7 +71,6 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', - 'sekizai.context_processors.sekizai', ], }, }, diff --git a/dal/dal/templates/base_short.html b/dal/dal/templates/base_short.html index 064217d..d2d03e1 100644 --- a/dal/dal/templates/base_short.html +++ b/dal/dal/templates/base_short.html @@ -1,4 +1,4 @@ -{% load staticfiles i18n sekizai_tags %} +{% load staticfiles i18n %} @@ -29,9 +29,6 @@ {% block css_extra %} {% endblock css_extra %} - {% render_block "css" postprocessor "compressor.contrib.sekizai.compress" %} - {% render_block "js" postprocessor "compressor.contrib.sekizai.compress" %} - diff --git a/dal/dal/templates/hosting_login.html b/dal/dal/templates/hosting_login.html index 9545cdd..8a52ae1 100644 --- a/dal/dal/templates/hosting_login.html +++ b/dal/dal/templates/hosting_login.html @@ -1,5 +1,5 @@ {% extends "hosting/base_short.html" %} -{% load i18n staticfiles bootstrap3%} +{% load i18n staticfiles %} {% block navbar %} {% include 'hosting/includes/_navbar_transparent.html' %} diff --git a/dal/dal/templates/landing.html b/dal/dal/templates/landing.html index 3556054..f56d2bb 100644 --- a/dal/dal/templates/landing.html +++ b/dal/dal/templates/landing.html @@ -1,14 +1,14 @@ {% extends "base_short.html" %} -{% load staticfiles bootstrap3 %} +{% load staticfiles %} {% block content %}
@@ -41,5 +41,3 @@ a:link { color: #000000 }
{% endblock %} - - diff --git a/dal/dal/views.py b/dal/dal/views.py index e974cf9..0ece0a1 100644 --- a/dal/dal/views.py +++ b/dal/dal/views.py @@ -1,4 +1,4 @@ -# Imports from django +# Imports from django from django.shortcuts import render from django.views.generic import View from django.contrib.auth import authenticate, login, logout @@ -11,10 +11,10 @@ from django.core.mail import EmailMessage from .models import ResetToken # Imports for the extra stuff not in django -# django_nameko is an extra module, so gets put in here + from base64 import b64encode, b64decode from datetime import datetime -from django_nameko import get_pool + from random import choice, randint import string from configparser import ConfigParser @@ -47,19 +47,19 @@ class PseudoUser(): password = ''.join(choice(string.ascii_letters + string.digits) for _ in range(30)) -# The index page +# The index page # If there's a session open, it will give the user the options he/she/it can do, if not, # it will show a landing page explaining what this is and prompt them to login class Index(View): - + # Basic binary choice, if it is an authenticated user, go straight to the options page, # if not, then show the landing page def get(self, request): if request.user.is_authenticated: return render(request, 'useroptions.html', { 'user': request.user } ) return render(request, 'landing.html') - + # Basically does the same as the GET request, just with trying to login the user beforehand # Shows an errorpage if authentication fails, since just looping to the landing page # would be frustrating @@ -74,7 +74,7 @@ class Index(View): return render(request, 'loginfailed.html') -# Registering a user +# Registering a user class Register(View): @@ -102,11 +102,11 @@ class Register(View): password2 = request.POST.get('password2') # check if the supplied passwords match if password1 != password2: - return render(request, 'error.html', { 'urlname': urlname, 'service': service, + return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Your passwords did not match. Please supply the same password twice.' } ) # check for at least a bit of length on the password if len(password1) < 8: - return render(request, 'error.html', { 'urlname': urlname, 'service': service, + return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Your password is too short, please use a longer one. At least 8 characters.' } ) email = request.POST.get('email') @@ -164,12 +164,12 @@ class ChangeData(View): # Only logged in users may change data if not request.user.is_authenticated: return render(request, 'mustbeloggedin.html') - + user = str(request.user) firstname = request.POST.get('firstname') lastname = request.POST.get('lastname') email = request.POST.get('email') - + # Some sanity checks for the supplied data if firstname == "": return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Please enter a firstname.' } ) @@ -255,7 +255,7 @@ class ResetPassword(View): # Builds the reset link for the email and puts the token into the database def build_reset_link(self, user, epochutc): - # set up the data + # set up the data host = 'account-staging.ungleich.ch' tokengen = PasswordResetTokenGenerator() # create some noise for use in the tokengenerator @@ -263,7 +263,7 @@ class ResetPassword(View): token = tokengen.make_token(pseudouser) buser = bytes(user, 'utf-8') userpart = b64encode(buser) - # create entry into the database + # create entry into the database newdbentry = ResetToken(user=user, token=token, creation=epochutc) newdbentry.save() # set up the link @@ -353,7 +353,7 @@ class ChangePassword(View): if not request.user.is_authenticated: return render(request, 'mustbeloggedin.html') return render(request, 'changepassword.html', { 'user': request.user } ) - + # Does some checks on the supplied data and changes the password def post(self, request): # Variables for the error page @@ -375,7 +375,7 @@ class ChangePassword(View): password2 = request.POST.get('password2') # Are both passwords from the form the same? if password1 != password2: - return render(request, 'error.html', { 'urlname': urlname, 'service': service, + return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Please check if you typed the same password both times for the new password' } ) # Check for password length if len(password1) < 8: @@ -417,7 +417,7 @@ class DeleteAccount(View): check = authenticate(request, username=username, password=pwd) if check is None: return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Wrong password for user.' } ) - + # Try to delete the user with get_pool().next() as rpc: result = rpc.deleteuser.delete_user(username)