Ejemplo n.º 1
0
def register(request):
    """Create the user or render the approriate form.

    Users are created without any permissions.

    """
    if request.user.is_authenticated():
        return redirect("blackem.users.views.home")
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect("blackem.users.views.home")
    else:
        form = RegistrationForm()
    return render_to_response(
        "users/user_form.html", {"form": form, "logged": False}, context_instance=RequestContext(request)
    )
Ejemplo n.º 2
0
def register(request):
    """Use a RegistrationForm to render a form that can be used to register a
    new user. If there is POST data, the user has tried to submit data.
    Therefore, validate and either redirect (success) or reload with errors
    (failure). Otherwise, load a blank creation form.
    """
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            # @NOTE This can go in once I'm using the messages framework.
            # messages.info(request, "Thank you for registering! You are now logged in.")
            new_user = authenticate(username=request.POST['username'], 
                password=request.POST['password1'])
            login(request, new_user)
            return HttpResponseRedirect(reverse('build_world:home'))
    else:
        form = RegistrationForm()
    # By now, the form is either invalid, or a blank for is rendered. If
    # invalid, the form will sent errors to render and the old POST data.
    return render_to_response('registration/join.html', { 'form':form }, 
        context_instance=RequestContext(request))