unit LimitCondition;
interface
uses
Classes, SysUtils, RealICQClient, RealICQModel;
type
TLimitCondition = class
private
class function GetFileSizeByMB(AFileName: string): Int64;
class function GetFileSizeByKB(AFileName: string): Int64;
public
class function GreaterThanFaceMaxSize(AFacePath: string; var AError: string): Boolean;
class function GreaterThanOfflineFileMaxSize(AFileName: string; var AError: string; ARealICQClient: TRealICQClient): Boolean;
class function FirstLoginComfirm: Boolean; static;
///
/// 登录用户的用户信息完整性检测
///
/// 当前登录用户
/// 是否完整
class function UserInfoCheck(AUser: TRealICQUser): Boolean;
end;
implementation
uses
LoggerImport, ConditionConfig, PerlRegEx, Forms, Dialogs, MainFrm;
{ TLimitCondition }
class function TLimitCondition.GetFileSizeByKB(AFileName: string): Int64;
var
AFileStream: TFileStream;
begin
try
AFileStream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
Result := AFileStream.Size div 1024;
except
on E: Exception do
begin
Error('检查文件“'+AFileName+'”发生错误:' + E.Message, 'TLimitCondition.GetFileSizeByKB');
Result := -1;
AFileStream.Free;
end;
end;
AFileStream.Free;
end;
class function TLimitCondition.GetFileSizeByMB(AFileName: string): Int64;
begin
Result := GetFileSizeByKB(AFileName);
if Result <> -1 then
Result := Result div 1024;
end;
class function TLimitCondition.GreaterThanFaceMaxSize(AFacePath: string; var AError: string): Boolean;
var
AFileSize:int64;
begin
AFileSize := GetFileSizeByMB(AFacePath);
Result := (AFileSize = -1) or (AFileSize > TConditionConfig.GetConfig.FaceSize);
if Result then
AError := '对不起,发送的图片中有超过' + IntToStr(TConditionConfig.GetConfig.FaceSize) + 'M !';
end;
class function TLimitCondition.GreaterThanOfflineFileMaxSize(AFileName: string;
var AError: string; ARealICQClient: TRealICQClient): Boolean;
var
AFileSize:int64;
begin
if ARealICQClient.OfflineFileSize <= 0 then
Result := False;
AFileSize := GetFileSizeByMB(AFileName);
Result := (AFileSize = -1) or (AFileSize > ARealICQClient.OfflineFileSize);
if Result then
AError := '对不起,发送离线文件不能超过' + IntToStr(ARealICQClient.OfflineFileSize) + 'M !';
end;
class function TLimitCondition.FirstLoginComfirm: Boolean;
var
FilePath: String;
UserLoginName: String;
begin
Result := TConditionConfig.GetConfig.FirstLoginConfirm and MainForm.RealICQClient.FirstLogin
end;
class function TLimitCondition.UserInfoCheck(AUser: TRealICQUser): Boolean;
var
StrCheckResult: string;
Reg: TPerlRegEx;
begin
Result := True;
if not TConditionConfig.GetConfig.UserInfoCheck then
Exit;
if AUser = nil then
begin
Result := False;
Exit;
end;
if AUser.Duty = '' then
begin
StrCheckResult := StrCheckResult + '职务:没有填写' + #13;
Result := False;
end;
// if AUser.Company = '' then
// begin
// StrCheckResult := StrCheckResult + '单位:没有填写' + #13;
// Result := False;
// end;
if AUser.Branch = '' then
begin
StrCheckResult := StrCheckResult + '处室:没有填写' + #13;
Result := False;
end;
Reg := TPerlRegEx.Create;
try
Reg.RegEx := '^1\d{10}';
Reg.Subject := AUser.Mobile;
if (AUser.Mobile = '') or (not Reg.Match) then
begin
StrCheckResult := StrCheckResult + '手机号码:没有填写或是无效手机号码' + #13;
Result := False;
end;
Reg.RegEx := '\d{6}';
Reg.Subject := AUser.ShortMobile;
if (AUser.ShortMobile = '') or (not Reg.Match) then
begin
StrCheckResult := StrCheckResult + '手机短号:没有填写或是无效手机号码,无(请填写6个1)' + #13;
Result := False;
end;
Reg.RegEx := '^0\d{2,3}-?\d{7,8}';
Reg.Subject := AUser.Tel;
if (AUser.Tel = '') or (not Reg.Match) then
begin
StrCheckResult := StrCheckResult + '办公电话:没有填写或是无效的办公电话号码' + #13;
Result := False;
end;
// Reg.RegEx := '^(\w-*\.*)+@(\w-?)+(\.\w{2,})+';
// Reg.Subject := AUser.Email;
// if (AUser.Email = '') or (not Reg.Match) then
// begin
// StrCheckResult := StrCheckResult + '电子邮箱:没有填写或是无效的电子邮箱地址' + #13;
// Result := False;
// end;
if not Result then
begin
StrCheckResult := StrCheckResult + '请完整填写以上用户信息,谢谢';
ShowMessage(StrCheckResult);
end;
finally
Reg.Free;
end;
end;
end.