コード例 #1
0
 def set_password(self, request, pk=None):
     perms = UserInfoView.get_permission_from_role(request)
     user = UserProfile.objects.get(id=pk)
     if 'admin' in perms or 'user_all' in perms or request.user.is_superuser:
         new_password1 = request.data['new_password1']
         new_password2 = request.data['new_password2']
         if new_password1 == new_password2:
             user.set_password(new_password2)
             user.save()
             return XopsResponse('密码修改成功!')
         else:
             return XopsResponse('新密码两次输入不一致!',
                                 status=status.HTTP_400_BAD_REQUEST)
     else:
         old_password = request.data['old_password']
         if check_password(old_password, user.password):
             new_password1 = request.data['new_password1']
             new_password2 = request.data['new_password2']
             if new_password1 == new_password2:
                 user.set_password(new_password2)
                 user.save()
                 return XopsResponse('密码修改成功!')
             else:
                 return XopsResponse('新密码两次输入不一致!',
                                     status=status.HTTP_400_BAD_REQUEST)
         else:
             return XopsResponse('旧密码错误!',
                                 status=status.HTTP_400_BAD_REQUEST)
コード例 #2
0
    def post(self, request):
        """
        post:
        发送信息到指定人员邮箱
        参数列表:

            username:用户名
            password:密码

        """
        username = request.data.get('username')
        password = request.data.get('password')
        print(username)
        print(password)
        user = authenticate(username=username, password=password)
        if user:
            payload = jwt_payload_handler(user)
            return XopsResponse(
                {
                    'token': jwt.encode(payload, SECRET_KEY),
                    'username': username
                },
                status=OK,
            )
        else:
            return XopsResponse('用户名或密码错误!', status=BAD)
コード例 #3
0
 def get(self, request):
     """
     get:
         获取所有组织结构数据,重组结构
     """
     if request.user.id is not None:
         org_data = self.get_all_org(request)
         return XopsResponse(org_data)
     else:
         return XopsResponse('请登录后访问!')
コード例 #4
0
 def get(self, request):
     """
     get:
     获取所有菜单数据,重组结构
     """
     if request.user.id is not None:
         menu_data = self.get_all_menus(request)
         return XopsResponse(menu_data, status=OK)
     else:
         return XopsResponse('请登录后访问!', status=FORBIDDEN)
コード例 #5
0
 def create(self, request, *args, **kwargs):
     # 创建用户默认添加密码
     data = request.data.copy()
     print(data)
     data['password'] = '******'
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     self.perform_create(serializer)
     headers = self.get_success_headers(serializer.data)
     return XopsResponse(serializer.data, status=CREATED, headers=headers)
コード例 #6
0
    def get(self, request):
        """
        get:
        发送信息到指定人员邮箱
        参数列表:

            id:用户id
            username:用户名
            avatar:头像接口
            email:邮件
            is_active:是否激活
            createTime:创建时间
            position: 职位
            roles:角色

        """
        # print("dd"+str(request.version))
        # print(request._request)
        # request._full_data = "dd"
        # print(request.data)
        # print(request.negotiator)
        # print(request.data)
        # print(request.FILES)
        # url = request.versioning_scheme.reverse(viewname='user_info', request=request)
        # print(url)
        if request.user.id is not None:
            perms = self.get_permission_from_role(request)
            org = self.get_department_from_organization(request)

            data = {
                'id': request.user.id,
                'username': request.user.username,
                'email': request.user.email,
                'is_active': request.user.is_active,
                'createTime': request.user.date_joined,
                'department': org,
                'position': request.user.position,
                'roles': perms,
            }
            return XopsResponse(data, status=OK)
        else:
            return XopsResponse('请登录后访问!', status=FORBIDDEN)
コード例 #7
0
 def destroy(self, request, *args, **kwargs):
     # 删除用户时删除其他表关联的用户
     instance = self.get_object()
     id = str(kwargs['pk'])
     # projects = Project.objects.filter(
     #     Q(user_id__icontains=id + ',') | Q(user_id__in=id) | Q(user_id__endswith=',' + id)).values()
     # if projects:
     #     for project in projects:
     #         user_id = project['user_id'].split(',')
     #         user_id.remove(id)
     #         user_id = ','.join(user_id)
     # Project.objects.filter(id=project['id']).update(user_id=user_id)
     # ConnectionInfo.objects.filter(uid_id=id).delete()
     self.perform_destroy(instance)
     return XopsResponse(status=NO_CONTENT)
コード例 #8
0
    def get(self, request, format=None):
        organizations = Organization.objects.all()
        serializer = OrganizationUserTreeSerializer(organizations, many=True)
        org_list = self.get_department_from_organization(request)

        tree_dict = {}
        tree_data = []
        for item in serializer.data:
            new_item = {
                'id': str(item['id']),
                'name': item['name'],
                'pid': item['pid'],
                'children': item['children']
            }
            tree_dict[item['id']] = new_item
        for i in tree_dict:
            if tree_dict[i]['pid']:
                pid = tree_dict[i]['pid']
                parent = tree_dict[pid]
                parent['children'].append(tree_dict[i])
            else:
                tree_data.append(tree_dict[i])

        return XopsResponse(tree_data)