Created
April 22, 2011 20:57
-
-
Save jpadilla/937626 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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