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

📄 ucbase.pas

📁 delphi 控件有需要的可以下载看看,可以用的,希望对你用 帮助
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  with FDataset do
    try
      if not IsEmpty then
        MailUserControl.EnviaEsqueceuSenha( fieldbyname(TableUsers.FieldUserName).asString,
                                            fieldbyname(TableUsers.FieldLogin).asString,
                                            fieldbyname(TableUsers.FieldPassword).asString,
                                            fieldbyname(TableUsers.FieldEmail).asString, '', EncryptKey)
      else MessageDlg(Settings.CommonMessages.InvalidLogin, mtWarning, [mbOK], 0);
    finally
      Close;
      Free;
    end;
end;
{$ENDIF}

procedure TUserControl.TryAutoLogon;
begin
  if not VerificaLogin(Login.AutoLogon.User, Login.AutoLogon.Password) then
  begin
    if Login.AutoLogon.MessageOnError then MessageDlg(Settings.CommonMessages.AutoLogonError, mtWarning, [mbOK], 0);
    ShowLogin;
  end;
end;


function TUserControl.VerificaLogin(User, Password: String): Boolean;
var
  vSenha, Key : String;
  FDataset : TDataset;
begin
  vSenha := TableUsers.FieldPassword +  ' = ' + QuotedStr(Encrypt(Password, EncryptKey));
  FDataset := DataConnector.UCGetSQLDataset('Select * from '+ TableUsers.TableName + ' Where '+
              TableUsers.FieldLogin+' = '+ QuotedStr(User) + ' and ' + vSenha);
  with FDataset do
    try
      if not IsEmpty then
      begin
        Key := Decrypt(FDataset.FieldByName(TableUsers.FieldKey).asString, EncryptKey);

        if Key <> FDataSet.FieldByName(TableUsers.FieldUserID).asString +
                  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);
      FreeAndNil(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;
      if PromptDelete_WindowCaption = '' then PromptDelete_WindowCaption := Const_Cad_ConfirmaDelete_WindowCaption; //added by fduenas

    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;
      if PromptDelete_WindowCaption = '' then PromptDelete_WindowCaption := Const_Prof_ConfirmaDelete_WindowCaption; //added by fduenas
    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;
      if PromptDelete_WindowCaption = '' then PromptDelete_WindowCaption := Const_LogC_ConfirmaDelete_WindowCaption; //added by fduenas
      if OptionUserAll = '' then OptionUserAll := Const_LogC_Todos; //added by fduenas
      if OptionLevelLow = '' then OptionLevelLow := Const_LogC_Low; //added by fduenas
      if OptionLevelNormal = '' then OptionLevelNormal := Const_LogC_Normal; //added by fduenas
      if OptionLevelHigh = '' then OptionLevelHigh := Const_LogC_High; //added by fduenas
      if OptionLevelCritic = '' then OptionLevelCritic := Const_LogC_Critic; //added by fduenas
      if DeletePerformed = '' then DeletePerformed := Const_LogC_ExcluirEfectuada; //added by fduenas
    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_BtClose = '' then MsgsForm_BtDelete := Const_Msgs_BtClose; //added by fduenas
      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 MsgsForm_PromptDelete_WindowCaption = '' then  MsgsForm_PromptDelete_WindowCaption := Const_Msgs_PromptDelete_WindowCaption;
      if MsgsForm_NoMessagesSelected = '' then  MsgsForm_NoMessagesSelected := Const_Msgs_NoMessagesSelected;
      if MsgsForm_NoMessagesSelected_WindowCaption = '' then  MsgsForm_NoMessagesSelected_WindowCaption := Const_Msgs_NoMessagesSelected_WindowCaption;

      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;
      

⌨️ 快捷键说明

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