⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aclintf.pas

📁 ACL权限控制软件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
begin
   exist_id := false;
   a := TStrings.Create;
   userlist := TXMLDocument.Create(nil);
   userlist.LoadFromFile(Filename);
   userlist.Active := true;
   i := 0;
   while i<userlist.ChildNodes.Count do
     begin
        subnode := userlist.ChildNodes.Nodes[i];
        if subnode.ChildNodes.FindNode('ID').Text = UserId then
          begin
             exist_id := true;
             if subnode.ChildNodes.FindNode('PASSWORD').Text = Password then
               break
             else
               begin
                  a.Add('密码错误!');
                  result := a;
                  exit;
               end;
          end;
        Inc(i);
     end;
   if not exist_id then
     begin
        a.Add('用户名不存在!');
        result := a;
        exit;
     end;
   i := 3;
   while i<subnode.ChildNodes.Count do
     begin
        grandnode := subnode.ChildNodes.Nodes[i];
        if grandnode.Attributes['access'] = 'True' then
           a.Add(grandnode.Attributes['id']);
        Inc(i);
     end;
   userlist.active := false;
   result := a;
   FreeAndNil(a);
end;

function TACLSeriveceIntf.GetReadPermission(FileName: DOMString;RoleId: String): TStrings;
var
   a: TStrings;
   rolelist: IXMLDocument;
   subnode,grandnode: IXMLNode;
   i: integer;
begin
   a := TStrings.Create;
   a := nil;
   rolelist := TXMLDocument.Create(nil);
   rolelist.LoadFromFile(Filename);
   rolelist.active := true;
   i := 0;
   while i<rolelist.ChildNodes.Count do
     begin
        subnode := rolelist.ChildNodes.Nodes[i];
        if subnode.Attributes['id'] = RoleId then
          break;
        Inc(i);
     end;
   i := 0;
   while i<subnode.ChildNodes.Count do
     begin
        grandnode := subnode.ChildNodes.Nodes[i];
        if grandnode.ChildNodes.FindNode('read').Text = 'True' then
        a.Add(grandnode.ChildNodes.FindNode('code').Text);
        Inc(i);
     end;
   rolelist.active := false;
   if a = nil then
     begin
        result := nil;
        exit;
     end;
   result := a;
   FreeAndNil(a);
end;

function TACLSeriveceIntf.GetWritePermission(FileName: DOMString;RoleId: String): TStrings;
var
   a: TStrings;
   rolelist: IXMLDocument;
   subnode,grandnode: IXMLNode;
   i: integer;
begin
   a := TStrings.Create;
   a := nil;
   rolelist := TXMLDocument.Create(nil);
   rolelist.LoadFromFile(Filename);
   rolelist.active := true;
   i := 0;
   while i<rolelist.ChildNodes.Count do
     begin
        subnode := rolelist.ChildNodes.Nodes[i];
        if subnode.Attributes['id'] = RoleId then
          break;
        Inc(i);
     end;
   i := 0;
   while i<subnode.ChildNodes.Count do
     begin
        grandnode := subnode.ChildNodes.Nodes[i];
        if grandnode.ChildNodes.FindNode('write').Text = 'True' then
        a.Add(grandnode.ChildNodes.FindNode('code').Text);
        Inc(i);
     end;
   if a = nil then
     begin
        result := nil;
        exit;
     end;
   rolelist.active := false;
   result := a;
   FreeAndNil(a);
end;

procedure TACLSeriveceIntf.NotifyStateChanged;
begin
end;

procedure TACLSeriveceIntf.AddListener(listener : TServiceListener);
begin
end;

procedure TACLSeriveceIntf.RemoveListener(listener : TServiceListener);
begin
end;

function TACLSeriveceIntf.getState : TServiceState;
begin
   result := ssRunning;
end;

function TACLSeriveceIntf.getName : String;
begin
    result := 'ACL管理器';
end;

function TACLSeriveceIntf.getDescription : String;
begin
    result := 'ACL管理器';
end;

constructor TACLSeriveceIntf.Create;
begin
end;

destructor TACLSeriveceIntf.Destroy;
begin
   inherited;
end;

//===========TCreatePermissionXML类的实现========================//

function TCreatePermissionXML.Execute(cmd : String; params : array of Const) : variant;
var
   role_result: TStrings;
   readpermission_result,writepermission_result: TStrings; //单一角色对应的权限列表
   i,j,k: integer;
   cf: boolean; //重复标记
begin
   if cmd = 'Login' then
      begin
 //====================================================//
      {role_result 有三种情况: 1:用户名不存在 2:密码错误 3: 返回正常的角色ID}

      {判断该用户是否正在使用}
      {f exist_operation(Params[0],Params[2]) then
         begin
            showmessage('该用户正在使用!');
            exit;
         end;}
     //   role_result := TStringList.Create;
       // GetRoleId('c:\userlist.xml',String(params[0].VAnsiString), String(params[1].VAnsiString));
     //   role_result.Assign(Form1.FStrings);
        //======//
        role_result := GetRoleId(FileName,String(params[0].VAnsiString), String(params[1].VAnsiString));
     //    role_result.Assign(Form1.FStrings);

        //======//

        if role_result.Strings[0] = '用户名不存在!'  then
           begin
              result := '登陆失败,该用户名不存在!'
           end
        else if role_result.Strings[0] = '密码错误!' then
           result :=  '登陆失败,密码错误!'
        else
          begin
          //  readpermission_result := TStringList.Create;
          //  read_result := TStringList.Create;
             {取出该用户对应的所有角色对应的读权限}
             for i:=0 to role_result.Count-1 do
               begin
               readpermission_result := GetReadPermission(FileName,role_result.Strings[i]);
           //       readpermission_result.Assign(Form1.FStrings);
         //      showmessage(readpermission_result.Strings[1]);


               if i=0 then
                 read_result := readpermission_result;

           //      showmessage(inttostr(read_result.Count));
            //   showmessage(read_result.Strings[0]);
                  if readpermission_result <> nil then // 动态readpermission中的权限和read_result中的权限不能重复
                    begin
                       for j:=0 to readpermission_result.Count-1 do
                         begin
                            cf := false;
                            for k:=0 to read_result.Count-1 do
                              begin
                                 if read_result.Strings[k] = readpermission_result.Strings[j] then
                                    cf := true;
                              end;
                            {取出该用户对应的所有角色对应的读权限中的不重复读权限赋值给read_result}
                            if not cf then
                               read_result.Add(readpermission_result.Strings[j]);
                         end;
                    end;

               end;

            {  for i:= 0 to read_result.Count do
               begin
                  cf := false;
                  for j:= 0 to a.Count do
                    begin
                       if a[j] = read_result.Strings[i] then
                       cf := true;
                    end;
                  if not cf  then //如果新的权限和已有的权限不重复,就添加到a里
                       a.Add(read_result.Strings[i]);
               end;  }

             {取出该用户对应的所有角色对应的写权限}
             for i:=0 to role_result.Count-1 do
               begin
                  writepermission_result := GetWritePermission(FileName,role_result.Strings[i]);
                 if i=0 then
                   write_result := writepermission_result;
                  if writepermission_result <> nil then // 动态writepermission中的权限和write_result中的权限不能重复
                    begin
                       for j:=0 to writepermission_result.Count-1 do
                         begin
                            cf := false;
                            for k:=0 to write_result.Count-1 do
                              begin
                                 if write_result.Strings[k] = writepermission_result.Strings[j] then
                                    cf := true;
                              end;
                            {取出该用户对应的所有角色对应的读权限中的不重复读权限赋值给write_result}
                            if not cf then
                               write_result.Add(writepermission_result.Strings[j]);
                         end;

                    end;
               end;
           end;

       { for i:=0 to read_result.Count-1 do
        begin
          showmessage(read_result.Strings[i]);   //该用户的读权限列表
        end;
        for i:=0 to write_result.Count-1 do
        begin
          showmessage(write_result.Strings[i]); //该用户的写权限列表
        end;  }
        result := '登陆成功!';
 //====================================================//
      end
        {    result :=  登录  返回 -> 用户对应所有角色的所有权限

         else
            result := 登陆失败 返回 1:用户名正确,密码错误 2:用户名不存在 }

   else if cmd = 'Logout' then
      begin
       {  Logout(params[0]);}   //注销函数Logout(UserId)
         result := '注销成功!'
      end;
end;


function TCreatePermissionXML.GetRoleId(FileName: String;UserId,Password: String): TStrings;
var
   a: TStrings;
   userlist: IXMLDocument;
   userlistnode,subnode,grandnode: IXMLNode;
   i: integer;
   exist_id: boolean;
begin
   exist_id := false;
   a := TStringList.Create;
   userlist := TXMLDocument.Create(nil);
   userlist.LoadFromFile(Filename + '\userlist.xml');
   userlist.Active := true;
   userlistnode := userlist.DocumentElement;
   i := 0;
   while i<userlistnode.ChildNodes.Count do
     begin
        subnode := userlistnode.ChildNodes.Nodes[i];
        if subnode.ChildNodes.FindNode('ID').Text = UserId then
          begin
             exist_id := true;
             if subnode.ChildNodes.FindNode('PASSWORD').Text = Password then
               break
             else
               begin
                  a.Add('密码错误!');
                  result := a;
                  exit;
               end;
          end;
        Inc(i);
     end;
   if not exist_id then
     begin
        a.Add('用户名不存在!');
        result := a;
        exit;
     end;
   i := 3;
   while i<subnode.ChildNodes.Count do
     begin
        grandnode := subnode.ChildNodes.Nodes[i];
        if grandnode.Attributes['access'] = 'True' then
           begin
           a.Add(grandnode.Attributes['id']);
           end;
        Inc(i);
     end;
   userlist.active := false;
   result := a;
//   Form1.FStrings := result;
//   showmessage(result.Strings[1]);
  // a.Free;
end;

function TCreatePermissionXML.GetReadPermission(FileName: String;RoleId: String): TStrings;
var
   a: TStrings;
   rolelist: IXMLDocument;
   rolelistnode,subnode,grandnode: IXMLNode;
   i: integer;
begin
   a := TStringList.Create;
   rolelist := TXMLDocument.Create(nil);
   rolelist.LoadFromFile(Filename + '\rolelist.xml');
   rolelist.active := true;
   rolelistnode := rolelist.DocumentElement;
   i := 0;
   while i<rolelistnode.ChildNodes.Count do
     begin
        subnode := rolelistnode.ChildNodes.Nodes[i];
        if subnode.Attributes['id'] = RoleId then
          break;
        Inc(i);
     end;
   i := 0;
   while i<subnode.ChildNodes.Count do
     begin
        grandnode := subnode.ChildNodes.Nodes[i];
        if grandnode.ChildNodes.FindNode('read').Text = 'True' then
        begin
        // showmessage(grandnode.ChildNodes.FindNode('code').Text);
         a.Add(grandnode.ChildNodes.FindNode('code').Text);
        end;
        Inc(i);
     end;
   rolelist.active := false;
  { if a.Text = '''' then
     begin
        result := '''';
        exit;
     end;    }
   result := a;
 //  Form1.FStrings := result;
  // FreeAndNil(a);  此句加上有问题
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -