def token_list(self, request, **kwargs): self.method_check(request, allowed=['get']) data = [] dummy_data = {} my_auth = MyBasicAuthentication() es_check = my_auth.is_authenticated(request, **kwargs) if es_check: param = { 'token': es_check['t'], 'operator': es_check['u'] } res = BackendRequest.get_domain(param) if res['result']: for t in res['domain']['token']: data.append({ 'token': t, "description": "", "created": res['domain']['create_time'] * 1000, "edit": "false" }) dummy_data["status"] = "1" dummy_data["totle"] = len(data) dummy_data["list"] = data else: dummy_data = err_data.build_error(res) else: data = err_data.build_error({}, "auth error!") data["location"] = "/auth/login/" dummy_data = data bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request) response_data = bundle resp = self.create_response(request, response_data) return resp
def token_retired_list(self, request, **kwargs): self.method_check(request, allowed=['get']) data = [ {"token": "01234kjhasak12j3l4lh3jh41lkh322j315kph12vasd", "description": "ddd", "created": "20140706", "edit": "false"}, {"token": "31aaagghk12j3l4lh12k3jh41lkh322j315kph12vasd", "description": "ssssss", "created": "20140706", "edit": "false"}, {"token": "aasdkvocinwj3l4lh12k3jh41lkh322j315kph12vasd", "description": "afffdsfadds", "created": "20140706", "edit": "false"} ] dummy_data = {} my_auth = MyBasicAuthentication() es_check = my_auth.is_authenticated(request, **kwargs) if es_check: param = { 'token': es_check['t'], 'operator': es_check['u'] } res = BackendRequest.get_domain(param) if res['result']: list = [] for a_domain in res['domain']: list.append({ 'token': a_domain['token'], 'created': a_domain['create_time'] * 1000 }) data = res['domain']['token'] dummy_data["status"] = "1" dummy_data["totle"] = len(data) dummy_data["list"] = list else: dummy_data = err_data.build_error(res) else: data = err_data.build_error({}, "auth error!") data["location"] = "/auth/login/" dummy_data = data bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request) response_data = bundle resp = self.create_response(request, response_data) return resp
def usage(request, **kwargs): my_auth = MyBasicAuthentication() is_login = my_auth.is_authenticated(request, **kwargs) domain_name = request.META.get('HTTP_HOST').split('.')[0] if is_login: visit_permit = BackendRequest.can_visit({ "token": is_login['t'], "operator": is_login['u'], "requestUrl": request.path[1:] }) if visit_permit['result'] and visit_permit['can_visit']: domain_info = BackendRequest.get_domain({'token': is_login['t']}) if domain_info['result']: info_detail = domain_info.get('domain', {'limit_quota': -1}) return_limit = info_detail.get('limit_quota', limit) # if not return_limit or return_limit < 0: # return_limit = limit token_limit = return_limit if return_limit == -1 else float( return_limit) / 1024 / 1024 result_hash = { "user": is_login["u"], "userid": is_login["i"], "role": is_login["r"], "timeline_color": timeline_color, "info": { "limit": token_limit, "retention": retention } } if release_type == 'SaaS': validated_orders = [] for o in list( Order.objects.filter( status='validated', domain_name=domain_name).order_by( '-create_time')): validated_orders.append({ 'end_day': o.pre_expire_time, 'start_day': o.validate_time, 'volume': utility.mb_to_gb(o.volume), 'price': o.charge, 'order_id': o.order_id(), 'create_day': o.create_time }) other_orders = [] for o in Order.objects.filter( Q(status='init') | Q(status='paid'), domain_name=domain_name).order_by('-create_time'): status_str = "" if o.status == 'init' or o.status == 'paid': status_str = '待处理' if o.status == 'expired': status_str = '已失效' other_orders.append({ 'end_day': o.pre_expire_time, 'start_day': o.pre_validate_time, 'volume': utility.mb_to_gb(o.volume), 'price': o.charge, 'order_id': o.order_id(), 'status': status_str, 'create_day': o.create_time }) result_hash["validated_orders"] = validated_orders result_hash["other_orders"] = other_orders page_data = result_hash return render(request, 'account/usage.html', {"page_data": json.dumps(page_data)}) else: return HttpResponseRedirect('/auth/login/') else: raise PermissionDenied else: return HttpResponseRedirect('/auth/login/')