Skip to content

Instantly share code, notes, and snippets.

@pydanny
Created July 25, 2011 20:18
Show Gist options
  • Select an option

  • Save pydanny/1105082 to your computer and use it in GitHub Desktop.

Select an option

Save pydanny/1105082 to your computer and use it in GitHub Desktop.
from django.contrib.auth import authenticate, login
def signup(request, template_name="accounts/signup.html"):
form = SignupForm(request.POST or None)
if form.is_valid():
user = User.objects.create_user(
username=request.POST.get('username'),
first_name=request.POST.get('first_name'),
last_name=request.POST.get('last_name'),
#... (password, email, etc)
)
user.save()
user = authenticate(username=username, password=password)
if user is not None and user.is_active:
profile = Profile.object.create(
user=user,
... (profile sutff here)
)
login(request, user)
return HttpResponseRedirect(reverse("signup_complete"))
else:
# go to page saying they suck or soemthing
return render_to_response(template_name, {
"form": form,
},
context_instance=RequestContext(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment