Commit f113a589 authored by smilin_desperado's avatar smilin_desperado

Move login/logout to accounts app

parent dc9808f2
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class AccountsConfig(AppConfig):
name = 'accounts'
from django.db import models
# Create your models here.
......@@ -22,7 +22,7 @@
{% endif %}
{% endif %}
<h2 class="">Job Application Tracker</h2>
<form method='post' action="{% url 'login' %}">
<form method='post' action="{% url 'accounts:login' %}">
{% csrf_token %}
<div class="form-group">
{{ form.username.label_tag }}
......@@ -5,6 +5,6 @@
{% block pagecontent %}
<div class="container p-5">
<h2>Thanks for using this job application tracker</h2>
<p>Click <a href="{% url 'login' %}">here</a> to login again</p>
<p>Click <a href="{% url 'accounts:login' %}">here</a> to login again</p>
{% endblock %}
from django.test import TestCase
from django.test.utils import setup_test_environment
from django.urls import reverse
class LoginTests(TestCase):
def test_unauthenticated_user_redirects_to_login(self):
response = self.client.get('/', follow=True)
html = response.content.decode('utf8')
self.assertRedirects(response, '/accounts/login/?next=/')
self.assertIn('Please login to see this page', html)
self.assertIn('<title>Login | JAT</title>', html)
def test_login_empty_submit(self):
response ='/accounts/login/', {})
html = response.content.decode('utf8')
self.assertIn("Your username and password didn't match. Please try again", html)
def test_login_incorrect_details(self):
response ='/accounts/login/', {'username': 'abc', 'password': 'badpass'})
html = response.content.decode('utf8')
self.assertIn("Your username and password didn't match. Please try again", html)
from django.urls import path
from django.contrib.auth.views import LoginView, LogoutView
app_name = 'accounts'
urlpatterns = [
path('login/', LoginView.as_view(template_name="accounts/login.html"), name='login'),
path('logout/', LogoutView.as_view(template_name="accounts/logout.html"), name='logout'),
from django.shortcuts import render
# Create your views here.
......@@ -27,6 +27,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__fil
# Application definition
......@@ -121,7 +122,6 @@ STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
LOGIN_URL = 'login'
LOGIN_REDIRECT_URL = 'tracker:index'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
......@@ -14,13 +14,12 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from django.urls import path, include, path
from django.conf import settings
urlpatterns = [
path('', include('tracker.urls')),
path('login/', auth_views.LoginView.as_view(template_name='login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='logout.html'), name='logout'),
path('accounts/', include('accounts.urls')),
......@@ -21,7 +21,7 @@
<br/><span class="text-muted">{{ user.username}}</span>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'logout' %}">Log out</a>
<a class="dropdown-item" href="{% url 'accounts:logout' %}">Log out</a>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment