NAME
Kernel::System::User – user lib
DESCRIPTION
All user functions. E. g. to add and updated user and other functions.
PUBLIC INTERFACE
BUILD()
Moose constructor method, that is executed on instantiation
of the object. During the instantiation
of the object, the event handling will be initialized.
GetUserData()
get user data (UserLogin, UserFirstname, UserLastname, UserEmail, …)
my %User = $UserObject->GetUserData(
UserID => 123,
);
or
my %User = $UserObject->GetUserData(
User => 'franz',
Valid => 1, # not required -> 0|1 (default 0)
# returns only data if user is valid
NoOutOfOffice => 1, # not required -> 0|1 (default 0)
# returns data without out of office infos
NoSensitive => 1, # not required -> 0|1 (default 0)
# returns data without sensitive infos
AvatarFile => 1, # not required -> 0|1 (default 0)
# returns Avatar image content if present
);
UserAdd()
to add new users
my $UserID = $UserObject->UserAdd(
UserFirstname => 'Huber',
UserLastname => 'Manfred',
UserLogin => 'mhuber',
UserPw => 'some-pass', # not required
UserEmail => 'email@example.com',
UserMobile => '1234567890', # not required
ValidID => 1,
ChangeUserID => 123,
EncryptPw => 1 # (optional) default 1
);
UserUpdate()
to update users
$UserObject->UserUpdate(
UserID => 4321,
UserFirstname => 'Huber',
UserLastname => 'Manfred',
UserLogin => 'mhuber',
UserPw => 'some-pass', # not required
UserEmail => 'email@example.com',
UserMobile => '1234567890', # not required
ValidID => 1,
ChangeUserID => 123,
EncryptPw => 1 # (optional) default 1
);
UserSearch()
to search users
my %List = $UserObject->UserSearch(
Search => '*some*', # also 'hans+huber' possible
Valid => 1, # not required
);
my %List = $UserObject->UserSearch(
UserLogin => '*some*',
Limit => 50,
Valid => 1, # not required
);
my %List = $UserObject->UserSearch(
PostMasterSearch => 'email@example.com',
Valid => 1, # not required
);
Returns hash of UserID, Login pairs:
my %List = (
1 => 'root@locahost',
4 => 'admin',
9 => 'joe',
);
For PostMasterSearch, it returns hash of UserID, Email pairs:
my %List = (
4 => 'john@example.com',
9 => 'joe@example.com',
);
SetPassword()
to set users passwords
$UserObject->SetPassword(
UserLogin => 'some-login',
PW => 'some-new-password',
SetPasswordLastSetTime => 1, # (optional) default 1
Encrypt => 1, # (optional) default 1
);
EncryptPassword()
To encrypt the password with the current configured encryption.
$UserObject->EncryptPassword(
UserLogin => 'tt',
PW => 'some-new-password',
);
Returns the encrypted password hash.
IsPasswordChangeable()
Check if the password is changeable for the current user.
my $PasswordChangeable = $UserObject->IsPasswordChangeable(
UserLogin => 'some-login',
);
Return true if the password is changeable and otherwise false.
GetPasswordPolicyRules()
Collect the current password policy for the given user.
my %PasswordPolicyRules = $UserObject->GetPasswordPolicyRules(
UserLogin => 'agent', # optional
);
Returns hash ref of the current password policy rules.
%PasswordPolicyRules = {
PasswordMinSize => 8,
PasswordMin2Lower2UpperCharacters => 1,
PasswordNeedDigit => 1,
};
CheckPasswordHistory()
Check the password history for a new password.
my $Result = $UserObject->CheckPasswordHistory(
UserLogin => 'tt',
NewPassword => 'test-password',
);
Returns true if the password is allowed and false, if the password was already used in the last time.
UpdatePasswordHistory()
Update the password history for a new crypt password, if needed.
my $Result = $UserObject->UpdatePasswordHistory(
UserLogin => 'tt',
NewCryptedPassword => 'crypted-password',
or
NewPassword => 'test-password',
);
Returns true if the password history was updated and false if not.
UserLookup()
user login or id lookup
my $UserLogin = $UserObject->UserLookup(
UserID => 1,
Silent => 1, # optional, don't generate log entry if user was not found
);
my $UserID = $UserObject->UserLookup(
UserLogin => 'some_user_login',
Silent => 1, # optional, don't generate log entry if user was not found
);
UserName()
get user name
my $Name = $UserObject->UserName(
User => 'some-login',
);
or
my $Name = $UserObject->UserName(
UserID => 123,
);
UserList()
return a hash with all users
my %List = $UserObject->UserList(
Type => 'Short', # Short|Long, default Short
Valid => 1, # default 1
NoOutOfOffice => 1, # (optional) default 0
);
returns:
# Type = 'Short'
%List = (
"1" => "root\@localhost",
"2" => "jdoe",
...
);
# or
# Type = 'Long'
%List = (
"1" => "Admin OTRS",
"2" => "John Doe",
...
);
GenerateRandomPassword()
generate a random password
my $Password = $UserObject->GenerateRandomPassword();
or
my $Password = $UserObject->GenerateRandomPassword(
Size => 16,
);
SetPreferences()
set user preferences
$UserObject->SetPreferences(
Key => 'UserComment',
Value => 'some comment',
UserID => 123,
SkipPushEvent => 1,
);
GetPreferences()
get user preferences
my %Preferences = $UserObject->GetPreferences(
UserID => 123,
);
SearchPreferences()
search in user preferences
my %UserList = $UserObject->SearchPreferences(
Key => 'UserEmail',
Value => 'email@example.com', # optional, limit to a certain value/pattern
Limit => 1000, # optional, limit the amount of result entries
Offset => 0, # optional, paginate the results
);
DeletePreferences()
delete keys from user preferences for users
my $Success = $UserObject->DeletePreferences(
Keys => ['AvatarLocation', 'UserComment', 'UserLastLogin', 'UserLoginFailed'],
UserIDs => [123, 456, 789],
SkipPushEvent => 1,
);
TokenGenerate()
generate a random token
my $Token = $UserObject->TokenGenerate(
UserID => 123,
);
TokenCheck()
check password token
my $Valid = $UserObject->TokenCheck(
Token => $Token,
UserID => 123,
);
GetAvatar()
get avatar image and store it into cache.
UserLoginExistsCheck()
return 1 if another user with this login (username) already exists
$Exist = $UserObject->UserLoginExistsCheck(
UserLogin => 'Some::UserLogin',
UserID => 1, # optional
);
UserLoginValid()
Determines if a given string parameter UserLogin is acceptable. Returns 1 if it is. Returns 0 otherwise.
This method should not be used if undef is to be accepted. This method considers undef as not acceptable.
my $IsValid = $UserObject->UserLoginIsValid(
UserLogin => 'someuserlogin',
);
GetUserOutOfOffice()
Returns the user out of office information already decoded.
Returns
{
Ranges => [...],
Active => {
Start => '...',
End => '...',
},
Message => '...',
}
_BuildOutOfOfficeInfo
Builds the user out of office information and returns it.
Returns
{
Ranges => [...],
Active => {
Start => '...',
End => '...',
},
Message => '...',
}
_AvatarFileGet()
Get user's avatar file content.
my $AvatarFile = $UserObject->_AvatarFileGet(
FileLocation => $Data{AvatarLocation},
);
Returns avatar file content:
$AvatarFile = '<binary-content>';
Please note this function will return an empty string in case not avatar file was found.