📄 ucbase.pas
字号:
FDataSet.FieldByName(TableUsers.FieldLogin).asString +
Decrypt(FDataSet.FieldByName(TableUsers.FieldPassword).asString, EncryptKey) then
begin
Result := False;
if Assigned(OnLoginError) then OnLoginError(Self, User, Password);
end else
begin
Result := True;
RegistraCurrentuser(FDataset);
end;
end else begin
Result := False;
if Assigned(OnLoginError) then OnLoginError(Self, User, Password);
end;
finally
Close;
Free;
end;
end;
procedure TUserControl.Logoff;
begin
if Assigned(onLogoff) then onLogoff(Self, CurrentUser.UserID);
LockControlsUCControlMonitor;
CurrentUser.UserID := 0;
if LoginMode = lmActive then ShowLogin;
ApplyRights;
end;
function TUserControl.AddUser(Login, Password, Name, Mail: String;
Profile: Integer; PrivUser: Boolean) : Integer;
var
Key : String;
begin
with DataConnector.UCGetSQLDataset('Select Max('+TableUsers.FieldUserID+') as IdUser from ' + TableUsers.TableName) do
begin
Result := Fieldbyname('idUser').asInteger + 1;
Close;
Free;
end;
Key := Encrypt( IntToStr(Result)+Login+Password, EncryptKey );
with TableUsers do
DataConnector.UCExecSQL(Format('Insert into %s( %s, %s, %s, %s, %s, %s, %s, %s, %s) VALUES(%d, %s, %s, %s, %s, %s, %d, %s, %s)',
[ TableName,
FieldUserID, FieldUserName, FieldLogin, FieldPassword, FieldEmail, FieldPrivileged, FieldProfile, FieldTypeRec, FieldKey,
Result, QuotedStr(Name), QuotedStr(Login), QuotedStr(Encrypt(Password, EncryptKey)),
QuotedStr(Mail), BoolToStr(PrivUser), Profile, QuotedStr('U'), QuotedStr(Key)]));
if Assigned(OnAddUser) then OnAddUser(Self, Login, Password, Name, Mail, Profile, Privuser);
end;
procedure TUserControl.ChangePassword(IDUser: Integer; NewPassword: String);
var
FLogin, FSenha : String;
Key : String;
begin
inherited;
with DataConnector.UCGetSQLDataset('Select '+TableUsers.FieldLogin+' as login, '+TableUsers.FieldPassword+
' as senha from ' + TableUsers.TableName+' where '+TableUsers.FieldUserID+' = '+ IntToStr(IdUser)) do
begin
FLogin := Fieldbyname('Login').asString;
Key := Encrypt( IntToStr(IDUser)+FLogin+NewPassword, EncryptKey );
FSenha := Decrypt(FieldByName('Senha').asString, EncryptKey);
Close;
Free;
end;
DataConnector.UCExecSQL('Update ' + TableUsers.TableName + ' Set '+TableUsers.FieldPassword+' = '+
QuotedStr(Encrypt(NewPassword, EncryptKey))+', '+TableUsers.FieldKey + ' = ' +QuotedStr(Key)+
' where '+TableUsers.FieldUserID+' = '+ IntToStr(IdUser));
if Assigned(onChangePassword) then OnChangePassword(Self, IdUser, FLogin, FSenha, NewPassword);
end;
procedure TUserControl.ChangeUser(IDUser: Integer; Login, Name,
Mail: String; Profile: Integer; PrivUser: Boolean);
var
Key, Password : String;
begin
with DataConnector.UCGetSQLDataset('Select ' + TableUsers.FieldPassword+
' as senha from ' + TableUsers.TableName+' where '+TableUsers.FieldUserID+' = '+ IntToStr(IdUser)) do
begin
Password := Decrypt(FieldByName('Senha').asString, EncryptKey);
Close;
Free;
end;
Key := Encrypt( IntToStr(IDUser)+Login+Password, EncryptKey );
with TableUsers do
DataConnector.UCExecSQL('Update ' + TableName + ' Set '+
FieldUserName + ' = '+ QuotedStr(Name)+', '+
FieldLogin + ' = '+ QuotedStr(Login)+', '+
FieldEmail + ' = '+ QuotedStr(Mail)+', '+
FieldPrivileged + ' = '+ BooltoStr(PrivUser)+', '+
FieldProfile + ' = '+ IntToStr(Profile)+ ', '+
FieldKey + ' = ' + QuotedStr(Key) +
' where '+FieldUserID +' = '+ IntToStr(IdUser));
if Assigned(OnChangeUser) then OnChangeUser(Self, IdUser, Login, Name, Mail, Profile, PrivUser);
end;
procedure IniSettings(DestSettings: TUserSettings);
var
tmp : TBitmap;
begin
with DestSettings.CommonMessages do
begin
if BlankPassword = '' then BlankPassword := Const_Men_SenhaDesabitada;
if PasswordChanged = '' then PasswordChanged := Const_Men_SenhaAlterada;
if InitialMessage.Text = '' then InitialMessage.Text := Const_Men_MsgInicial;
if MaxLoginAttemptsError = '' then MaxLoginAttemptsError := Const_Men_MaxTentativas;
if InvalidLogin = '' then InvalidLogin := Const_Men_LoginInvalido;
if AutoLogonError = '' then AutoLogonError := Const_Men_AutoLogonError;
end;
with DestSettings.Login do
begin
if BtCancel = '' then BtCancel := Const_Log_BtCancelar;
if BtOK = '' then BtOK := Const_Log_BtOK;
if LabelPassword = '' then LabelPassword := Const_Log_LabelSenha;
if LabelUser = '' then LabelUser := Const_Log_LabelUsuario;
if WindowCaption = '' then WindowCaption := Const_Log_WindowCaption;
Tmp := TBitmap.create;
Tmp.LoadFromResourceName(HInstance, 'UCLOCKLOGIN');
LeftImage.Assign(tmp);
end;
with DestSettings.UsersForm do
begin
if WindowCaption = '' then WindowCaption := Const_Cad_WindowCaption;
if LabelDescription = '' then LabelDescription := Const_Cad_LabelDescricao;
if ColName = '' then ColName := Const_Cad_ColunaNome;
if ColLogin = '' then ColLogin := Const_Cad_ColunaLogin;
if ColEmail = '' then ColEmail := Const_Cad_ColunaEmail;
if BtAdd = '' then BtAdd := Const_Cad_BtAdicionar;
if BtChange = '' then BtChange := Const_Cad_BtAlterar;
if BtDelete = '' then BtDelete := Const_Cad_BtExcluir;
if BtRights = '' then BtRights := Const_Cad_BtPermissoes;
if BtPassword = '' then BtPassword := Const_Cad_BtSenha;
if BtClose = '' then BtClose := Const_Cad_BtFechar;
if PromptDelete = '' then PromptDelete := Const_Cad_ConfirmaExcluir;
end;
with DestSettings.UsersProfile do
begin
if WindowCaption = '' then WindowCaption := Const_Prof_WindowCaption;
if LabelDescription = '' then LabelDescription := Const_Prof_LabelDescricao;
if ColProfile = '' then ColProfile := Const_Prof_ColunaNome;
if BtAdd = '' then BtAdd := Const_Prof_BtAdicionar;
if BtChange = '' then BtChange := Const_Prof_BtAlterar;
if BtDelete = '' then BtDelete := Const_Prof_BtExcluir;
if BtRights = '' then BtRights := Const_Prof_BtPermissoes; //BGM
if BtClose = '' then BtClose := Const_Prof_BtFechar;
if PromptDelete = '' then PromptDelete := Const_Prof_ConfirmaExcluir;
end;
with DestSettings.AddChangeUser do
begin
if WindowCaption = '' then WindowCaption := Const_Inc_WindowCaption;
if LabelAdd = '' then LabelAdd := Const_Inc_LabelAdicionar;
if LabelChange = '' then LabelChange := Const_Inc_LabelAlterar;
if LabelName = '' then LabelName := Const_Inc_LabelNome;
if LabelLogin = '' then LabelLogin := Const_Inc_LabelLogin;
if LabelEmail = '' then LabelEmail := Const_Inc_LabelEmail;
if LabelPerfil = '' then LabelPerfil := Const_Inc_LabelPerfil;
if CheckPrivileged = '' then CheckPrivileged := Const_Inc_CheckPrivilegiado;
if BtSave = '' then BtSave := Const_Inc_BtGravar;
if BtCancel = '' then BtCancel := Const_Inc_BtCancelar;
end;
with DestSettings.AddChangeProfile do
begin
if WindowCaption = '' then WindowCaption := Const_PInc_WindowCaption;
if LabelAdd = '' then LabelAdd := Const_PInc_LabelAdicionar;
if LabelChange = '' then LabelChange := Const_PInc_LabelAlterar;
if LabelName = '' then LabelName := Const_PInc_LabelNome;
if BtSave = '' then BtSave := Const_PInc_BtGravar;
if BtCancel = '' then BtCancel := Const_PInc_BtCancelar;
end;
with DestSettings.Rights do
begin
if WindowCaption = '' then WindowCaption := Const_Perm_WindowCaption;
if LabelUser = '' then LabelUser := Const_Perm_LabelUsuario;
if LabelProfile = '' then LabelProfile := Const_Perm_LabelPerfil;
if PageMenu = '' then PageMenu := Const_Perm_PageMenu;
if PageActions = '' then PageActions := Const_Perm_PageActions;
if BtUnlock = '' then BtUnlock := Const_Perm_BtLibera;
if BtLock = '' then BtLock := Const_Perm_BtBloqueia;
if BtSave = '' then BtSave := Const_Perm_BtGravar;
if BtCancel = '' then BtCancel := Const_Perm_BtCancelar;
end;
with DestSettings.ChangePassword do
begin
if WindowCaption = '' then WindowCaption := Const_Troc_WindowCaption;
if LabelDescription = '' then LabelDescription := Const_Troc_LabelDescricao;
if LabelCurrentPassword = '' then LabelCurrentPassword := Const_Troc_LabelSenhaAtual;
if LabelNewPassword = '' then LabelNewPassword := Const_Troc_LabelNovaSenha;
if LabelConfirm = '' then LabelConfirm := Const_Troc_LabelConfirma;
if BtSave = '' then BtSave := Const_Troc_BtGravar;
if BtCancel = '' then BtCancel := Const_Troc_BtCancelar;
end;
with DestSettings.CommonMessages.ChangePasswordError do
begin
if InvalidCurrentPassword = '' then InvalidCurrentPassword := Const_ErrPass_SenhaAtualInvalida;
if NewPasswordError = '' then NewPasswordError := Const_ErrPass_ErroNovaSenha;
if NewEqualCurrent = '' then NewEqualCurrent := Const_ErrPass_NovaIgualAtual;
if PasswordRequired = '' then PasswordRequired := Const_ErrPass_SenhaObrigatoria;
if MinPasswordLength = '' then MinPasswordLength := Const_ErrPass_SenhaMinima;
if InvalidNewPassword= '' then InvalidNewPassword := Const_ErrPass_SenhaInvalida;
end;
with DestSettings.ResetPassword do
begin
if WindowCaption = '' then WindowCaption := Const_DefPass_WindowCaption;
if LabelPassword = '' then LabelPassword := Const_DefPass_LabelSenha;
end;
with DestSettings.Log do
begin
if WindowCaption = '' then WindowCaption := Const_LogC_WindowCaption;
if LabelDescription = '' then LabelDescription := Const_LogC_LabelDescricao;
if LabelUser = '' then LabelUser := Const_LogC_LabelUsuario;
if LabelDate = '' then LabelDate := Const_LogC_LabelData;
if LabelLevel = '' then LabelLevel := Const_LogC_LabelNivel;
if ColLevel = '' then ColLevel := Const_LogC_ColunaNivel;
if ColMessage = '' then ColMessage := Const_LogC_ColunaMensagem;
if ColUser = '' then ColUser := Const_LogC_ColunaUsuario;
if ColDate = '' then ColDate := Const_LogC_ColunaData;
if BtFilter = '' then BtFilter := Const_LogC_BtFiltro;
if BtDelete = '' then BtDelete := Const_LogC_BtExcluir;
if BtClose = '' then BtClose := Const_LogC_BtFechar;
if PromptDelete = '' then PromptDelete := Const_LogC_ConfirmaExcluir;
end;
with DestSettings.AppMessages do
begin
if MsgsForm_BtNew = '' then MsgsForm_BtNew := Const_Msgs_BtNew;
if MsgsForm_BtReplay = '' then MsgsForm_BtReplay := Const_Msgs_BtReplay;
if MsgsForm_BtForward = '' then MsgsForm_BtForward := Const_Msgs_BtForward;
if MsgsForm_BtDelete = '' then MsgsForm_BtDelete := Const_Msgs_BtDelete;
if MsgsForm_WindowCaption = '' then MsgsForm_WindowCaption := Const_Msgs_WindowCaption;
if MsgsForm_ColFrom = '' then MsgsForm_ColFrom := Const_Msgs_ColFrom;
if MsgsForm_ColSubject = '' then MsgsForm_ColSubject := Const_Msgs_ColSubject;
if MsgsForm_ColDate = '' then MsgsForm_ColDate := Const_Msgs_ColDate;
if MsgsForm_PromptDelete = '' then MsgsForm_PromptDelete := Const_Msgs_PromptDelete;
if MsgRec_BtClose = '' then MsgRec_BtClose := Const_MsgRec_BtClose;
if MsgRec_WindowCaption = '' then MsgRec_WindowCaption := Const_MsgRec_WindowCaption;
if MsgRec_Title = ''then MsgRec_Title := Const_MsgRec_Title;
if MsgRec_LabelFrom = ''then MsgRec_LabelFrom := Const_MsgRec_LabelFrom;
if MsgRec_LabelDate = '' then MsgRec_LabelDate := Const_MsgRec_LabelDate;
if MsgRec_LabelSubject = '' then MsgRec_LabelSubject := Const_MsgRec_LabelSubject;
if MsgRec_LabelMessage = '' then MsgRec_LabelMessage := Const_MsgRec_LabelMessage;
if MsgSend_BtSend = '' then MsgSend_BtSend := Const_MsgSend_BtSend;
if MsgSend_BtCancel = '' then MsgSend_BtCancel := Const_MsgSend_BtCancel;
if MsgSend_WindowCaption = '' then MsgSend_WindowCaption := Const_MsgSend_WindowCaption;
if MsgSend_Title = '' then MsgSend_Title := Const_MsgSend_Title;
if MsgSend_GroupTo = '' then MsgSend_GroupTo := Const_MsgSend_GroupTo;
if MsgSend_RadioUser = '' then MsgSend_RadioUser := Const_MsgSend_RadioUser;
if MsgSend_RadioAll = '' then MsgSend_RadioAll := Const_MsgSend_RadioAll;
if MsgSend_GroupMessage = '' then MsgSend_GroupMessage := Const_MsgSend_GroupMessage;
end;
DestSettings.WindowsPosition := poDesktopCenter;
end;
procedure TUserControl.CriaTabelaMsgs(const TableName : String);
begin
DataConnector.UCExecSQL('Create Table '+ TableName + ' ( '+
'IdMsg int ,'+
'UsrFrom int, '+
'UsrTo int, '+
'Subject Varchar(50),'+
'Msg Varchar(255),'+
'DtSend Varchar(12),'+
'DtReceive Varchar(12) )');
end;
destructor TUserControl.Destroy;
begin
FRightItems.Free;
FUser.Free;
ControlRight.Free;
Login.Free;
LogControl.Free;
UsersForm.Free;
UsersProfile.Free;
ChangePasswordForm.Free;
FUserSettings.Free;
FNaoPermitidos.Free;
FreeAndNil(UCControlList);
FreeAndNil(LoginMonitorList);
inherited Destroy;
end;
procedure TUserControl.SetItems(Value: TUCCollection);
begin
end;
procedure TUserControl.HideField(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
Text := '(Campo Bloqueado)';
end;
procedure TUserControl.StartLogin;
begin
CurrentUser.UserID := 0;
ShowLogin;
ApplyRights;
end;
procedure TUserControl.Execute;
begin
// if not UCFindDataConnection then raise Exception.Create(Format(msgExceptConnection,[name]));
if Assigned(FThUCRun) then FThUCRun.Terminate;
try
if not DataConnector.UCFindTable(FTableRights.TableName) then CriaTableRights;
if not DataConnector.UCFindTable(FTableRights.TableName+'EX') then CriaTableRights(True); //extra rights table
if LogControl.Active then
if not DataConnector.UCFindTable(LogControl.TableLog) then CriaTableLog;
CriaTabelaUsuarios(DataConnector.UCFindTable(FTableUsers.Ta
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -