text: from django.http import HttpResponseRedirect
  from django.contrib.auth import logout as auth_logout
  from django.contrib.auth.decorators import login_required
  from django.template import RequestContext
  from django.shortcuts import render_to_response, redirect
  from django.contrib.messages.api import get_messages
  
  from social_auth import __version__ as version
  
  
  def home(request):
      """Home view, displays login mechanism"""
      if request.user.is_authenticated():
          return HttpResponseRedirect('done')
      else:
          return render_to_response('home.html', {'version': version},
                                    RequestContext(request))
  
  
  @login_required
  def done(request):
      """Login complete view, displays user data"""
      ctx = {
          'version': version,
          'last_login': request.session.get('social_auth_last_login_backend')
      }
      return render_to_response('done.html', ctx, RequestContext(request))
  
  
  def error(request):
      """Error view"""
      messages = get_messages(request)
      return render_to_response('error.html', {'version': version,
                                               'messages': messages},
                                RequestContext(request))
  
  
  def logout(request):
      """Logs out user"""
      auth_logout(request)
      return HttpResponseRedirect('/')
  
  
  def form(request):
      if request.method == 'POST' and request.POST.get('username'):
          request.session['saved_username'] = request.POST['username']
          backend = request.session['partial_pipeline']['backend']
          return redirect('socialauth_complete', backend=backend)
      return render_to_response('form.html', {}, RequestContext(request))
  
  
  def form2(request):
      if request.method == 'POST' and request.POST.get('first_name'):
          request.session['saved_first_name'] = request.POST['first_name']
          backend = request.session['partial_pipeline']['backend']
          return redirect('socialauth_complete', backend=backend)
      return render_to_response('form2.html', {}, RequestContext(request))
  
  
  def close_login_popup(request):
      return render_to_response('close_popup.html', {}, RequestContext(request))
  