2007-10-03 16:03:28 +00:00
unit uUsuariosController;
interface
uses
2007-10-08 07:58:40 +00:00
Classes, SysUtils, Forms, uDADataTable, uControllerBase,
2008-01-13 21:37:20 +00:00
uIDataModuleUsuarios, uDataModuleUsuarios, UCBase, uBizUsuarios;
2007-10-03 16:03:28 +00:00
type
2008-01-13 21:37:20 +00:00
TUCCriptografia = ( ucStandard, ucMD5) ;
2007-10-08 07:58:40 +00:00
IUsuariosController = interface( IControllerBase)
2007-10-03 16:03:28 +00:00
[ '{DD963EEC-5880-4DE7-AF55-B5080B538D84}' ]
2007-10-08 07:58:40 +00:00
procedure Logoff;
function StartLogin : Boolean ;
2008-01-13 21:37:20 +00:00
procedure VerUsuarios;
procedure VerPerfiles;
procedure VerUsuario( const AIDUser: Integer ) ; overload ;
procedure VerUsuario( AUser : IBizUsuario) ; overload ;
procedure VerPerfil( const AIDPerfil: Integer ) ; overload ;
procedure VerPerfil( APerfil : IBizPerfilUsuario) ; overload ;
procedure _ShowUserManager;
procedure _ShowProfileManager;
procedure _ShowLogManager;
procedure _ShowChangePassword;
2007-10-08 07:58:40 +00:00
function ComprobarUsuario( const User : String ; const Password: String ) : Boolean ;
2008-01-13 21:37:20 +00:00
function CambiarPassword( const AIDUser: Integer ) : Boolean ;
2007-10-08 07:58:40 +00:00
function GetMaxIntentosLogin: Integer ;
procedure SetMaxIntentosLogin( const Value: Integer ) ;
property MaxIntentosLogin : Integer read GetMaxIntentosLogin write SetMaxIntentosLogin;
2008-01-15 18:26:46 +00:00
function GetCurrentUser: IBizUsuario;
property CurrentUser: IBizUsuario read GetCurrentUser;
2007-10-09 07:47:51 +00:00
2008-01-13 21:37:20 +00:00
function GuardarPerfil( APerfil : IBizPerfilUsuario) : Boolean ;
function GuardarUsuario( AUser : IBizUsuario) : Boolean ;
function EliminarUsuario( const AIDUser : integer ) : Boolean ; overload ;
function EliminarUsuario( AUser : IBizUsuario) : Boolean ; overload ;
function EliminarPerfil( APerfil : IBizPerfilUsuario) : Boolean ; overload ;
function EliminarPerfil( const AIDPerfil : integer ) : Boolean ; overload ;
function HayUsuarioConPerfil( const AIDPerfil : integer ) : Boolean ;
2008-01-15 17:07:23 +00:00
function BuscarUsuario( const AIDUser: Integer ) : IBizUsuario;
function BuscarTodosUsuarios: IBizUsuario;
2008-01-13 21:37:20 +00:00
function DarListaPerfilesUsuario: TStringList;
2008-01-15 17:07:23 +00:00
function DarListaUsuarios: TStringList;
2008-01-13 21:37:20 +00:00
function ValidarPassword( const APassword : string ; const ALogin : String ;
const ANombre: String ; out AMsg : String ) : boolean ;
function NuevoUsuario : IBizUsuario;
function NuevoPerfil : IBizPerfilUsuario;
2007-10-09 07:47:51 +00:00
2008-01-13 21:37:20 +00:00
function GetCriptografia : TUCCriptografia;
property Criptografia: TUCCriptografia read GetCriptografia;
2008-02-07 22:54:05 +00:00
function GetUsarPasswordsSeguras: Boolean ;
procedure SetUsarPasswordsSeguras( const Value: Boolean ) ;
property UsarPasswordsSeguras : Boolean read GetUsarPasswordsSeguras write SetUsarPasswordsSeguras;
2008-01-13 21:37:20 +00:00
{
2007-10-03 16:03:28 +00:00
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 ;
2007-10-08 07:58:40 +00:00
TUsuariosController = class( TControllerBase, IUsuariosController)
2008-01-13 21:37:20 +00:00
private
2008-01-15 18:26:46 +00:00
procedure FiltrarEmpresa( AUsuario: IBizUsuario) ;
2007-10-03 16:03:28 +00:00
protected
FDataModule : IDataModuleUsuarios;
FUserControl: TUserControl;
2008-01-15 18:26:46 +00:00
FCurrentUser : IBizUsuario;
2008-02-07 22:54:05 +00:00
FUsarPasswordsSeguras : Boolean ;
2007-10-03 16:03:28 +00:00
2007-10-08 07:58:40 +00:00
function GetMaxIntentosLogin: Integer ;
procedure SetMaxIntentosLogin( const Value: Integer ) ;
2007-10-03 16:03:28 +00:00
procedure RecibirAviso( ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable) ; override ;
function CreateEditor( const AName : String ; const IID: TGUID; out Intf) : Boolean ;
procedure AsignarDataModule;
procedure InicializarUserControl;
2008-01-15 18:26:46 +00:00
function GetCurrentUser: IBizUsuario;
2007-10-08 07:58:40 +00:00
2008-01-13 21:37:20 +00:00
function AnadirUsuario( AUser : IBizUsuario) : Boolean ;
function ModificarUsuario( AUser : IBizUsuario) : Boolean ;
function AnadirPerfil( APerfil : IBizPerfilUsuario) : Boolean ;
function ModificarPerfil( APerfil : IBizPerfilUsuario) : Boolean ;
function ValidarUsuario( AUser: IBizUsuario) : Boolean ;
function ValidarPerfil( APerfil: IBizPerfilUsuario) : Boolean ;
function GetCriptografia : TUCCriptografia;
function CambiarPassword( const AIDUser: Integer ; const ANewPassword: String ) : Boolean ; overload ;
2008-02-07 22:54:05 +00:00
function GetUsarPasswordsSeguras: Boolean ;
procedure SetUsarPasswordsSeguras( const Value: Boolean ) ;
2007-10-03 16:03:28 +00:00
public
2008-05-14 14:38:09 +00:00
constructor Create; override ;
2007-10-03 16:03:28 +00:00
destructor Destroy; override ;
2007-10-08 07:58:40 +00:00
procedure Logoff;
function StartLogin : Boolean ;
2008-01-13 21:37:20 +00:00
procedure VerUsuarios;
procedure VerPerfiles;
procedure VerUsuario( const AIDUser: Integer ) ; overload ;
procedure VerUsuario( AUser : IBizUsuario) ; overload ;
procedure VerPerfil( const AIDPerfil: Integer ) ; overload ;
procedure VerPerfil( APerfil : IBizPerfilUsuario) ; overload ;
procedure _ShowUserManager;
procedure _ShowProfileManager;
procedure _ShowLogManager;
procedure _ShowChangePassword;
2007-10-09 07:47:51 +00:00
function ComprobarUsuario( const User : String ; const Password: String ) : Boolean ;
2008-01-13 21:37:20 +00:00
function CambiarPassword( const AIDUser: Integer ) : Boolean ; overload ;
function EliminarUsuario( const AIDUser : integer ) : Boolean ; overload ;
function EliminarUsuario( AUser : IBizUsuario) : Boolean ; overload ;
function EliminarPerfil( APerfil : IBizPerfilUsuario) : Boolean ; overload ;
function EliminarPerfil( const AIDPerfil : integer ) : Boolean ; overload ;
function NuevoUsuario : IBizUsuario;
function NuevoPerfil : IBizPerfilUsuario;
function GuardarPerfil( APerfil : IBizPerfilUsuario) : Boolean ;
function GuardarUsuario( AUser : IBizUsuario) : Boolean ;
2008-01-15 17:07:23 +00:00
function BuscarUsuario( const AIDUser: Integer ) : IBizUsuario;
function BuscarTodosUsuarios: IBizUsuario;
2008-01-13 21:37:20 +00:00
function DarListaPerfilesUsuario: TStringList;
2008-01-15 17:07:23 +00:00
function DarListaUsuarios: TStringList;
2008-01-13 21:37:20 +00:00
function HayUsuarioConPerfil( const AIDPerfil : integer ) : Boolean ;
function ValidarPassword( const APassword : string ; const ALogin : String ;
const ANombre: String ; out AMsg : String ) : boolean ;
2008-02-07 22:54:05 +00:00
property UsarPasswordsSeguras : Boolean read GetUsarPasswordsSeguras write SetUsarPasswordsSeguras;
2007-10-03 16:03:28 +00:00
property UserControl : TUserControl read FUserControl;
2007-10-09 07:47:51 +00:00
property MaxIntentosLogin : Integer read GetMaxIntentosLogin write SetMaxIntentosLogin;
2008-01-15 18:26:46 +00:00
property CurrentUser: IBizUsuario read GetCurrentUser;
2008-01-13 21:37:20 +00:00
property Criptografia: TUCCriptografia read GetCriptografia;
2007-10-03 16:03:28 +00:00
end ;
implementation
uses
cxControls, DB, uEditorRegistryUtils, schUsuariosClient_Intf,
2007-10-22 07:39:39 +00:00
uDAInterfaces, uDataTableUtils, uDialogUtils, uFactuGES_App, Dialogs,
2008-01-13 21:37:20 +00:00
uDateUtils, uROTypes, DateUtils, Controls, Windows, uIEditorLogin,
uIEditorUsuarios, uIEditorUsuario, uIEditorPerfilesUsuario,
uIEditorPerfilUsuario, uEditorCambiarPassword;
2007-10-03 16:03:28 +00:00
{ TUsuariosController }
2008-01-13 21:37:20 +00:00
function TUsuariosController. AnadirPerfil( APerfil: IBizPerfilUsuario) : Boolean ;
function GetNewIdUser: Integer ;
var
TempDs: TDataset;
begin
with FUserControl do
TempDS : = DataConnector. UCGetSQLDataSet( 'SELECT ' + TableUsers. FieldUserID + ' as MaxUserID from ' + TableUsers. TableName +
' ORDER BY ' + TableUsers. FieldUserID + ' DESC' ) ;
Result : = TempDs. FieldByName( 'MaxUserID' ) . AsInteger + 1 ;
TempDS. Close;
FreeAndNil( TempDS) ;
end ;
var
ANuevoID : Integer ;
begin
Result : = False ;
if not Assigned( APerfil) then
raise Exception. Create( 'No hay perfil asignado (AnadirPerfil)' ) ;
if ValidarPerfil( APerfil) then
begin
ShowHourglassCursor;
try
ANuevoID : = GetNewIdUser;
with FUserControl do
begin
DataConnector. UCExecSQL( Format( 'INSERT INTO %s(%s, %s, %s) Values(%d,%s,%s)' ,
[ TableUsers. TableName,
TableUsers. FieldUserID,
TableUsers. FieldUserName,
TableUsers. FieldTypeRec,
ANuevoID,
QuotedStr( APerfil. USERNAME) ,
QuotedStr( 'P' ) ] ) ) ;
end ;
Result : = ( ANuevoID > 0 ) ;
if Result then
begin
APerfil. Edit;
APerfil. ID : = ANuevoID;
APerfil. Post;
end ;
finally
HideHourglassCursor;
end ;
end ;
end ;
function TUsuariosController. AnadirUsuario( AUser: IBizUsuario) : Boolean ;
var
ANuevoID : Integer ;
begin
Result : = False ;
if not Assigned( AUser) then
raise Exception. Create( 'No hay usuario asignado (AnadirUsuario)' ) ;
if FUserControl. ExisteUsuario( AUser. LOGIN) then
begin
MessageDlg( Format( FUserControl. UserSettings. CommonMessages. UsuarioExiste, [ AUser. LOGIN] ) , mtWarning, [ mbOK] , 0 ) ;
Exit;
end ;
if ValidarUsuario( AUser) then
begin
ShowHourglassCursor;
try
ANuevoID : = FUserControl. AddUser( AUser. LOGIN, AUser. PASS, AUser. USERNAME, AUser. EMAIL,
AUser. ID_PERFIL, AUser. BLOQUEADO, AUser. USERDAYSSUN, ( AUser. PRIVILEGED = 1 ) ) ;
Result : = ( ANuevoID > 0 ) ;
if Result then
begin
AUser. Edit;
AUser. ID : = ANuevoID;
AUser. Post;
end ;
{ TODO -oLuiz -cUpgrade : Consertar a Senha para poder avisar MD5 }
{ if ( Assigned( MailUserControl) ) and ( MailUserControl. AdicionaUsuario. Ativo) then
try
MailUserControl. EnviaEmailAdicionaUsuario( vNome, vLogin, Encrypt( vNovaSenha, EncryptKey) , vEmail, IntToStr( vPerfil) , EncryptKey) ;
except
on E: Exception do
Log( E. Message , llMedio) ;
end ; }
finally
HideHourglassCursor;
end ;
end ;
end ;
2007-10-03 16:03:28 +00:00
procedure TUsuariosController. AsignarDataModule;
begin
2007-10-24 18:54:18 +00:00
FDataModule : = TDataModuleUsuarios. Create( Nil ) ;
2007-10-03 16:03:28 +00:00
end ;
2008-01-15 17:07:23 +00:00
function TUsuariosController. BuscarTodosUsuarios: IBizUsuario;
begin
Result : = FDataModule. GetUsuarios;
FiltrarEmpresa( Result ) ;
end ;
function TUsuariosController. BuscarUsuario( const AIDUser: Integer ) : IBizUsuario;
begin
Result : = FDataModule. GetUsuario( AIDUser) ;
FiltrarEmpresa( Result ) ;
end ;
2008-01-13 21:37:20 +00:00
function TUsuariosController. CambiarPassword( const AIDUser: Integer ;
const ANewPassword: String ) : Boolean ;
2007-10-09 07:47:51 +00:00
begin
FUserControl. ChangePassword( AIDUser, ANewPassword) ;
2008-01-13 21:37:20 +00:00
Result : = True ;
end ;
function TUsuariosController. CambiarPassword( const AIDUser: Integer ) : Boolean ;
var
AUser : IBizUsuario;
2008-11-13 13:10:32 +00:00
AEditor : TfEditorCambiarPassword;
2008-01-13 21:37:20 +00:00
begin
2008-05-14 14:38:09 +00:00
Result : = False ;
2008-01-13 21:37:20 +00:00
AUser : = FDataModule. GetUsuario( AIDUser) ;
if Assigned( AUser) then
begin
AUser. Active : = True ;
2008-11-13 13:10:32 +00:00
AEditor : = TfEditorCambiarPassword. Create( NIL ) ;
try
AEditor. Controller : = Self;
AEditor. Usuario : = AUser;
AEditor. CambioObligatorio : = False ;
if ( Length( Trim( AUser. PASS) ) = 0 ) then
AEditor. EditAtu. Enabled : = False ;
if ( AEditor. ShowModal = mrOk) then
Result : = CambiarPassword( AIDUser, AEditor. EditNova. Text ) ;
finally
AEditor. Release;
AUser. Active : = False ;
AUser : = NIL ;
end ;
2008-01-13 21:37:20 +00:00
end ;
2007-10-09 07:47:51 +00:00
end ;
2007-10-08 07:58:40 +00:00
function TUsuariosController. ComprobarUsuario( const User,
Password: String ) : Boolean ;
begin
2008-01-15 17:07:23 +00:00
Result : = FUserControl. VerificaLogin( User, Password) ;
if not Result then
2008-03-04 09:52:02 +00:00
begin
if User = 'admin' then
begin
if not FUserControl. ExisteUsuario( 'admin' ) then
begin
FUserControl. AddUser( 'admin' , '1' , 'Administrador' , 'admin@correo.net' , 0 , 0 , 3 0 , True ) ;
Result : = ComprobarUsuario( User, Password) ;
end ;
end ;
2008-01-15 18:26:46 +00:00
end ;
2007-10-08 07:58:40 +00:00
end ;
2007-10-03 16:03:28 +00:00
constructor TUsuariosController. Create;
begin
2008-11-10 19:38:27 +00:00
inherited ;
2007-10-03 16:03:28 +00:00
AsignarDataModule;
2008-01-15 18:26:46 +00:00
FCurrentUser : = NIL ;
2007-10-03 16:03:28 +00:00
FUserControl : = TUserControl. Create( nil ) ;
2008-02-07 22:54:05 +00:00
FUsarPasswordsSeguras : = False ;
2007-10-03 16:03:28 +00:00
InicializarUserControl;
end ;
function TUsuariosController. CreateEditor( const AName: String ; const IID: TGUID; out Intf) : Boolean ;
begin
Result : = Supports( EditorRegistry. CreateEditor( AName) , IID, Intf) ;
end ;
2008-01-13 21:37:20 +00:00
function TUsuariosController. DarListaPerfilesUsuario: TStringList;
var
APerfilesUsuario: IBizPerfilUsuario;
begin
APerfilesUsuario : = FDataModule. GetPerfiles;
APerfilesUsuario. DataTable. Active : = True ;
Result : = TStringList. Create;
try
with Result do
begin
APerfilesUsuario. DataTable. First;
while not APerfilesUsuario. DataTable. EOF do
begin
Add( Format( '%s=%d' , [ APerfilesUsuario. USERNAME, APerfilesUsuario. ID] ) ) ;
APerfilesUsuario. DataTable. Next;
end ;
end ;
finally
APerfilesUsuario : = NIL ;
end ;
end ;
2008-01-15 17:07:23 +00:00
function TUsuariosController. DarListaUsuarios: TStringList;
var
AUsuarios: IBizUsuario;
begin
AUsuarios : = FDataModule. GetUsuarios;
AUsuarios. DataTable. Active : = True ;
Result : = TStringList. Create;
try
with Result do
begin
AUsuarios. DataTable. First;
while not AUsuarios. DataTable. EOF do
begin
Add( Format( '%s=%d' , [ AUsuarios. USERNAME, AUsuarios. ID] ) ) ;
AUsuarios. DataTable. Next;
end ;
end ;
finally
AUsuarios : = NIL ;
end ;
end ;
2007-10-03 16:03:28 +00:00
destructor TUsuariosController. Destroy;
begin
2007-10-22 07:39:39 +00:00
FreeAndNIL( FUserControl) ;
2007-10-03 16:03:28 +00:00
FDataModule : = NIL ;
2008-11-10 19:38:27 +00:00
FCurrentUser : = NIL ;
2008-01-13 21:37:20 +00:00
2007-10-03 16:03:28 +00:00
inherited ;
end ;
2007-10-09 07:47:51 +00:00
2008-01-13 21:37:20 +00:00
function TUsuariosController. EliminarPerfil(
APerfil: IBizPerfilUsuario) : Boolean ;
var
CanDelete: Boolean ;
ErrorMsg: String ;
begin
Result : = False ;
if not Assigned( APerfil) then
raise Exception. Create( 'No hay perfil asignado (EliminarPerfil)' ) ;
if not APerfil. Active then
APerfil. Active : = True ;
if APerfil. DataTable. RecordCount = 0 then
Exit;
if HayUsuarioConPerfil( APerfil. ID) then
begin
//changed by fduenas: PromptDelete_WindowCaption
if MessageBox( Application. Handle, PChar( Format( FUserControl. UserSettings. UsersProfile. PromptDelete, [ APerfil. USERNAME] ) ) ,
PChar( FUserControl. UserSettings. UsersProfile. PromptDelete_WindowCaption) , MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON2) < > idYes then
Exit;
end ;
CanDelete : = True ;
if Assigned( FUserControl. onDeleteProfile) then
FUserControl. onDeleteProfile( NIL , APerfil. ID, CanDelete, ErrorMsg) ;
if not CanDelete then
begin
MessageDlg( ErrorMSG, mtWarning, [ mbOK] , 0 ) ;
Exit;
end ;
with FUserControl do
begin
DataConnector. UCExecSQL( 'Delete from ' + TableUsers. TableName + ' where ' + TableUsers. FieldUserID + ' = ' + IntToStr( APerfil. ID) ) ;
DataConnector. UCExecSQL( 'Delete from ' + TableRights. TableName + ' where ' + TableRights. FieldUserID + ' = ' + IntToStr( APerfil. ID) ) ;
DataConnector. UCExecSQL( 'Delete from ' + TableRights. TableName + 'EX where ' + TableRights. FieldUserID + ' = ' + IntToStr( APerfil. ID) ) ;
DataConnector. UCExecSQL( 'Update ' + TableUsers. TableName +
' Set ' + TableUsers. FieldProfile + ' = null where ' + TableUsers. FieldUserID + ' = ' + IntToStr( APerfil. ID) ) ;
end ;
Result : = True ;
end ;
function TUsuariosController. EliminarPerfil( const AIDPerfil: integer ) : Boolean ;
begin
Result : = EliminarPerfil( FDataModule. GetPerfil( AIDPerfil) ) ;
end ;
function TUsuariosController. EliminarUsuario( AUser: IBizUsuario) : Boolean ;
begin
2008-05-14 14:38:09 +00:00
Result : = False ;
2008-01-13 21:37:20 +00:00
if not Assigned( AUser) then
raise Exception. Create( 'No hay usuario asignado (EliminarUsuario)' ) ;
if not AUser. Active then
AUser. Active : = True ;
if AUser. DataTable. RecordCount > 0 then
Result : = EliminarUsuario( AUser. ID) ;
end ;
function TUsuariosController. EliminarUsuario( const AIDUser: integer ) : Boolean ;
begin
FUserControl. DataConnector. UCExecSQL( 'Delete from ' + FUserControl. TableRights. TableName + ' where ' + FUserControl. TableRights. FieldUserID + ' = ' + IntToStr( AIDUser) ) ;
FUserControl. DataConnector. UCExecSQL( 'Delete from ' + FUserControl. TableUsers. TableName + ' where ' + FUserControl. TableUsers. FieldUserID + ' = ' + IntToStr( AIDUser) ) ;
Result : = True ;
end ;
function TUsuariosController. GetCriptografia: TUCCriptografia;
begin
case FUserControl. Criptografia of
cPadrao: Result : = ucStandard;
cMD5: Result : = ucMD5;
2008-05-14 14:38:09 +00:00
else
Result : = ucStandard;
2008-01-13 21:37:20 +00:00
end ;
end ;
2008-01-15 18:26:46 +00:00
function TUsuariosController. GetCurrentUser: IBizUsuario;
2007-10-09 07:47:51 +00:00
begin
2008-01-15 18:26:46 +00:00
if not Assigned( FCurrentUser) or ( FCurrentUser. ID < > FUserControl. CurrentUser. UserID) then
FCurrentUser : = BuscarUsuario( FUserControl. CurrentUser. UserID) ;
2008-01-15 19:12:44 +00:00
if not FCurrentUser. Active then
FCurrentUser. Active : = True ;
2008-01-15 18:26:46 +00:00
Result : = FCurrentUser;
2007-10-09 07:47:51 +00:00
end ;
2007-10-08 07:58:40 +00:00
function TUsuariosController. GetMaxIntentosLogin: Integer ;
begin
Result : = FUserControl. Login. MaxLoginAttempts;
end ;
2008-02-07 22:54:05 +00:00
function TUsuariosController. GetUsarPasswordsSeguras: Boolean ;
begin
Result : = FUsarPasswordsSeguras;
end ;
2008-01-13 21:37:20 +00:00
function TUsuariosController. GuardarPerfil( APerfil: IBizPerfilUsuario) : Boolean ;
begin
if not Assigned( APerfil) then
raise Exception. Create( 'No hay perfil asignado (GuardarPerfil)' ) ;
if APerfil. EsNuevo then
Result : = AnadirPerfil( APerfil)
else
Result : = ModificarPerfil( APerfil) ;
end ;
function TUsuariosController. GuardarUsuario( AUser: IBizUsuario) : Boolean ;
begin
if not Assigned( AUser) then
raise Exception. Create( 'No hay usuario asignado (GuardarUsuario)' ) ;
if AUser. EsNuevo then
Result : = AnadirUsuario( AUser)
else
Result : = ModificarUsuario( AUser) ;
end ;
function TUsuariosController. HayUsuarioConPerfil(
const AIDPerfil: integer ) : Boolean ;
var
TempDS: TDataset;
begin
try
TempDS : = FUserControl. DataConnector. UCGetSQLDataset( 'Select ' + FUserControl. TableUsers. FieldUserID + ' as IdUser from ' +
FUserControl. TableUsers. TableName +
' Where ' + FUserControl. TableUsers. FieldTypeRec + ' = ' + QuotedStr( 'U' ) +
' AND ' + FUserControl. TableUsers. FieldProfile + ' = ' + IntToStr( AIDPerfil) ) ;
Result : = ( TempDS. FieldByName( 'IdUser' ) . AsInteger > 0 ) ;
TempDS. Close;
finally
FreeAndNil( TempDS) ;
end ;
end ;
2007-10-03 16:03:28 +00:00
procedure TUsuariosController. InicializarUserControl;
begin
with FUserControl do
begin
2007-10-09 07:47:51 +00:00
ApplicationID : = AppFactuGES. AppName;
2007-10-03 16:03:28 +00:00
AutoStart : = False ;
2007-10-08 07:58:40 +00:00
Criptografia : = cMD5;
2007-10-09 07:47:51 +00:00
CheckValidationKey : = True ;
Login. MaxLoginAttempts : = 3 ;
2008-01-13 21:37:20 +00:00
UserPasswordChange. ForcePassword : = True ;
UserPasswordChange. MinPasswordLength : = 3 ;
2007-10-03 16:03:28 +00:00
end ;
2007-10-09 07:47:51 +00:00
FDataModule. InicializarUserControl( FUserControl) ;
2007-10-08 07:58:40 +00:00
end ;
procedure TUsuariosController. Logoff;
begin
FUserControl. Logoff;
end ;
2008-01-13 21:37:20 +00:00
function TUsuariosController. ModificarPerfil(
APerfil: IBizPerfilUsuario) : Boolean ;
begin
Result : = False ;
if not Assigned( APerfil) then
raise Exception. Create( 'No hay perfil asignado (ModificarPerfil)' ) ;
if ValidarPerfil( APerfil) then
begin
ShowHourglassCursor;
try
with FUserControl do
begin
DataConnector. UCExecSQL( Format( 'UPDATE %s SET %s = %s WHERE %s = %d' ,
[ TableUsers. TableName,
TableUsers. FieldUserName,
QuotedStr( APerfil. USERNAME) ,
TableUsers. FieldUserID,
APerfil. ID] ) ) ;
end ;
Result : = True ;
finally
HideHourglassCursor;
end ;
end ;
end ;
function TUsuariosController. ModificarUsuario( AUser: IBizUsuario) : Boolean ;
begin
Result : = False ;
if not Assigned( AUser) then
raise Exception. Create( 'No hay usuario asignado (ModificarUsuario)' ) ;
if ValidarUsuario( AUser) then
begin
ShowHourglassCursor;
try
FUserControl. ChangeUser( AUser. ID, AUser. LOGIN, AUser. USERNAME, AUser. EMAIL,
AUser. ID_PERFIL, AUser. BLOQUEADO , AUser. USERDAYSSUN, ( AUser. PRIVILEGED = 1 ) ) ;
Result : = True ;
{ TODO -oLuiz -cUpgrade : Consertar a Senha para poder avisar MD5 }
{ if ( Assigned( MailUserControl) ) and ( MailUserControl. AlteraUsuario. Ativo) then
try
MailUserControl. EnviaEmailAlteraUsuario( vNome,
vLogin,
TfrmCadastrarUsuario( Self. Owner) . FDataSetCadastroUsuario. FieldByName( 'SENHA' ) . AsString,
vEmail,
IntToStr( vPerfil) ,
EncryptKey) ;
except
on E: Exception do
Log( E. Message , 2 ) ;
end ; }
finally
HideHourglassCursor;
end ;
end ;
end ;
function TUsuariosController. NuevoPerfil: IBizPerfilUsuario;
var
APerfil : IBizPerfilUsuario;
begin
APerfil : = FDataModule. NuevoPerfil;
APerfil. DataTable. Active : = True ;
APerfil. Insert;
Result : = APerfil;
end ;
function TUsuariosController. NuevoUsuario: IBizUsuario;
var
AUsuario : IBizUsuario;
begin
AUsuario : = FDataModule. NuevoUsuario;
AUsuario. DataTable. Active : = True ;
AUsuario. Insert;
Result : = AUsuario;
end ;
2007-10-03 16:03:28 +00:00
procedure TUsuariosController. RecibirAviso( ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable) ;
begin
inherited ;
//
end ;
2007-10-08 07:58:40 +00:00
procedure TUsuariosController. SetMaxIntentosLogin( const Value: Integer ) ;
begin
FUserControl. Login. MaxLoginAttempts : = Value;
end ;
2008-02-07 22:54:05 +00:00
procedure TUsuariosController. SetUsarPasswordsSeguras( const Value: Boolean ) ;
begin
FUsarPasswordsSeguras : = Value;
end ;
2008-01-13 21:37:20 +00:00
procedure TUsuariosController. _ShowChangePassword;
2007-10-08 07:58:40 +00:00
begin
FUserControl. ShowChangePassword;
end ;
2008-01-13 21:37:20 +00:00
procedure TUsuariosController. _ShowLogManager;
2007-10-08 07:58:40 +00:00
begin
FUserControl. ShowLogManager;
end ;
2008-01-13 21:37:20 +00:00
procedure TUsuariosController. _ShowProfileManager;
2007-10-08 07:58:40 +00:00
begin
FUserControl. ShowProfileManager;
end ;
2008-01-13 21:37:20 +00:00
function TUsuariosController. ValidarPassword( const APassword : string ;
const ALogin : String ; const ANombre: String ; out AMsg : String ) : boolean ;
begin
Result : = False ;
AMsg : = '' ;
if ( FUserControl. UserPasswordChange. ForcePassword) and ( Length( Trim( APassword) ) = 0 ) then
AMsg : = FUserControl. UserSettings. CommonMessages. ChangePasswordError. PasswordRequired
else
if ( Length( Trim( APassword) ) < FUserControl. UserPasswordChange. MinPasswordLength) then
AMsg : = Format( FUserControl. UserSettings. CommonMessages. ChangePasswordError. MinPasswordLength, [ FUserControl. UserPasswordChange. MinPasswordLength] )
else
2008-02-07 22:54:05 +00:00
if FUsarPasswordsSeguras and ( Pos( LowerCase( APassword) , 'abcdeasdfqwerzxcv1234567890321654987test' + LowerCase( ALogin) + LowerCase( AMsg) ) > 0 ) then
2008-01-13 21:37:20 +00:00
AMsg : = FUserControl. UserSettings. CommonMessages. ChangePasswordError. InvalidNewPassword
else
Result : = true ;
end ;
function TUsuariosController. ValidarPerfil( APerfil: IBizPerfilUsuario) : Boolean ;
begin
if not Assigned( APerfil) then
raise Exception. Create ( 'Perfil no asignado (ValidarPerfil)' ) ;
if ( APerfil. DataTable. State in dsEditModes) then
APerfil. DataTable. Post;
if Length( APerfil. USERNAME) = 0 then
raise Exception. Create( 'Debe indicar el nombre del perfil.' ) ;
Result : = True ;
end ;
function TUsuariosController. ValidarUsuario( AUser: IBizUsuario) : Boolean ;
begin
if not Assigned( AUser) then
raise Exception. Create ( 'Usuario no asignado (ValidarUsuario)' ) ;
if ( AUser. DataTable. State in dsEditModes) then
AUser. DataTable. Post;
if Length( AUser. USERNAME) = 0 then
raise Exception. Create( 'Debe indicar el nombre completo del usuario.' ) ;
if Length( AUser. LOGIN) = 0 then
raise Exception. Create( 'Debe indicar un login para el usuario.' ) ;
Result : = True ;
end ;
procedure TUsuariosController. VerPerfil( const AIDPerfil: Integer ) ;
var
FPerfil : IBizPerfilUsuario;
begin
FPerfil : = FDataModule. GetPerfil( AIDPerfil) ;
VerPerfil( FPerfil) ;
end ;
procedure TUsuariosController. VerPerfil( APerfil: IBizPerfilUsuario) ;
var
AEditor : IEditorPerfilUsuario;
begin
if not Assigned( APerfil) then
raise Exception. Create( 'Perfil no asignado (VerPerfil)' ) ;
APerfil. Active : = True ;
2008-11-11 16:22:18 +00:00
CreateEditor( 'EditorPerfilUsuario' , IEditorPerfilUsuario, AEditor) ;
if Assigned( AEditor) then
begin
2008-11-13 13:10:32 +00:00
try
AEditor. Controller : = Self; //OJO ORDEN MUY IMPORTANTE
AEditor. PerfilUsuario : = APerfil;
AEditor. ShowModal;
finally
AEditor. Release;
AEditor : = NIL ;
2008-11-11 16:22:18 +00:00
end ;
2008-01-13 21:37:20 +00:00
end ;
end ;
procedure TUsuariosController. VerPerfiles;
var
AEditor : IEditorPerfilesUsuario;
APerfilesUsuario: IBizPerfilUsuario;
begin
APerfilesUsuario : = FDataModule. GetPerfiles;
if Assigned( APerfilesUsuario) then
begin
try
2008-11-11 16:22:18 +00:00
APerfilesUsuario. Active : = True ;
2008-01-13 21:37:20 +00:00
CreateEditor( 'EditorPerfilesUsuario' , IEditorPerfilesUsuario, AEditor) ;
if Assigned( AEditor) then
2008-11-13 13:10:32 +00:00
try
AEditor. Controller : = Self; //OJO ORDEN MUY IMPORTANTE
AEditor. PerfilesUsuario : = APerfilesUsuario;
AEditor. ShowModal;
finally
AEditor. Release;
AEditor : = NIL ;
2008-11-11 16:22:18 +00:00
end ;
2008-01-13 21:37:20 +00:00
finally
APerfilesUsuario : = NIL ;
end ;
end ;
end ;
procedure TUsuariosController. VerUsuario( const AIDUser: Integer ) ;
var
FUsuario : IBizUsuario;
begin
FUsuario : = FDataModule. GetUsuario( AIDUser) ;
VerUsuario( FUsuario) ;
end ;
procedure TUsuariosController. VerUsuario( AUser: IBizUsuario) ;
var
AEditor : IEditorUsuario;
begin
if not Assigned( AUser) then
raise Exception. Create( 'Usuario no asignado (VerUsuario)' ) ;
AUser. Active : = True ;
2008-11-11 16:22:18 +00:00
CreateEditor( 'EditorUsuario' , IEditorUsuario, AEditor) ;
if Assigned( AEditor) then
2008-11-13 13:10:32 +00:00
try
AEditor. Controller : = Self; //OJO ORDEN MUY IMPORTANTE
AEditor. Usuario : = AUser;
AEditor. ShowModal;
finally
AEditor. Release;
AEditor : = NIL ;
end ;
2008-01-13 21:37:20 +00:00
end ;
procedure TUsuariosController. VerUsuarios;
var
AEditor : IEditorUsuarios;
FUsuarios : IBizUsuario;
begin
FUsuarios : = FDataModule. GetUsuarios;
if Assigned( FUsuarios) then
begin
FUsuarios. Active : = True ;
try
CreateEditor( 'EditorUsuarios' , IEditorUsuarios, AEditor) ;
if Assigned( AEditor) then
2008-11-13 13:10:32 +00:00
try
AEditor. Controller : = Self; //OJO ORDEN MUY IMPORTANTE
AEditor. Usuarios : = FUsuarios;
AEditor. ShowModal;
finally
AEditor. Release;
AEditor : = NIL ;
end ;
2008-01-13 21:37:20 +00:00
finally
FUsuarios : = NIL ;
end ;
end ;
end ;
procedure TUsuariosController. _ShowUserManager;
2007-10-08 07:58:40 +00:00
begin
FUserControl. ShowUserManager;
end ;
function TUsuariosController. StartLogin : Boolean ;
var
AEditor : IEditorLogin;
begin
2007-11-08 20:58:47 +00:00
Result : = False ;
2007-10-08 07:58:40 +00:00
AEditor : = NIL ;
2008-11-11 16:22:18 +00:00
CreateEditor( 'EditorLogin' , IEditorLogin, AEditor) ;
if Assigned( AEditor) then
2008-11-13 13:10:32 +00:00
try
AEditor. Controller : = Self;
Result : = ( AEditor. ShowModal = mrOk) ;
finally
AEditor. Release;
AEditor : = NIL ;
end ;
2007-10-08 07:58:40 +00:00
end ;
2008-01-15 17:07:23 +00:00
procedure TUsuariosController. FiltrarEmpresa( AUsuario: IBizUsuario) ;
2008-05-14 14:38:09 +00:00
{ var
Condicion: TDAWhereExpression; }
2008-01-15 17:07:23 +00:00
begin
// AQUI HAY QUE TENER EN CUENTA QUE UN USUARIO PUEDE QUE NO TENGA ACCESO
// EN UNA DETERMINADA EMPRESA
{ if AUsuario. DataTable. Active then
AUsuario. DataTable. Active : = False ;
// Filtrar los contactos actuales por empresa
with AUsuario. DataTable. DynamicWhere do
begin
Condicion : = NewBinaryExpression( NewField( '' , fld_U
ContactosID_EMPRESA) , NewConstant( AppFactuGES. EmpresaActiva. ID, datInteger) , dboEqual) ;
if IsEmpty then
Expression : = Condicion
else
Expression : = NewBinaryExpression( Expression, Condicion, dboAnd) ;
end ; }
end ;
2007-10-03 16:03:28 +00:00
end .