예제 #1
0
def login_view(request):
    """Login view
    """
    if request.POST:
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = authenticate(username=data['username'],
                                password=data['password'])
            if user is not None and user.is_active:
                login(request, user)
                if user.bands.count():
                    band = user.bands.all()[0]
                    Band.set_active_band(request, band)
                url = request.GET.get('next', reverse('section_home'))
                return HttpResponseRedirect(url)
    else:
        form = AuthenticationForm()
    c = {'form': form, 'next': request.GET.get('next')}
    c = RequestContext(request, c)
    return render_to_response("auth/login.html", c)