New user login/logoff system using standard Dj

This commit is contained in:
Philip Sargent
2021-04-06 00:49:09 +01:00
parent 6d6bec35f2
commit d1cd72c5f8
25 changed files with 348 additions and 197 deletions

View File

@@ -20,7 +20,7 @@
You are logged in as {{ user.username }}
{% if user.person %}(<a href="{{ user.person.get_absolute_url }}">{{ user.person }}</a>)
{% endif %}.
| <a href="{% url "auth_logout" %}">Log out</a> {% else %} <a href='/accounts/logout'>Sign up</a> | <a href='{% url "auth_login" %}'>Log in</a> {% endif %}
| <a <a href='/accounts/logout/'>Log out</a> {% else %} <a href='/accounts/register/'>Register</a> | <a href='/accounts/login/'>Log in</a> {% endif %}
{% endblock%}
{% block editLink %}

View File

@@ -0,0 +1,25 @@
{% extends 'base.html' %}
{% block title %}Website Error - {% endblock %}
{% block content %}
<div class='middle'>
<h2>Website Error</h2>
</div>
<div style='width: 300px;' class='middle3 login'>
<div class='align-center'>
<div class='space'></div>
<div class='align-center'>
<h3>There has been an error.</h3>
<p>We are terribly sorry but an unknown fault has occurred. </p>
</div>
</div>
</div>
{% endblock %}

View File

@@ -33,25 +33,25 @@
{% block content %}
<div id="col1">
<h3>Welcome</h3>
<p class="indent">
This is Troggle, the online system for Cambridge University Caving Club's Expeditions to Austria.
This is <b>Troggle</b>, the online system for Cambridge University Caving Club's Expeditions to Austria.
</p>
<p class="indent">
Here you will find information about the {{expedition.objects.count}} expeditions the club has undertaken since 1976. Browse survey information, photos, and description wikis for {{Cave.objects.count}} caves, {{subcave.objects.count}} areas within those caves, and {{extantqms.count}} going leads yet to be explored. We have {{Photo.objects.count}} photos and {{Logbookentry.objects.count}} logbook entries.
Here you will find information about the {{expedition.objects.count}} expeditions the club has undertaken since 1976. Browse survey information, photos, and description pages for {{Cave.objects.count}} caves and {{extantqms.count}} going leads yet to be explored. We have {{Photo.objects.count}} photos and {{Logbookentry.objects.count}} logbook entries.
</p>
<p class="indent">
You are not logged-in, so not all the pages will be visible and you will not be able to edit anything.
<!-- logged in users are directed to 'tasks.html' not this 'frontpage.html' -->
You are not logged-in, so a few of the unpublished cave survey pages will not be visible to you. And of course you will not be able to edit anything.
</p>
<!-- <img src="/expofiles/photos/2007/selected/eishoehle5nial.jpg">-->
<img src="/expofiles/photos/2007/selected/eishoehle4nial.jpg">
<p>Nial in <a href="/expofiles/photos/2007/selected/">Eishohle in 2007</a>.
{% endblock content %}
{% block margins %}
<img src="{{ settings.MEDIA_URL }}eieshole.jpg">
<img src="{{ settings.MEDIA_URL }}goesser.jpg">
{% endblock margins %}

View File

@@ -0,0 +1,53 @@
{% extends 'base.html' %}
{% block content %}
<!-- To understand how this all works, with invisible default behaviour, see
troggle/templates/login/logout.html
troggle/templates/registration/
because magic
This is because Django is Opinionated and does lots of Invisible Defaults
-->
<div class='middle'>
<h2>Troggle user login</h2>
</div>
{% if message %}
<div style='width: 350px;' class='middle3 login'>
{% if title %}
<div class='align-center'>
<h3>{{title}}</h3>
<div class='space'></div>
{% endif %}
<p>{{message }}</p>
</div>
{% endif %}
<h3>Troggle ordinary user login - no access to Django control panel</h3>
<p>(This is using template login/index.html)
<div style='width: 250px;' class='middle3 login'>
<div class='align-center'>
<div class='space'></div>
{% if invalid %}
<p class='error'>The username and password you provided don't match. Please try again.</p>
<p>Have you <a href='/accounts/forgottenpassword/'>forgotten your password</a>?<br/>
Or perhaps <a href='/accounts/forgottenusername/'>your username</a>?</p>
<p>Neither of those links work yet, by the way, I'm only trying to *appear* helpful.
<div class='space'></div>
{% endif %}
<div class='align-center'>
<form action="" method="post" accept-charset="utf-8">{% csrf_token %}
<table class='form'>
<tr><th><label for="id_username">Username:</label></th><td><input id="id_username" type="text" name="username" maxlength="30" /></td></tr>
<tr><th><label for="id_password">Password:</label></th><td><input type="password" name="password" id="id_password" /></td></tr>
</table>
<div class='space'></div>
<br/>
<p><input type="submit" value="Login &rarr;"></p>
</form>
</div>
{% endblock %}

View File

@@ -0,0 +1,51 @@
{% extends 'base.html' %}
{% block content %}
<!-- this overrides the django.contrib.auth default logout form
and it must be placed in
troggle/templates/login/logout.html
because magic
Note that we need to have TWO DIFFERENT logout templates to make this work,
the other one is in
troggle/templates/registration/
That one is for logging out of the Django Admin system.
This one is for logging out of the normal system whereas this one
Not forgetting the template in
troggle/templates/login/index
which also has a login form.
This is because Django is Opinionated and does lots of Invisible Defaults
-->
<div class='middle'>
<h2>You have been logged out</h2>
</div>
<h3>Troggle ordinary user login - no access to Django control panel</h3>
<p>(using template login/logout.html)
<div style='width: 250px;' class='middle3 login'>
<div class='align-center'>
<div class='space'></div>
<div class='align-center'>
<form action="/login/" method="post" accept-charset="utf-8">{% csrf_token %}
<table class='form'>
{{form.as_table}}
</table>
<div class='space'></div>
<span class='indent'>
<br /><input type="submit" value="Login &rarr;">
</form>
</div>
</form>
</div>
</div>
{% endblock %}

View File

@@ -1,25 +0,0 @@
{% extends "base.html" %}
{% block title %}
New troggle account registered
{% endblock %}
{% block header %}
<h1>activate.html</h1>
{% endblock %}
{% block content %}
{% if account %}
<p>
Hello, {{ account }}! Your account is now activated. Now you can <a href="{%url "auth_login"%}">log in</a> with the password you chose. Use the links in the upper right to control this in the future.
</p>
<p>
If you have been on the expedition in the past, you already have a profile in the system; <a href={% url "profiles_select_profile" %}>click here </a> to find it and link it to your account. Otherwise, please <a href={% url "profiles_create_profile" %}> create yourself a new profile</a>.
</p>
{% else %}
The activation key you entered has already been used or was invalid.
{% endif %}
{% endblock %}

View File

@@ -1,10 +0,0 @@
<P>Hello {{ form.user }},</P>
<P>Glad you're joining the CUCC EXPO team! Please go to</P>
<P><a href="{{ site }}{% url "registration_activate" activation_key %}">{{ site }}{% url "registration_activate" activation_key %}</a></P>
<P>to activate your account. Do this within {{ expiration_days }} days, or else you'll have to sign up again.</P>
<P>Yours,<BR>
The magical troggle</P>

View File

@@ -1,10 +0,0 @@
Hello {{ form.user }},
Glad you're joining the CUCC EXPO team! Please go to
{{ site }}{% url "registration_activate" activation_key %}
to activate your account. Do this within {{ expiration_days }} days, or else you'll have to sign up again.
Yours,
The magical troggle

View File

@@ -1 +0,0 @@
[CUCC Expo] Activation email

View File

@@ -0,0 +1,55 @@
{% extends 'base.html' %}
{% block content %}
<!-- this overrides the django.contrib.admin default logout form
and it must be placed in
troggle/templates/registration/
because magic
Note that we need to have TWO DIFFERENT logout templates to make this work,
the other one is in
troggle/templates/login/logout.html
That one is for logging out
of the normal system whereas this one is for logging out of the Django Admin system.
Not forgetting the template in
troggle/templates/login/index
which also has a login form.
This is because Django is Opinionated and does lots of Invisible Defaults
-->
<div class='middle'>
<h2>You have been logged out</h2>
</div>
<!-- Yeah this logon form sometimes fails to appear, and then the Submit button gives a horrible crash.
All because of some CSRF horribleness ? Possibly.
So let's not even attempt to have it here, OK?
-->
<!--
<h3>Troggle user Login</h3>
<p>(using template registration/logged_out.html)
<div style='width: 250px;' class='middle3 login'>
<div class='align-center'>
<div class='space'></div>
<div class='align-center'>
<form action="/login/" method="post" accept-charset="utf-8">{% csrf_token %}
<table class='form'>
{{form.as_table}}
</table>
<div class='space'></div>
<span class='indent'>
<br /><input type="submit" value="Login &rarr;">
</form>
</div>
-->
<form action="/accounts/login/" method="GET" accept-charset="utf-8">
<br /><input type="submit" value="Login &rarr;">
</form>
{% endblock %}

View File

@@ -1,27 +0,0 @@
{% extends "base.html" %}
{% load csrffaker %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<div align="center">
<pre>This uses the registration/login.html template</pre>
<form method="post" action=".">{% csrf_token %}
<table>
<tr><td>{{ form.username.label_tag }}</td><td>{{ form.username }}</td></tr>
<tr><td>{{ form.password.label_tag }}</td><td>{{ form.password }}</td></tr>
</table>
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
</div>
{% endblock %}

View File

@@ -1,4 +0,0 @@
{% extends "base.html" %}
{% block content %}
You have been logged out.
{% endblock %}

View File

@@ -1,6 +0,0 @@
{% extends “base.html” %}
{% block body %}
Hello {{ account }}!
Check your email to confirm the activation. There are {{ expiration_days }} days left to do it.
{% endblock %}

View File

@@ -1,13 +0,0 @@
{% extends "base.html" %}
{% block title %}
{{ block.super }}: registration complete
{% endblock %}
{% block contentheader %}
<h1>Registration Complete</h1>
{% endblock %}
{% block content %}
<p>Thank you for signing up. An email with the activation code has been sent to your inbox. </p>
{% endblock %}

View File

@@ -1,50 +0,0 @@
{% extends "base.html" %}
{% block title %}
registration_form.html | {{ block.super }}
{% endblock %}
{% block header %}
<h1>registration_form.html</h1>
{% endblock %}
{% block content %}
<form action="{% url "registration_register" %}" method="POST">{% csrf_token %}
{% for error in form.non_field_errors %}
<span style="color:red">{{ error }}</span>
{% endfor %}
<table>
<tr>
<td align="right" valign="top">Username:</td>
<td>
{{ form.username }} <br/>
{% for error in form.username.errors %}
<span style="color:red">{{ error }}</span>
{% endfor %}
</td>
</tr>
<tr>
<td align="right" valign="top">Email:</td>
<td>
{{ form.email }} <br/>
{% for error in form.email.errors %}
<span style="color:red">{{ error }}</span>
{% endfor %}
</td>
</tr>
<tr>
<td align="right" valign="top">Password:</td>
<td>
{{ form.password1 }} <br/>
{% for error in form.password1.errors %}
<span style="color:red">{{ error }}</span>
{% endfor %}
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Register" /></td>
</tr>
</table>
</form>
{% endblock %}