Skip to content

Instantly share code, notes, and snippets.

@jpadilla
Created April 22, 2011 20:57
Show Gist options
  • Save jpadilla/937626 to your computer and use it in GitHub Desktop.
Save jpadilla/937626 to your computer and use it in GitHub Desktop.
def register(self, request, **kwargs):
"""
Create and immediately log in a new user.
"""
username, email, password, first_name, last_name = kwargs['username'], kwargs['email'], \
kwargs['password1'], kwargs['first_name'], kwargs['last_name']
create_user = User.objects.create_user(username, email, password)
create_user.first_name = first_name
create_user.last_name = last_name
create_user.save()
# authenticate() always has to be called before login(), and
# will return the user we just created.
new_user = authenticate(username=username, password=password)
login(request, new_user)
signals.user_registered.send(sender=self.__class__,
user=new_user,
request=request)
return new_user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment