def register(request, template=None, next_url=None):
    action_url = '.'

    try:
        if request.REQUEST['next_url']:
            next_url = request.REQUEST['next_url']
            action_url = '%s?next_url=%s' % (action_url, next_url)
    except:
        pass
        
    if 'user' in request.session.keys():
        # Redirect the user to the next desired page or to the site's root
        if next_url:
            return HttpResponseRedirect(next_url)
        else:
            return HttpResponseRedirect('/')
            
    # Handle a submitted form
    if request.method == "POST":
        form = UserForm(request.POST)
        
        # If all of the user's submission validates, they are registered.
        # Otherwise Django's forms library and the template will provide the
        # user with feedback.
        if form.is_valid():
            # Load the form data into a User object
            user = form.save(commit=False)
            clear_password = user.password
            
            # Set the users hashed password and save the user
            user.set_password(clear_password)
            user.put()
            
            # Log the user in
            user.login(email=user.email, password=clear_password, request=request)
            
            # Redirect the user to the next desired page or to the site's root
            if next_url:
                return HttpResponseRedirect(next_url)
            else:
                return HttpResponseRedirect('/')
                
    # Handle a request for the page
    else:
        form = UserForm()
        
    c = RequestContext(request, {
        'form':form,
        'action_url':action_url,
    })
    
    if template is None:
        template = 'register.html'
    
    return render_to_response(template, c)
dataset/ETHPy150Open bgolub/fftogo/django_ae_utils/auth/views.py/register/original