THYUserProfile

Overview

The THYUserProfile is a class that is used to manage user profile and plugin privileges.

Use Cases

There is two possible way to use THYUserProfile:

  • Control user profile and login procedures.
  • Control plugin privilages check.

For example, this OnProcessLogin event handler performs a login check and assigns a proper privilages:

procedure TMainData.UserProfileProcessLogin(Sender: THYUserProfile;
  const aUserID, aPassword: String; var LoginResult: THYLoginResult);
begin
  LoginResult := lrFailed;

 //password check
  if SameText(aUserId, aPassword) then
    LoginResult := lrOK;

 //privilages
  if LoginResult = lrOK then begin
    if SameText(aUserId, 'jhon') then
      Sender.Privilages := 'read,write'
    else
       Sender.Privilages := 'read';
  end;
end;

To see this in action, please take a look at the Security sample that is shipped with Hydra.

Location

  • Unit: Hydra.VCL.UserProfile.pas
  • Ancestry: TComponent | THYUserProfile

 

constructor Create  override

Creates a new instance of the class.

constructor Create(aOwner: TComponent)

Parameters:

  • aOwner: Reference to the owner object.

Attributes

Stores collection of a custom attributes.

property Attributes: THYUserProfileAttributes read write

AutoHideMainForm

Gets or sets value that indicates whether main form will be hidden during login procedure.

property AutoHideMainForm: Boolean read write

AutoTerminateIfLoginFails

Gets or sets value that control whether application will be terminated if login procedure fails.

property AutoTerminateIfLoginFails: Boolean read write

DisplayCurrentUserID

Gets or sets value that indicates whether user identifier will be displayed in the login form on startup.

property DisplayCurrentUserID: Boolean read write

GetAttributeValue

Reads a value of an attribute with specified name, if this attribute is not available then returns default value.

function GetAttributeValue(const anAttributeName: string; const DefaultValue: string): Variant

Parameters:

  • anAttributeName: Name of the attribute.
  • DefaultValue: Default value of the attribute.

HasPrivilege

Checkes whether this has specified privilege.

function HasPrivilege(const aPrivilege: string): Boolean

Parameters:

  • aPrivilege: Custom privilage.

Login (TFormClass): THYLoginResult  overload

Initiates login procedure with a custom login form. Note: Login form must implemnet IHYLoginForm interface.

function Login(aFormClass: TFormClass): THYLoginResult

Parameters:

  • aFormClass: Class of the login form.

Login (string, string): THYLoginResult  overload

Initiates login procedure with specified ID and password.

function Login(const aUserID: string; const aPassword: string): THYLoginResult

Parameters:

  • aUserID: User identified.
  • aPassword: User password.

MaxLoginAttempts

Gets or sets value that controls number of the login attemtps.

property MaxLoginAttempts: Integer read write

OnAfterDisplayLoginForm

Event handler that is triggered after login form is displayed.

property OnAfterDisplayLoginForm: THYAfterLoginEvent read write
delegate: procedure OnAfterDisplayLoginForm(Sender: THYUserProfile; var LoginResult: THYLoginResult)

OnAfterProcessLogin

Event handler that is triggered after login procedure complets.

property OnAfterProcessLogin: THYAfterLoginEvent read write
delegate: procedure OnAfterProcessLogin(Sender: THYUserProfile; var LoginResult: THYLoginResult)

OnBeforeDisplayLoginForm

Event handler that is triggered before login form is displayed.

property OnBeforeDisplayLoginForm: THYBeforeLoginEvent read write
delegate: procedure OnBeforeDisplayLoginForm(Sender: THYUserProfile; const aUserID: string; const aPassword: string)

OnBeforeProcessLogin

Event handler that is triggered before login procedure is initiated.

property OnBeforeProcessLogin: THYBeforeLoginEvent read write
delegate: procedure OnBeforeProcessLogin(Sender: THYUserProfile; const aUserID: string; const aPassword: string)

OnChangePrivileges

This event is fired whenever privilages changed.

property OnChangePrivileges: THYUserProfileNotifyEvent read write
delegate: procedure OnChangePrivileges(Sender: THYUserProfile)

OnChangeUserID

This event is fired whenever user identifier changed.

property OnChangeUserID: THYUserProfileNotifyEvent read write
delegate: procedure OnChangeUserID(Sender: THYUserProfile)

OnProcessLogin

This event handler is called by the Login method and allows to perform login procedure.

property OnProcessLogin: THYLoginEvent read write
delegate: procedure OnProcessLogin(Sender: THYUserProfile; const aUserID: string; const aPassword: string; var LoginResult: THYLoginResult)

Privileges

Gets or sets a comma separated string that stores available privileges.

property Privileges: string read write

SetPrivilegeList

Assigns specified string array to available privilages

procedure SetPrivilegeList(const aPrivilegeList: array of string)

Parameters:

  • aPrivilegeList: String array that holds custom privilages.

UserID

Gets or sets user identifier.

property UserID: string read write

 

Attributes

Stores collection of a custom attributes.

property Attributes: THYUserProfileAttributes read write

AutoHideMainForm

Gets or sets value that indicates whether main form will be hidden during login procedure.

property AutoHideMainForm: Boolean read write

AutoTerminateIfLoginFails

Gets or sets value that control whether application will be terminated if login procedure fails.

property AutoTerminateIfLoginFails: Boolean read write

DisplayCurrentUserID

Gets or sets value that indicates whether user identifier will be displayed in the login form on startup.

property DisplayCurrentUserID: Boolean read write

MaxLoginAttempts

Gets or sets value that controls number of the login attemtps.

property MaxLoginAttempts: Integer read write

Privileges

Gets or sets a comma separated string that stores available privileges.

property Privileges: string read write

UserID

Gets or sets user identifier.

property UserID: string read write

 

constructor Create  override

Creates a new instance of the class.

constructor Create(aOwner: TComponent)

Parameters:

  • aOwner: Reference to the owner object.

GetAttributeValue

Reads a value of an attribute with specified name, if this attribute is not available then returns default value.

function GetAttributeValue(const anAttributeName: string; const DefaultValue: string): Variant

Parameters:

  • anAttributeName: Name of the attribute.
  • DefaultValue: Default value of the attribute.

HasPrivilege

Checkes whether this has specified privilege.

function HasPrivilege(const aPrivilege: string): Boolean

Parameters:

  • aPrivilege: Custom privilage.

Login (TFormClass): THYLoginResult  overload

Initiates login procedure with a custom login form. Note: Login form must implemnet IHYLoginForm interface.

function Login(aFormClass: TFormClass): THYLoginResult

Parameters:

  • aFormClass: Class of the login form.

Login (string, string): THYLoginResult  overload

Initiates login procedure with specified ID and password.

function Login(const aUserID: string; const aPassword: string): THYLoginResult

Parameters:

  • aUserID: User identified.
  • aPassword: User password.

SetPrivilegeList

Assigns specified string array to available privilages

procedure SetPrivilegeList(const aPrivilegeList: array of string)

Parameters:

  • aPrivilegeList: String array that holds custom privilages.

 

OnAfterDisplayLoginForm

Event handler that is triggered after login form is displayed.

property OnAfterDisplayLoginForm: THYAfterLoginEvent read write
delegate: procedure OnAfterDisplayLoginForm(Sender: THYUserProfile; var LoginResult: THYLoginResult)

OnAfterProcessLogin

Event handler that is triggered after login procedure complets.

property OnAfterProcessLogin: THYAfterLoginEvent read write
delegate: procedure OnAfterProcessLogin(Sender: THYUserProfile; var LoginResult: THYLoginResult)

OnBeforeDisplayLoginForm

Event handler that is triggered before login form is displayed.

property OnBeforeDisplayLoginForm: THYBeforeLoginEvent read write
delegate: procedure OnBeforeDisplayLoginForm(Sender: THYUserProfile; const aUserID: string; const aPassword: string)

OnBeforeProcessLogin

Event handler that is triggered before login procedure is initiated.

property OnBeforeProcessLogin: THYBeforeLoginEvent read write
delegate: procedure OnBeforeProcessLogin(Sender: THYUserProfile; const aUserID: string; const aPassword: string)

OnChangePrivileges

This event is fired whenever privilages changed.

property OnChangePrivileges: THYUserProfileNotifyEvent read write
delegate: procedure OnChangePrivileges(Sender: THYUserProfile)

OnChangeUserID

This event is fired whenever user identifier changed.

property OnChangeUserID: THYUserProfileNotifyEvent read write
delegate: procedure OnChangeUserID(Sender: THYUserProfile)

OnProcessLogin

This event handler is called by the Login method and allows to perform login procedure.

property OnProcessLogin: THYLoginEvent read write
delegate: procedure OnProcessLogin(Sender: THYUserProfile; const aUserID: string; const aPassword: string; var LoginResult: THYLoginResult)