unit uUsuariosController; interface uses Classes, SysUtils, Forms, uDADataTable, uControllerBase, uIDataModuleUsuarios, uDataModuleUsuarios, UCBase; type IUsuariosController = interface(IControllerBase) ['{DD963EEC-5880-4DE7-AF55-B5080B538D84}'] procedure Logoff; function StartLogin : Boolean; procedure ShowUserManager; procedure ShowProfileManager; procedure ShowLogManager; procedure ShowChangePassword; function ComprobarUsuario(const User : String; const Password: String): Boolean; procedure CambiarPassword(const AIDUser: Integer; const ANewPassword: String); function GetMaxIntentosLogin: Integer; procedure SetMaxIntentosLogin(const Value: Integer); property MaxIntentosLogin : Integer read GetMaxIntentosLogin write SetMaxIntentosLogin; function GetCurrentUser: TUCCurrentUser; property CurrentUser: TUCCurrentUser read GetCurrentUser; { procedure ChangeUser(IDUser: Integer; Login, Name, Mail: String; Profile,UserExpired,UserDaysSun: Integer; PrivUser: Boolean); procedure ChangePassword(IDUser: Integer; NewPassword: String); procedure AddRight(idUser: Integer; ItemRight: TObject; FullPath: Boolean = True); overload; procedure AddRight(idUser: Integer; ItemRight: String); overload; procedure AddRightEX(idUser: Integer; Module, FormName, ObjName: String); function VerificaLogin(User, Password: String): Boolean; function GetLocalUserName: String; function GetLocalComputerName: String; function AddUser(Login, Password, Name, Mail: String; Profile , UserExpired , DaysExpired : Integer; PrivUser: Boolean): Integer; function ExisteUsuario(Login: String): Boolean; property CurrentUser: TUCCurrentUser read FCurrentUser write FCurrentUser; property CurrentEmpresa : TEmpresaDef read FEmpresaAtual write FEmpresaAtual; property UserSettings: TUCUserSettings read FUserSettings write SetUserSettings;} { function BuscarTodos: IBizFormaPago; function Buscar(ID: Integer): IBizFormaPago; procedure VerTodos(AUsuarios: IBizFormaPago); procedure Ver(AFormaPago: IBizFormaPago); procedure Anadir(AFormaPago : IBizFormaPago); function Eliminar(AFormaPago : IBizFormaPago): Boolean; function Guardar(AFormaPago : IBizFormaPago): Boolean; procedure DescartarCambios(AFormaPago : IBizFormaPago); function Localizar(AUsuarios: IBizFormaPago; ADescripcion:String): Boolean; function DarListaUsuarios: TStringList;} end; TUsuariosController = class(TControllerBase, IUsuariosController) protected FDataModule : IDataModuleUsuarios; FUserControl: TUserControl; function GetMaxIntentosLogin: Integer; procedure SetMaxIntentosLogin(const Value: Integer); procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override; function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean; // function ValidarFormaPago(AFormaPago: IBizFormaPago): Boolean; procedure AsignarDataModule; procedure InicializarUserControl; procedure ComprobarUsuarioInicial; function GetCurrentUser: TUCCurrentUser; procedure OnLoginForm(Sender: TObject; var CustomForm: TCustomForm); public constructor Create; virtual; destructor Destroy; override; procedure Logoff; function StartLogin : Boolean; procedure ShowUserManager; procedure ShowProfileManager; procedure ShowLogManager; procedure ShowChangePassword; function ComprobarUsuario(const User : String; const Password: String): Boolean; procedure CambiarPassword(const AIDUser: Integer; const ANewPassword: String); { function Eliminar(AFormaPago : IBizFormaPago): Boolean; function Guardar(AFormaPago : IBizFormaPago): Boolean; virtual; procedure DescartarCambios(AFormaPago : IBizFormaPago); virtual; procedure Anadir(AFormaPago : IBizFormaPago); function BuscarTodos: IBizFormaPago; function Buscar(ID: Integer): IBizFormaPago; procedure VerTodos(AUsuarios: IBizFormaPago); procedure Ver(AFormaPago: IBizFormaPago); function Localizar(AUsuarios: IBizFormaPago; ADescripcion:String): Boolean; function DarListaUsuarios: TStringList;} property UserControl : TUserControl read FUserControl; property MaxIntentosLogin : Integer read GetMaxIntentosLogin write SetMaxIntentosLogin; property CurrentUser: TUCCurrentUser read GetCurrentUser; end; implementation uses cxControls, DB, uEditorRegistryUtils, schUsuariosClient_Intf, uDAInterfaces, uDataTableUtils, uDialogUtils, uFactuGES_App, uDateUtils, uROTypes, DateUtils, Controls, Windows, uIEditorLogin; { TUsuariosController } {procedure TUsuariosController.Anadir(AFormaPago: IBizFormaPago); begin AFormaPago.Insert; end;} procedure TUsuariosController.AsignarDataModule; begin FDataModule := TDataModuleUsuarios.Create(Nil); end; {function TUsuariosController.Buscar(ID: Integer): IBizFormaPago; begin ShowHourglassCursor; try Result := BuscarTodos; with Result.DataTable.Where do begin if NotEmpty then AddOperator(opAND); OpenBraket; AddText(fld_UsuariosID + ' = ' + IntToStr(ID)); CloseBraket; end; finally HideHourglassCursor; end; end; function TUsuariosController.BuscarTodos: IBizFormaPago; begin Result := FDataModule.GetItems; end;} procedure TUsuariosController.CambiarPassword(const AIDUser: Integer; const ANewPassword: String); begin FUserControl.ChangePassword(AIDUser, ANewPassword); end; function TUsuariosController.ComprobarUsuario(const User, Password: String): Boolean; begin Result := FUserControl.VerificaLogin(User, Password); end; procedure TUsuariosController.ComprobarUsuarioInicial; begin // Para que haya un usuario siempre en la BD if not FUserControl.ExisteUsuario('admin') then FUserControl.AddUser('admin', '1', 'Administrador', 'admin@correo.net', 0, 0 , 30, True); end; constructor TUsuariosController.Create; begin AsignarDataModule; FUserControl := TUserControl.Create(nil); InicializarUserControl; ComprobarUsuarioInicial; end; function TUsuariosController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean; begin Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf); end; { function TUsuariosController.DarListaUsuarios: TStringList; var AUsuarios: IBizFormaPago; begin AUsuarios := BuscarTodos; AUsuarios.DataTable.Active := True; Result := TStringList.Create; try with Result do begin AUsuarios.DataTable.First; while not AUsuarios.DataTable.EOF do begin Add(AUsuarios.DESCRIPCION); AUsuarios.DataTable.Next; end; end; finally AUsuarios := NIL; end; end; procedure TUsuariosController.DescartarCambios(AFormaPago: IBizFormaPago); begin if not Assigned(AFormaPago) then raise Exception.Create ('Forma de pago no asignada'); ShowHourglassCursor; try if (AFormaPago.State in dsEditModes) then AFormaPago.Cancel; AFormaPago.DataTable.CancelUpdates; finally HideHourglassCursor; end; end; } destructor TUsuariosController.Destroy; begin FreeANDNIL(FUserControl); FDataModule := NIL; inherited; end; function TUsuariosController.GetCurrentUser: TUCCurrentUser; begin Result := FUserControl.CurrentUser; end; function TUsuariosController.GetMaxIntentosLogin: Integer; begin Result := FUserControl.Login.MaxLoginAttempts; end; procedure TUsuariosController.InicializarUserControl; begin with FUserControl do begin ApplicationID := AppFactuGES.AppName; AutoStart := False; Criptografia := cMD5; CheckValidationKey := True; Login.MaxLoginAttempts := 3; OnCustomLoginForm := OnLoginForm; end; FDataModule.InicializarUserControl(FUserControl); end; procedure TUsuariosController.Logoff; begin FUserControl.Logoff; end; procedure TUsuariosController.OnLoginForm(Sender: TObject; var CustomForm: TCustomForm); begin // CustomForm := TfLoginForm.Create(NIL); end; { function TUsuariosController.ValidarFormaPago(AFormaPago: IBizFormaPago): Boolean; begin Result := False; if not Assigned(AFormaPago) then raise Exception.Create ('Forma de pago no asignada'); if (AFormaPago.DataTable.State in dsEditModes) then AFormaPago.DataTable.Post; if Length(AFormaPago.REFERENCIA) = 0 then raise Exception.Create('Debe indicar una referencia para esta forma de pago.'); if Length(AFormaPago.DESCRIPCION) = 0 then raise Exception.Create('Debe indicar una descripción para esta forma de pago.'); Result := True; end; procedure TUsuariosController.Ver(AFormaPago: IBizFormaPago); var AEditor : IEditorFormaPago; begin AEditor := NIL; ShowHourglassCursor; try CreateEditor('EditorFormaPago', IEditorFormaPago, AEditor); with AEditor do FormaPago := AFormaPago; finally HideHourglassCursor; end; if Assigned(AEditor) then try AEditor.ShowModal; AEditor.Release; finally AEditor := NIL; end; end; procedure TUsuariosController.VerTodos(AUsuarios: IBizFormaPago); var AEditor : IEditorUsuarios; begin AEditor := NIL; ShowHourglassCursor; try CreateEditor('EditorUsuarios', IEditorUsuarios, AEditor); with AEditor do Usuarios := AUsuarios; finally HideHourglassCursor; end; if Assigned(AEditor) then try AEditor.ShowModal; AEditor.Release; finally AEditor := NIL; end; end; function TUsuariosController.Eliminar(AFormaPago: IBizFormaPago): Boolean; begin Result := False; if not Assigned(AFormaPago) then raise Exception.Create ('Forma de pago no asignada'); ShowHourglassCursor; try if (AFormaPago.State in dsEditModes) then AFormaPago.Cancel; AFormaPago.Delete; AFormaPago.DataTable.ApplyUpdates; HideHourglassCursor; Result := True; finally HideHourglassCursor; end; end;} procedure TUsuariosController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); begin inherited; // end; procedure TUsuariosController.SetMaxIntentosLogin(const Value: Integer); begin FUserControl.Login.MaxLoginAttempts := Value; end; procedure TUsuariosController.ShowChangePassword; begin FUserControl.ShowChangePassword; end; procedure TUsuariosController.ShowLogManager; begin FUserControl.ShowLogManager; end; procedure TUsuariosController.ShowProfileManager; begin FUserControl.ShowProfileManager; end; procedure TUsuariosController.ShowUserManager; begin FUserControl.ShowUserManager; end; function TUsuariosController.StartLogin : Boolean; var AEditor : IEditorLogin; begin AEditor := NIL; ShowHourglassCursor; try CreateEditor('EditorLogin', IEditorLogin, AEditor); with AEditor do Controller := Self; finally HideHourglassCursor; end; if Assigned(AEditor) then begin try Result := (AEditor.ShowModal = mrOk); AEditor.Release; finally AEditor := NIL; end; end; end; {function TUsuariosController.Guardar(AFormaPago: IBizFormaPago): Boolean; begin Result := False; if ValidarFormaPago(AFormaPago) then begin ShowHourglassCursor; try AFormaPago.DataTable.ApplyUpdates; Result := True; finally HideHourglassCursor; end; end; end; function TUsuariosController.Localizar(AUsuarios: IBizFormaPago; ADescripcion: String): Boolean; begin Result := True; ShowHourglassCursor; try with AUsuarios.DataTable do begin DisableControls; First; if not Locate(fld_UsuariosDESCRIPCION, ADescripcion, []) then Result := False; EnableControls; end; finally HideHourglassCursor; end; end;} end.