From bd95993653a1b94d07316e24a0f519d00f9359d6 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Tue, 4 Dec 2012 16:21:32 -0500 Subject: User can login and logout --- .gitignore | 1 + accounts/__init__.py | 0 accounts/models.py | 3 +++ accounts/tests.py | 16 ++++++++++++++++ accounts/urls.py | 6 ++++++ accounts/views.py | 5 +++++ codemash/settings.py | 14 +++++--------- codemash/urls.py | 3 +++ templates/accounts/profile.html | 9 +++++++++ templates/index.html | 5 +++++ templates/registration/logged_out.html | 6 ++++++ templates/registration/login.html | 27 +++++++++++++++++++++++++++ 12 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 accounts/__init__.py create mode 100644 accounts/models.py create mode 100644 accounts/tests.py create mode 100644 accounts/urls.py create mode 100644 accounts/views.py create mode 100644 templates/accounts/profile.html create mode 100644 templates/registration/logged_out.html create mode 100644 templates/registration/login.html diff --git a/.gitignore b/.gitignore index c18dd8d..c99f965 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__/ +/database.db diff --git a/accounts/__init__.py b/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/models.py b/accounts/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/accounts/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/accounts/tests.py b/accounts/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/accounts/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/accounts/urls.py b/accounts/urls.py new file mode 100644 index 0000000..ead707a --- /dev/null +++ b/accounts/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import patterns, include, url + + +urlpatterns = patterns('accounts.views', + url(r'^profile/$', 'profile', name='profile'), +) diff --git a/accounts/views.py b/accounts/views.py new file mode 100644 index 0000000..2616923 --- /dev/null +++ b/accounts/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + + +def profile(request): + return render(request, "accounts/profile.html") diff --git a/codemash/settings.py b/codemash/settings.py index 23b1b93..0285da9 100644 --- a/codemash/settings.py +++ b/codemash/settings.py @@ -11,20 +11,15 @@ ADMINS = ( MANAGERS = ADMINS +PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': '', # Or path to database file if using sqlite3. - # The following settings are not used with sqlite3: - 'USER': '', - 'PASSWORD': '', - 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(PROJECT_ROOT, "database.db"), } } -PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) - # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. @@ -133,6 +128,7 @@ INSTALLED_APPS = ( # 'django.contrib.admindocs', 'contact', + 'accounts', ) # A sample logging configuration. The only tangible logging diff --git a/codemash/urls.py b/codemash/urls.py index 0431c65..567499c 100644 --- a/codemash/urls.py +++ b/codemash/urls.py @@ -6,6 +6,9 @@ from django.conf.urls import patterns, include, url urlpatterns = patterns('', (r'^contact/', include('contact.urls', namespace='contact')), + (r'^accounts/', include('django.contrib.auth.urls', namespace='auth')), + (r'^accounts/', include('accounts.urls', namespace='account')), + url(r'^$', 'pages.views.home', name='home'), # Uncomment the admin/doc line below to enable admin documentation: diff --git a/templates/accounts/profile.html b/templates/accounts/profile.html new file mode 100644 index 0000000..aa6f3ad --- /dev/null +++ b/templates/accounts/profile.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} + +{% block content %} +

Your Account

+

Hello {{ user.email }}

+ +{% endblock %} diff --git a/templates/index.html b/templates/index.html index ff76c3e..1e497a5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,6 +6,11 @@

Hello Codemash

You've just created your first Django page. Pretty cool, eh?

{% endblock %} diff --git a/templates/registration/logged_out.html b/templates/registration/logged_out.html new file mode 100644 index 0000000..b6908d4 --- /dev/null +++ b/templates/registration/logged_out.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} + +{% block content %} +

You are logged out

+

You can go home.

+{% endblock %} diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..37893a9 --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} + +{% block content %} + +{% if form.errors %} +

Your username and password didn't match. Please try again.

+{% endif %} + +

Login

+
+ {% csrf_token %} + + + + + + + + + +
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
+ + + +
+ +{% endblock %} -- cgit v1.2.3