Created
May 2, 2013 04:26
-
-
Save marti1125/5500141 to your computer and use it in GitHub Desktop.
register metho
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
@allow_public | |
def register(request): | |
"""Registers Users. | |
Pulls out an invite code if it exists and auto validates the user | |
if so. Single-purpose view. | |
""" | |
if 'code' in request.GET: | |
request.session['invite-code'] = request.GET['code'] | |
return redirect('home') | |
if request.user.is_authenticated(): | |
return redirect(reverse('profile', args=[request.user.username])) | |
authenticated_email = request.session.get('authenticated_email') | |
if not authenticated_email: | |
log.error('Browserid registration, but no verified email in session') | |
return redirect('home') | |
user = auth.authenticate(authenticated_email=authenticated_email) | |
if not user: | |
return redirect('home') | |
user_form = UserForm(request.POST or None, instance=user) | |
profile_form = RegisterForm(request.POST or None, | |
instance=user.get_profile()) | |
if request.method == 'POST': | |
if (user_form.is_valid() and profile_form.is_valid()): | |
user_form.save() | |
profile_form.save() | |
auth.login(request, user) | |
_update_invites(request) | |
messages.info(request, _(u'Your account has been created.')) | |
return redirect(reverse('profile', args=[request.user.username])) | |
# 'user' object must be passed in because we are not logged in | |
return render(request, 'registration/register.html', | |
dict(profile_form=profile_form, | |
user_form=user_form, | |
edit_form_action=reverse('register'), | |
mode='new', | |
profile=user.get_profile(), | |
user=user, | |
)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment