def sign_in(req): if req.method == 'GET': if req.user.is_authenticated(): return HttpResponseRedirect(reverse('dashboard')) p = {} p.update(csrf(req)) return render_to_response(TEMPLATE_PATH + 'signin.html', p, context_instance=RequestContext(req)) elif req.method == 'POST': username = req.POST.get('username', '') password = req.POST.get('password', '') user = authenticate(username=username, password=password) if user is None: return _json_response('Invalid sign in.') elif user.is_active: login(req, user) return _json_response({'redirect': reverse('dashboard')}) else: return _json_response("failure")
def homepage_counter(req): if req.method == 'POST': if req.POST.get('handshake').strip() == settings.STATS_SECRET_KEY: proj = get_object_or_404(Project, name=req.POST.get('deployment_key')) ac = AppCounter() try: ac = AppCounter.objects.get(app=proj) ac.counter = ac.counter + 1 except ObjectDoesNotExist as dne: ac.app = proj ac.counter = 1 ac.save() return _json_response('ok')