Exemplo n.º 1
0
    def get(self, request):
        if self.discourse_username:
            return redirect(request.GET.get('next', '/'))

        form = LoginForm()
        form.initial['next'] = request.GET.get('next', '/')

        return self.render_to_response({'form': form})
Exemplo n.º 2
0
    def post(self, request):
        if self.discourse_username:
            return redirect(request.GET.get('next', '/'))

        form = LoginForm(request.POST)

        if form.is_valid():
            # authenticated
            request.session['discourse_username'] = form.discourse_username
            messages.info(request, 'Welcome back %s' % form.discourse_username)
            return redirect(form.cleaned_data['next'] or '/')

        return self.render_to_response({'form': form})