diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/TESTS/tests.py | 39 | ||||
-rw-r--r-- | core/views/auth.py | 58 | ||||
-rw-r--r-- | core/views/other.py | 4 |
3 files changed, 89 insertions, 12 deletions
diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py index ec7de15..d7eeec3 100644 --- a/core/TESTS/tests.py +++ b/core/TESTS/tests.py @@ -126,18 +126,12 @@ class PageTests(TestCase): def test_expoweb_dir(self): response = self.client.get('/handbook') content = response.content.decode() - self.assertEqual(response.status_code, 200) - ph = r'Introduction to expo' - phmatch = re.search(ph, content) - self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + self.assertEqual(response.status_code, 302) # directory, so redirects to /index.htm def test_expoweb_dirslash(self): response = self.client.get('/handbook/') content = response.content.decode() - self.assertEqual(response.status_code, 200) - ph = r'Introduction to expo' - phmatch = re.search(ph, content) - self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + self.assertEqual(response.status_code, 302) # directory, so redirects to /index.htm def test_expoweb_dir_no_index(self): response = self.client.get('/handbook/troggle') @@ -147,6 +141,31 @@ class PageTests(TestCase): phmatch = re.search(ph, content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + def test_expoweb_dir_with_index_htm(self): + response = self.client.get('/years/1999/index.htm') + content = response.content.decode() + self.assertEqual(response.status_code, 200) # directory, so redirects to /index.htm + ph = r'Passage descriptions for 1999' + phmatch = re.search(ph, content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + + def test_expoweb_dir_with_index_html(self): + response = self.client.get('/years/2015/index.html') + content = response.content.decode() + self.assertEqual(response.status_code, 200) # directory, so redirects to /index.htm + ph = r'Things left at top camp 2014' + phmatch = re.search(ph, content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + + def test_expoweb_dir_with_index2(self): + response = self.client.get('/handbook/index.htm') + content = response.content.decode() + self.assertEqual(response.status_code, 200) + ph = r'Introduction to expo' + phmatch = re.search(ph, content) + #print("\n ! - test_expoweb_dir_with_index2\n{}\n{}".format(response.reason_phrase, content)) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + def test_expoweb_htm(self): response = self.client.get('/handbook/index.htm') content = response.content.decode() @@ -234,9 +253,9 @@ class PageTests(TestCase): def test_page_folk(self): # This page is separately generated, so it has the full data content - response = self.client.get('/folk/') + response = self.client.get('/folk/index.htm') content = response.content.decode() - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 200) for ph in [ r'involves some active contribution', r'Naomi Griffiths', r'Gail Smith', diff --git a/core/views/auth.py b/core/views/auth.py new file mode 100644 index 0000000..19b80a4 --- /dev/null +++ b/core/views/auth.py @@ -0,0 +1,58 @@ +from builtins import str +from django.shortcuts import render +from django.http import Http404, HttpResponseRedirect +from django.contrib.auth import authenticate, login, logout +from django.contrib.auth import forms as auth_forms + +# This is copied from CUYC.cuy.website.view.auth +# If we want to do the whole online-email thing, we would also need to copy across the code in these +# imported files and delete what is superfluous. +# Or we could just load the latest version of django-registration app. +#from cuy.club.models import Member, Message +#from ..forms import WebsiteLoginForm, WebsiteRegisterForm +#from ...common import mail_site_error +#from .generic import user_is_active + +'''The login and logout functions. +This is also where we would manage registration: for people wanting to create and validate their individual +logon accounts/forgottenpassword''' + +############################ +# Authentication Functions # +############################ + +def expologout(request): + login_form = auth_forms.AuthenticationForm() + logout(request) + + return render(request, 'login/logout.html', {'form':login_form}) + +def expologin(request): + # GET + if not request.method == 'POST': + if (not request.user.is_authenticated) or (not request.user.is_active): + return render(request, 'login/index.html', {}) + else: + # going to login page when you are already logged in + return render(request, 'tasks.html', {}) + + # POST + username = request.POST['username'] + password = request.POST['password'] + + user = authenticate(username=username, password=password) + if user is None: + return render(request, 'login/index.html', + {'invalid': True, 'username':username}) + if not user.is_active: + return render(request, 'login/enable.html', + {'login_state':'notenabled'}) + + try: + login(request, user) + # Should do the ?next= stuff here.. + return render(request, 'tasks.html', {}) + except: + return render(request, 'errors/generic.html', {}) + + diff --git a/core/views/other.py b/core/views/other.py index 4f53ead..b6e3422 100644 --- a/core/views/other.py +++ b/core/views/other.py @@ -35,8 +35,8 @@ def showrequest(request): return HttpResponse(request.GET) def frontpage(request): - '''never seen in practice''' - # bthe messages system does a popup on this page if there is a recent message, e.g. from the admin site actions. + '''never seen in common practice. Logon should redirect here when this is more useful''' + # the messages system does a popup on this page if there is a recent message, e.g. from the admin site actions. # via django.contrib.messages.middleware.MessageMiddleware # this is set in the templates. if request.user.is_authenticated(): |