Beispiel #1
0
def login_user(request, next='/'):

    #message = None
    if request.is_ajax():
        pass
    else:
    	if request.POST:
			login_form = LoginForm(request.POST, initial={'next':next})
			if login_form.is_valid():
				u = login_form.cleaned_data['username']
				p = login_form.cleaned_data['password']
				the_user = authenticate(username=u, password=p)
				if the_user is not None and the_user.is_active:
					login(request, the_user)
					if request.GET:
						redir = request.GET['next']
					else:
						redir = '/'
					return HttpResponseRedirect(redir)
				else:
					message = "password and username did not match"
					form = LoginForm(request.POST, initial={'next':next})
					return render_to_response('base/login.html', {'form':form}, context_instance=RequestContext(request))
        else:
			login_form = LoginForm(initial={'next':request.META.get('HTTP_REFERER') or '/'})
			return render_to_response('base/login.html', {'form':login_form}, context_instance=RequestContext(request))
Beispiel #2
0
def ajax_login(request):
    # POSTs done by Request.JSON
    if request.POST:
        form = LoginForm(request.POST)
        if form.is_valid():
            user = auth.authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])
            # we have a winner
            if user is not None and user.is_active:
                auth.login(request, user)
                try:
                    #p =  user.get_profile()
                    return HttpResponse(simplejson.dumps({'user':True, 'location':request.META['HTTP_REFERER']}), mimetype="application/javascript")
                except:
                    return HttpResponse(simplejson.dumps({'user':True, 'location':user.get_profile().get_absolute_url()}), mimetype="application/javascript")
            else:
                return HttpResponse(simplejson.dumps({'user':False, 'msg':"Username & Password do not match"}), mimetype="application/javascript")

        else:
            return HttpResponse(simplejson.dumps({'user':False, 'msg':"Username & Password do not match"}), mimetype="application/javascript")
    # GETs done by Request.HTML
    else:
        form = LoginForm()
        return HttpResponse(form.as_ul())
Beispiel #3
0
def ajax_login(request):
    # POSTs done by Request.JSON
    if request.POST:
        form = LoginForm(request.POST)
        if form.is_valid():
            user = auth.authenticate(username=form.cleaned_data['username'],
                                     password=form.cleaned_data['password'])
            # we have a winner
            if user is not None and user.is_active:
                auth.login(request, user)
                try:
                    #p =  user.get_profile()
                    return HttpResponse(simplejson.dumps({
                        'user':
                        True,
                        'location':
                        request.META['HTTP_REFERER']
                    }),
                                        mimetype="application/javascript")
                except:
                    return HttpResponse(simplejson.dumps({
                        'user':
                        True,
                        'location':
                        user.get_profile().get_absolute_url()
                    }),
                                        mimetype="application/javascript")
            else:
                return HttpResponse(simplejson.dumps({
                    'user':
                    False,
                    'msg':
                    "Username & Password do not match"
                }),
                                    mimetype="application/javascript")

        else:
            return HttpResponse(simplejson.dumps({
                'user':
                False,
                'msg':
                "Username & Password do not match"
            }),
                                mimetype="application/javascript")
    # GETs done by Request.HTML
    else:
        form = LoginForm()
        return HttpResponse(form.as_ul())