From ce3b9091f080c2a33a60d23af99de3222e570024 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Tue, 4 Dec 2012 16:44:28 -0500 Subject: User can create account --- accounts/views.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'accounts/views.py') 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 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect +from django.contrib.auth import authenticate, login + +from accounts.forms import UserCreationForm def profile(request): return render(request, "accounts/profile.html") + + +def create_account(request): + form = UserCreationForm() + + if request.method == "POST": + form = UserCreationForm(request.POST) + + if form.is_valid(): + form.save() + + user = authenticate(username=form.cleaned_data["username"], + password=form.cleaned_data["password1"]) + login(request, user) + + return redirect("account:profile") + + return render(request, "accounts/create.html", { + "form": form, + }) -- cgit v1.2.3