Beispiel #1
0
        def wrapper(view_set, request, *args, **kw):
            token = request.META.get('HTTP_AUTHORIZATION')
            jwt_object = JwtToken()
            user = jwt_object.get_info(token)
            request.dmp_user = user
            if user["is_active"] != 1:
                raise AuthFailedException()
            if user["is_admin"] != 1:
                from DMP.Business.Service.UserService import UserService
                UserService.has_permissions(user["id"], perms)

            return func(view_set, request, *args, **kw)
Beispiel #2
0
 def login(self, request):
     if "account" not in request.data:
         raise ValidationException(10002)
     if "password" not in request.data:
         raise ValidationException(10003)
     token = UserService.login(request.data['account'],
                               request.data['password'])
     return Response(return_format(200), headers={'Authorization': token})
Beispiel #3
0
 def create(cls, **kwargs):
     """
     创建
     :param kwargs:
     :return:
     """
     try:
         with transaction.atomic('BusinessMysql'):
             serializer = BusinessSerializer(data=kwargs)
             if serializer.is_valid():
                 business = serializer.save()
                 UserService.create_admin_user(business.email, business.id)
                 return business.id
             else:
                 raise ValidationException(detail=serializer.errors)
     except ValidationException:
         raise
     except IntegrityError:
         raise
Beispiel #4
0
 def create(self, request):
     business_id = request.dmp_user['business_id']
     if "department_ids" not in request.data:
         raise ValidationException()
     if type(request.data["department_ids"]) != list:
         raise ValidationException(10007)
     if "role_ids" not in request.data:
         raise ValidationException()
     if type(request.data["role_ids"]) != list:
         raise ValidationException(10007)
     user_id = UserService.create_user(**request.data, business=business_id)
     return Response(return_format(200, data={"id": user_id}))
Beispiel #5
0
 def update(self, request, pk=None):
     business_id = request.dmp_user['business_id']
     UserService.update(pk, business_id, **request.data)
     return Response(return_format(200))
Beispiel #6
0
 def retrieve(self, request, pk=None):
     business_id = request.dmp_user['business_id']
     data = UserService.detail(pk, business_id)
     return Response(return_format(200, data=data))
Beispiel #7
0
 def list(self, request):
     business_id = request.dmp_user['business_id']
     page_paginate = PagePaginate(request)
     result = UserService.list(business_id, page_paginate.page,
                               page_paginate.page_size)
     return Response(return_format(200, data=result))