diff options
author | Mike Crute <mcrute@gmail.com> | 2012-12-04 16:44:28 -0500 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2012-12-20 22:00:11 -0500 |
commit | ce3b9091f080c2a33a60d23af99de3222e570024 (patch) | |
tree | 68e7a84b800e6d91ffe26d48e31e34aa88ce64d3 /accounts | |
parent | bd95993653a1b94d07316e24a0f519d00f9359d6 (diff) | |
download | django-precompiler-ce3b9091f080c2a33a60d23af99de3222e570024.tar.bz2 django-precompiler-ce3b9091f080c2a33a60d23af99de3222e570024.tar.xz django-precompiler-ce3b9091f080c2a33a60d23af99de3222e570024.zip |
User can create account
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/forms.py | 7 | ||||
-rw-r--r-- | accounts/urls.py | 1 | ||||
-rw-r--r-- | accounts/views.py | 25 |
3 files changed, 32 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 @@ | |||
1 | from django.contrib.auth.forms import UserCreationForm as _UserForm | ||
2 | |||
3 | |||
4 | class 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 | ||
4 | urlpatterns = patterns('accounts.views', | 4 | urlpatterns = 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 @@ | |||
1 | from django.shortcuts import render | 1 | from django.shortcuts import render, redirect |
2 | from django.contrib.auth import authenticate, login | ||
3 | |||
4 | from accounts.forms import UserCreationForm | ||
2 | 5 | ||
3 | 6 | ||
4 | def profile(request): | 7 | def profile(request): |
5 | return render(request, "accounts/profile.html") | 8 | return render(request, "accounts/profile.html") |
9 | |||
10 | |||
11 | def 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 | }) | ||