示例#1
0
文件: user.py 项目: Pancho2wang/wapp
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     try:
         obj = User()
         if param.get('account'):
             obj.account = param.get('account')
         if param.get('password'):
             obj.password = param.get('password')
         if param.get('name'):
             obj.name = param.get('name')
         if param.get('status'):
             obj.status = param.get('status')
         if param.get('user_type'):
             obj.user_type = param.get('user_type')
         obj.save()
         if param.get('companys'):
             cIds = ','.join(str(s) for s in param.get('companys'))
             obj.companys.set(
                 Company.objects.extra(where=['id IN (' + cIds + ')']))
         else:
             obj.companys.clear()
         if param.get('roles'):
             rIds = ','.join(str(s) for s in param.get('roles'))
             obj.roles.set(
                 Role.objects.extra(where=['id IN (' + rIds + ')']))
         else:
             obj.roles.clear()
         obj.save()
     except:
         return JsonResponse(Message.success(301, None, '新增失败!'))
     return JsonResponse(Message.success(200, None, '新增成功!'))
示例#2
0
 def post(self,request,*args,**kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     try:
         # Role.objects.create(**param)
         obj = Role()
         if param.get('name'):
             obj.name = param.get('name')
         if param.get('seq'):
             obj.seq = param.get('seq')
         if param.get('alias_name'):
             obj.alias_name = param.get('alias_name')
         if param.get('status'):
             obj.status = param.get('status')
         if param.get('is_all_sql_auth'):
             obj.is_all_sql_auth = param.get('is_all_sql_auth')
         if param.get('desc'):
             obj.desc = param.get('desc')
         obj.save()
         if param.get('resources'):
             rIds = ','.join(str(s) for s in param.get('resources'))
             obj.resources.set(Resource.objects.extra(where=['id IN ('+ rIds +')']))
         else:
             obj.resources.clear()
         if param.get('sql_resources'):
             sIds = ','.join(str(s) for s in param.get('sql_resources'))
             obj.sql_resources.set(SQLResource.objects.extra(where=['id IN ('+ sIds +')']))
         else:
             obj.sql_resources.clear()
         obj.save()
     except:
         return JsonResponse(Message.success(301, None, '新增失败!'))
     return JsonResponse(Message.success(200, None, '新增成功!'))
示例#3
0
文件: index.py 项目: Pancho2wang/wapp
 def post(self,request):
     '''
     接收用户名和密码
     :param request:
     :return:
     '''
     param = json.loads(request.body)
     account = param.get('account')
     pwd = param.get('password')
     print(account,pwd)
     obj = User.objects.filter(account=account,password=pwd,enabled=1,status=1).first()
     if not obj:
         return JsonResponse(Message.error(400, '用户名或者密码错误'))
     #创建随机字符串
     ctime = time.time()
     key = '%s|%s'%(account,ctime)
     m = hashlib.md5()
     m.update(key.encode('utf-8'))
     token = m.hexdigest()
     loginObj = LoginStatus.objects.filter(user_id = obj.id).first()
     if not loginObj:
         LoginStatus.objects.create(user_id = obj.id, token = token)
     else:
         loginObj.token = token
         loginObj.status = 1
         loginObj.save()
     return JsonResponse(Message.success(200, token, '登录成功'))
示例#4
0
 def post(self,request,*args,**kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     cid = param.get('id')
     if not cid:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     try:
         # data = Role.objects.get(pk=cid)
         obj = Role.objects.get(pk=cid,enabled=1)
         resourceList = obj.resources.filter(enabled=1).values('id')
         resources = []
         for resource in resourceList:
             resources.append(resource['id'])
         sqlResourceList = obj.sql_resources.filter(enabled=1).values('id')
         sqlResources = []
         for sqlResource in sqlResourceList:
             sqlResources.append(sqlResource['id'])
         data = model_to_dict(obj)
         data['resources'] = resources
         data['sql_resources'] = sqlResources
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '获取失败!'))
     return JsonResponse(Message.success(200, data, '获取成功!'))
示例#5
0
 def post(self,request,*args,**kwargs):
     print('token', request.user)
     print('user', request.auth)
     page = PageConfig['page']
     pageSize = PageConfig['pageSize']
     name = ''
     if request.body:
         param = json.loads(request.body)   
         if param.get('page'):
             page = param.get('page')
         if param.get('pageSize'):
             pageSize = param.get('pageSize')
         if param.get('name'):
             name = param.get('name')
     try:
         data = Role.objects.filter(enabled=1, name__contains=name).values('id','name','seq','status','alias_name','is_all_sql_auth','create_time').order_by('seq')
         paginator = Paginator(data, pageSize)
         total = paginator.count
         roles = paginator.page(page)
         # total = Role.objects.filter(enabled=1).count()
         # data = Role.objects.filter(enabled=1).values('id','name','seq','status','alias_name','is_all_sql_auth','create_time').order_by('seq')[((page - 1) * pageSize):pageSize]
     except PageNotAnInteger:
         roles = paginator.page(1) 
     except EmptyPage:
         roles = paginator.page(paginator.num_pages)
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '获取列表失败!'))
     return JsonResponse(Message.success(200, {'list': list(roles), 'total': total}, '获取列表成功!'))
示例#6
0
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     cid = param.get('id')
     if not cid:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     try:
         obj = SQLResource.objects.get(pk=cid)
         if param.get('name'):
             obj.name = param.get('name')
         if param.get('seq'):
             obj.seq = param.get('seq')
         if param.get('status'):
             obj.status = param.get('status')
         if param.get('sql_id'):
             obj.sql_id = param.get('sql_id')
         if param.get('desc'):
             obj.desc = param.get('desc')
         if param.get('sql_script'):
             obj.desc = param.get('desc')
         obj.save()
     except:
         return JsonResponse(Message.success(301, None, '更新失败!'))
     return JsonResponse(Message.success(200, None, '更新成功!'))
示例#7
0
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     try:
         obj = Resource()
         if param.get('name'):
             obj.name = param.get('name')
         if param.get('seq'):
             obj.seq = param.get('seq')
         if param.get('status'):
             obj.status = param.get('status')
         if param.get('pid'):
             obj.pid = Resource.objects.get(pk=param.get('pid'))
         if param.get('per_type'):
             obj.per_type = param.get('per_type')
         if param.get('url'):
             obj.url = param.get('url')
         if param.get('icon'):
             obj.icon = param.get('icon')
         if param.get('desc'):
             obj.desc = param.get('desc')
         obj.save()
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '新增失败!'))
     return JsonResponse(Message.success(200, None, '新增成功!'))
示例#8
0
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     try:
         SQLResource.objects.create(**param)
     except:
         return JsonResponse(Message.success(301, None, '新增失败!'))
     return JsonResponse(Message.success(200, None, '新增成功!'))
示例#9
0
 def post(self,request,*args,**kwargs):
     print('token', request.user)
     print('user', request.auth)
     try:
         data = Role.objects.filter(enabled=1).values('id','name','seq','status','alias_name').order_by('seq')
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '获取列表失败!'))
     return JsonResponse(Message.success(200, {'list': list(data)}, '获取列表成功!'))
示例#10
0
 def post(self, request, *args, **kwargs):
     print('token', request.user)
     print('user', request.auth)
     try:
         data = Resource.objects.filter(enabled=1).values(
             'id', 'name', 'pid').order_by('seq')
         data = dataChangeToTree(list(data))
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '获取列表失败!'))
     return JsonResponse(Message.success(200, {'list': data}, '获取列表成功!'))
示例#11
0
文件: index.py 项目: Pancho2wang/wapp
 def post(self,request):
     '''
     接收用户名和密码
     :param request:
     :return:
     '''
     token = request.META.get("HTTP_TOKEN")
     obj = LoginStatus.objects.filter(token=token, status=1).first()
     if not obj:
         return JsonResponse(Message.error(300, None, '登出失败'))
     obj.status = 0
     obj.save()
     return JsonResponse(Message.success(200, None, '登出成功'))
示例#12
0
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     cid = param.get('id')
     if not cid:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     try:
         data = SQLResource.objects.get(pk=cid, enabled=1)
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '获取失败!'))
     return JsonResponse(Message.success(200, model_to_dict(data), '获取成功!'))
示例#13
0
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     ids = param.get('ids')
     if not ids:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     try:
         idstr = ','.join(str(s) for s in ids)
         SQLResource.objects.extra(where=['id IN (' + idstr +
                                          ')']).update(enabled=0)
     except:
         return JsonResponse(Message.success(301, None, '删除失败!'))
     return JsonResponse(Message.success(200, None, '删除成功!'))
示例#14
0
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     cid = param.get('id')
     if not cid:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     try:
         obj = Resource.objects.get(pk=cid)
         obj.enabled = 0
         obj.save()
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '删除失败!'))
     return JsonResponse(Message.success(200, None, '删除成功!'))
示例#15
0
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     cid = param.get('id')
     if not cid:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     try:
         data = Resource.objects.filter(pk=cid, enabled=1).values(
             'id', 'pid', 'name', 'seq', 'status', 'per_type', 'url',
             'icon', 'desc').first()
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '获取失败!'))
     # return JsonResponse(Message.success(200, model_to_dict(data), '获取成功!'))
     return JsonResponse(Message.success(200, data, '获取成功!'))
示例#16
0
文件: user.py 项目: Pancho2wang/wapp
 def post(self, request, *args, **kwargs):
     if not request.body:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     param = json.loads(request.body)
     cid = param.get('id')
     if not cid:
         return JsonResponse(Message.success(402, None, '请求入参不正确!'))
     try:
         obj = User.objects.get(pk=cid, enabled=1)
         roleList = obj.roles.filter(enabled=1).values('id')
         roles = []
         for role in roleList:
             roles.append(role['id'])
         companyList = obj.companys.filter(enabled=1).values('id')
         companys = []
         for company in companyList:
             companys.append(company['id'])
         data = model_to_dict(obj)
         data['roles'] = roles
         data['companys'] = companys
     except Exception as e:
         print(e)
         return JsonResponse(Message.success(301, None, '获取失败!'))
     return JsonResponse(Message.success(200, data, '获取成功!'))
示例#17
0
文件: index.py 项目: Pancho2wang/wapp
 def get(self, request):
     return JsonResponse(Message.success(200, None, '后台系统欢迎您!'))
示例#18
0
def w_exception_handler(exc,context):
    response = exception_handler(exc, context) #获取本来应该返回的exception的response 
    if response is not None:
      response.data = Message.error(401, response.data['detail'])
      # del response.data['detail']  #删掉原来的detail
    return response