aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2012-12-04 16:44:28 -0500
committerMike Crute <mcrute@gmail.com>2012-12-20 22:00:11 -0500
commitce3b9091f080c2a33a60d23af99de3222e570024 (patch)
tree68e7a84b800e6d91ffe26d48e31e34aa88ce64d3
parentbd95993653a1b94d07316e24a0f519d00f9359d6 (diff)
downloaddjango-precompiler-ce3b9091f080c2a33a60d23af99de3222e570024.tar.bz2
django-precompiler-ce3b9091f080c2a33a60d23af99de3222e570024.tar.xz
django-precompiler-ce3b9091f080c2a33a60d23af99de3222e570024.zip
User can create account
-rw-r--r--accounts/forms.py7
-rw-r--r--accounts/urls.py1
-rw-r--r--accounts/views.py25
-rw-r--r--templates/accounts/create.html11
-rw-r--r--templates/index.html2
5 files changed, 45 insertions, 1 deletions
diff --git a/accounts/forms.py b/accounts/forms.py
new file mode 100644
index 0000000..abdab79
--- /dev/null
+++ b/accounts/forms.py
@@ -0,0 +1,7 @@
1from django.contrib.auth.forms import UserCreationForm as _UserForm
2
3
4class UserCreationForm(_UserForm):
5
6 class Meta(_UserForm.Meta):
7 fields = ("username", "email")
diff --git a/accounts/urls.py b/accounts/urls.py
index ead707a..08f8f38 100644
--- a/accounts/urls.py
+++ b/accounts/urls.py
@@ -3,4 +3,5 @@ from django.conf.urls import patterns, include, url
3 3
4urlpatterns = patterns('accounts.views', 4urlpatterns = patterns('accounts.views',
5 url(r'^profile/$', 'profile', name='profile'), 5 url(r'^profile/$', 'profile', name='profile'),
6 url(r'^create/$', 'create_account', name='create'),
6) 7)
diff --git a/accounts/views.py b/accounts/views.py
index 2616923..4a0d3ed 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -1,5 +1,28 @@
1from django.shortcuts import render 1from django.shortcuts import render, redirect
2from django.contrib.auth import authenticate, login
3
4from accounts.forms import UserCreationForm
2 5
3 6
4def profile(request): 7def profile(request):
5 return render(request, "accounts/profile.html") 8 return render(request, "accounts/profile.html")
9
10
11def create_account(request):
12 form = UserCreationForm()
13
14 if request.method == "POST":
15 form = UserCreationForm(request.POST)
16
17 if form.is_valid():
18 form.save()
19
20 user = authenticate(username=form.cleaned_data["username"],
21 password=form.cleaned_data["password1"])
22 login(request, user)
23
24 return redirect("account:profile")
25
26 return render(request, "accounts/create.html", {
27 "form": form,
28 })
diff --git a/templates/accounts/create.html b/templates/accounts/create.html
new file mode 100644
index 0000000..130f180
--- /dev/null
+++ b/templates/accounts/create.html
@@ -0,0 +1,11 @@
1{% extends "base.html" %}
2
3{% block content %}
4<h1>Register an Account</h1>
5
6<form method="post" action="{% url 'account:create' %}">
7 {% csrf_token %}
8 {{ form.as_p }}
9 <input type="submit" value="Register" />
10</form>
11{% endblock %}
diff --git a/templates/index.html b/templates/index.html
index 1e497a5..2bba5df 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -7,9 +7,11 @@
7<ul> 7<ul>
8 <li><a href="{% url 'contact:form' %}">Contact Us</a></li> 8 <li><a href="{% url 'contact:form' %}">Contact Us</a></li>
9{% if user.is_authenticated %} 9{% if user.is_authenticated %}
10 <li><a href="{% url 'account:profile' %}">{{ user.username }}'s profile</a></li>
10 <li><a href="{% url 'auth:logout' %}">Logout ({{ user.username }})</a></li> 11 <li><a href="{% url 'auth:logout' %}">Logout ({{ user.username }})</a></li>
11{% else %} 12{% else %}
12 <li><a href="{% url 'auth:login' %}">Login</a></li> 13 <li><a href="{% url 'auth:login' %}">Login</a></li>
14 <li><a href="{% url 'account:create' %}">Register</a></li>
13{% endif %} 15{% endif %}
14</ul> 16</ul>
15<p>You've just created your first Django page. Pretty cool, eh?</p> 17<p>You've just created your first Django page. Pretty cool, eh?</p>