git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@60 0c75b7a4-871f-7646-8a2f-f78d34cc349f
220 lines
6.4 KiB
ObjectPascal
220 lines
6.4 KiB
ObjectPascal
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;}
|
|
|
|
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;
|
|
|
|
procedure AsignarDataModule;
|
|
procedure InicializarUserControl;
|
|
procedure ComprobarUsuarioInicial;
|
|
function GetCurrentUser: TUCCurrentUser;
|
|
|
|
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);
|
|
|
|
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, Dialogs,
|
|
uDateUtils, uROTypes, DateUtils, Controls, Windows, uIEditorLogin;
|
|
|
|
{ TUsuariosController }
|
|
|
|
procedure TUsuariosController.AsignarDataModule;
|
|
begin
|
|
FDataModule := TDataModuleUsuarios.Create;
|
|
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;
|
|
|
|
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;
|
|
end;
|
|
FDataModule.InicializarUserControl(FUserControl);
|
|
end;
|
|
|
|
procedure TUsuariosController.Logoff;
|
|
begin
|
|
FUserControl.Logoff;
|
|
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;
|
|
|
|
end.
|