LimitCondition.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. unit LimitCondition;
  2. interface
  3. uses
  4. Classes, SysUtils, RealICQClient, RealICQModel;
  5. type
  6. TLimitCondition = class
  7. private
  8. class function GetFileSizeByMB(AFileName: string): Int64;
  9. class function GetFileSizeByKB(AFileName: string): Int64;
  10. public
  11. class function GreaterThanFaceMaxSize(AFacePath: string; var AError: string): Boolean;
  12. class function GreaterThanOfflineFileMaxSize(AFileName: string; var AError: string; ARealICQClient: TRealICQClient): Boolean;
  13. class function FirstLoginComfirm: Boolean; static;
  14. /// <summary>
  15. /// 登录用户的用户信息完整性检测
  16. /// </summary>
  17. /// <param name="AUser">当前登录用户</param>
  18. /// <returns>是否完整</returns>
  19. class function UserInfoCheck(AUser: TRealICQUser): Boolean;
  20. end;
  21. implementation
  22. uses
  23. LoggerImport, ConditionConfig, PerlRegEx, Forms, Dialogs, MainFrm;
  24. { TLimitCondition }
  25. class function TLimitCondition.GetFileSizeByKB(AFileName: string): Int64;
  26. var
  27. AFileStream: TFileStream;
  28. begin
  29. try
  30. AFileStream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
  31. Result := AFileStream.Size div 1024;
  32. except
  33. on E: Exception do
  34. begin
  35. Error('检查文件“'+AFileName+'”发生错误:' + E.Message, 'TLimitCondition.GetFileSizeByKB');
  36. Result := -1;
  37. AFileStream.Free;
  38. end;
  39. end;
  40. AFileStream.Free;
  41. end;
  42. class function TLimitCondition.GetFileSizeByMB(AFileName: string): Int64;
  43. begin
  44. Result := GetFileSizeByKB(AFileName);
  45. if Result <> -1 then
  46. Result := Result div 1024;
  47. end;
  48. class function TLimitCondition.GreaterThanFaceMaxSize(AFacePath: string; var AError: string): Boolean;
  49. var
  50. AFileSize:int64;
  51. begin
  52. AFileSize := GetFileSizeByMB(AFacePath);
  53. Result := (AFileSize = -1) or (AFileSize > TConditionConfig.GetConfig.FaceSize);
  54. if Result then
  55. AError := '对不起,发送的图片中有超过' + IntToStr(TConditionConfig.GetConfig.FaceSize) + 'M !';
  56. end;
  57. class function TLimitCondition.GreaterThanOfflineFileMaxSize(AFileName: string;
  58. var AError: string; ARealICQClient: TRealICQClient): Boolean;
  59. var
  60. AFileSize:int64;
  61. begin
  62. if ARealICQClient.OfflineFileSize <= 0 then
  63. Result := False;
  64. AFileSize := GetFileSizeByMB(AFileName);
  65. Result := (AFileSize = -1) or (AFileSize > ARealICQClient.OfflineFileSize);
  66. if Result then
  67. AError := '对不起,发送离线文件不能超过' + IntToStr(ARealICQClient.OfflineFileSize) + 'M !';
  68. end;
  69. class function TLimitCondition.FirstLoginComfirm: Boolean;
  70. var
  71. FilePath: String;
  72. UserLoginName: String;
  73. begin
  74. Result := TConditionConfig.GetConfig.FirstLoginConfirm and MainForm.RealICQClient.FirstLogin
  75. end;
  76. class function TLimitCondition.UserInfoCheck(AUser: TRealICQUser): Boolean;
  77. var
  78. StrCheckResult: string;
  79. Reg: TPerlRegEx;
  80. begin
  81. Result := True;
  82. if not TConditionConfig.GetConfig.UserInfoCheck then
  83. Exit;
  84. if AUser = nil then
  85. begin
  86. Result := False;
  87. Exit;
  88. end;
  89. if AUser.Duty = '' then
  90. begin
  91. StrCheckResult := StrCheckResult + '职务:没有填写' + #13;
  92. Result := False;
  93. end;
  94. // if AUser.Company = '' then
  95. // begin
  96. // StrCheckResult := StrCheckResult + '单位:没有填写' + #13;
  97. // Result := False;
  98. // end;
  99. if AUser.Branch = '' then
  100. begin
  101. StrCheckResult := StrCheckResult + '处室:没有填写' + #13;
  102. Result := False;
  103. end;
  104. Reg := TPerlRegEx.Create;
  105. try
  106. Reg.RegEx := '^1\d{10}';
  107. Reg.Subject := AUser.Mobile;
  108. if (AUser.Mobile = '') or (not Reg.Match) then
  109. begin
  110. StrCheckResult := StrCheckResult + '手机号码:没有填写或是无效手机号码' + #13;
  111. Result := False;
  112. end;
  113. Reg.RegEx := '\d{6}';
  114. Reg.Subject := AUser.ShortMobile;
  115. if (AUser.ShortMobile = '') or (not Reg.Match) then
  116. begin
  117. StrCheckResult := StrCheckResult + '手机短号:没有填写或是无效手机号码,无(请填写6个1)' + #13;
  118. Result := False;
  119. end;
  120. Reg.RegEx := '^0\d{2,3}-?\d{7,8}';
  121. Reg.Subject := AUser.Tel;
  122. if (AUser.Tel = '') or (not Reg.Match) then
  123. begin
  124. StrCheckResult := StrCheckResult + '办公电话:没有填写或是无效的办公电话号码' + #13;
  125. Result := False;
  126. end;
  127. // Reg.RegEx := '^(\w-*\.*)+@(\w-?)+(\.\w{2,})+';
  128. // Reg.Subject := AUser.Email;
  129. // if (AUser.Email = '') or (not Reg.Match) then
  130. // begin
  131. // StrCheckResult := StrCheckResult + '电子邮箱:没有填写或是无效的电子邮箱地址' + #13;
  132. // Result := False;
  133. // end;
  134. if not Result then
  135. begin
  136. StrCheckResult := StrCheckResult + '请完整填写以上用户信息,谢谢';
  137. ShowMessage(StrCheckResult);
  138. end;
  139. finally
  140. Reg.Free;
  141. end;
  142. end;
  143. end.