Add login/logout functionality
This commit is contained in:
parent
5e23c73594
commit
4d9f4242e3
0
accounts/__init__.py
Normal file
0
accounts/__init__.py
Normal file
17
accounts/templates/accounts/login.html
Normal file
17
accounts/templates/accounts/login.html
Normal file
@ -0,0 +1,17 @@
|
||||
{% extends 'front_template.html' %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
{% if form.errors %}
|
||||
<div class="error">Username/password mismatch. Please try again!</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="{% url 'accounts:login' %}">
|
||||
{% csrf_token %}
|
||||
{{ form.username.label_tag }} {{ form.username }}<br>
|
||||
{{ form.password.label_tag }} {{ form.password }}<br>
|
||||
|
||||
<button type="submit">Login</button>
|
||||
<input type="hidden" name="next" value="{% url 'booking:list' %}">
|
||||
</form>
|
||||
{% endblock %}
|
@ -7,6 +7,29 @@ class FrontTest(TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
|
||||
self.admin = User.objects.create_user(
|
||||
username = 'admin',
|
||||
password = 'password')
|
||||
self.admin.save()
|
||||
|
||||
def test_login_page(self):
|
||||
response = self.client.get('/accounts/login')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_login(self):
|
||||
response = self.client.post('/accounts/login', {
|
||||
'next': '/',
|
||||
'username': 'admin',
|
||||
'password': 'password'})
|
||||
|
||||
self.assertRedirects(response, '/')
|
||||
|
||||
def test_logout(self):
|
||||
self.client.login(username = 'admin', password = 'aeou')
|
||||
|
||||
response = self.client.get('/accounts/logout')
|
||||
self.assertRedirects(response, '/')
|
||||
|
||||
def test_registration_page(self):
|
||||
response = self.client.get('/accounts/register')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
@ -9,4 +9,16 @@ urlpatterns = patterns(
|
||||
RegistrationFormView.as_view(),
|
||||
name = 'register'
|
||||
),
|
||||
url(
|
||||
r'^login$',
|
||||
'django.contrib.auth.views.login',
|
||||
{'template_name': 'accounts/login.html'},
|
||||
name = 'login'
|
||||
),
|
||||
url(
|
||||
r'^logout$',
|
||||
'django.contrib.auth.views.logout',
|
||||
{'next_page': 'booking:list'},
|
||||
name = 'logout'
|
||||
),
|
||||
)
|
||||
|
@ -18,6 +18,6 @@ class RegistrationFormView(generic.View):
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
|
||||
return HttpResponseRedirect(reverse('booking:index'))
|
||||
return HttpResponseRedirect(reverse('booking:list'))
|
||||
|
||||
return render(request, self.template_name, {'form': form})
|
||||
|
@ -5,9 +5,16 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Rubber Duck Booking Tool</h1>
|
||||
{% if user.is_authenticated %}
|
||||
<div>
|
||||
<a href="{% url 'accounts:register' %}">Register</a>
|
||||
Logged in as {{ user }}
|
||||
<a href="{% url 'accounts:logout' %}">Logout</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div>
|
||||
<a href="{% url 'accounts:login' %}">Login</a> or <a href="{% url 'accounts:register' %}">Register</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<a href="{% url 'booking:list' %}">Home</a>
|
||||
<a href="{% url 'booking:terms' %}">Terms and Conditions</a>
|
||||
<a href="{% url 'booking:vocabulary' %}">Vocabulary</a>
|
||||
|
@ -1,5 +1,4 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
|
Loading…
Reference in New Issue
Block a user