new $k.User(userInstance)
Constructs a user from the user instance
Name | Type | Description |
---|---|---|
userInstance |
$k.Instance |
User instance Represents a user. |
Methods
static$k.User.createUserAccount(name) : $k.User
Creates a new user account.
Currently, the active user must have administration rights. Note: Elevating the context with elevatedDo() does not grant administration rights.Name | Type | Description |
---|---|---|
name |
string |
The account name of the new user |
Throws:
Type | Description |
---|---|
$k.exception.AccessDenied | If new users cannot be created in this context. |
Returns:
Type | Description |
---|---|
$k.User | The new user |
static$k.User.getAuthenticatedUser() : $k.User
Finds, authenticates and returns the user.
Returns undefined if thre is either no such user, or if the password does not match.
- Version:
- Experimental feature, might be removed at any time
- Since:
- 5.0.1
Returns:
Type | Description |
---|---|
$k.User | The authenticated used, or undefined |
static$k.User.userAccount() : $k.User
Finds the user with the given account
- Since:
- 5.4.0
Returns:
Type | Description |
---|---|
$k.User | The user, or undefined if no such user exists |
accountName() : string
Returns the name of the account
- Since:
- 5.4.0
Returns:
Type | Description |
---|---|
string | The name, or undefined if there is no account |
changePassword(oldPassword, newPassword) : boolean
Changes the current users password
Name | Type | Description |
---|---|---|
oldPassword |
string |
The old password to be verified |
newPassword |
string |
The new password to set |
Throws:
Type | Description |
---|---|
$k.exception.AccessDenied | If the user object and transaction-user mismatch |
$k.exception.InvalidValue | If one of the provided passwords is undefined/null |
$k.exception.ObjectNotFound | If there is no current user set or no password attribute available |
Returns:
Type | Description |
---|---|
boolean | Return true if the password change was successful |
Example
try { result = $k.user().changePassword("oldsecret", "newsecret") }
catch(e) { error = e.toString() }
instance() : $k.Instance
Returns the instance associated with the user, or undefined if there is none
Returns:
Type | Description |
---|---|
$k.Instance |
isAdmin() : boolean
Returns true if the user has administration rights
- Since:
- 5.3.0
Returns:
Type | Description |
---|---|
boolean |
name() : string
Returns the name of the user
Returns:
Type | Description |
---|---|
string | The name of the user instance, or the name of the account if there is no associated instance |
setAccountPassword(password)
Sets the password of the user account
Name | Type | Description |
---|---|---|
password |
string |
- Since:
- 5.4.0
Throws:
Type | Description |
---|---|
$k.exception.AccessDenied | If the user cannot be modified in this context |
$k.exception.ObjectNotFound | If the user has no user account |
setInstance(instance)
Sets the instance associated with the user
Name | Type | Description |
---|---|---|
instance |
$k.Instance |
- Since:
- 5.4.0
Throws:
Type | Description |
---|---|
$k.exception.AccessDenied | If the user cannot be modified in this context |
$k.exception.ObjectNotFound | If the user has no user account |
setInstancePassword(password)
Sets the password of the user instance
Name | Type | Description |
---|---|---|
password |
string |
- Since:
- 5.4.0
Throws:
Type | Description |
---|---|
$k.exception.AccessDenied | If the user cannot be modified in this context |
$k.exception.ObjectNotFound | If the user has no user instance |
setIsAdmin(enable)
Enable/disable permanent administration rights
Name | Type | Description |
---|---|---|
enable |
boolean |
- Since:
- 5.4.0
Throws:
Type | Description |
---|---|
$k.exception.AccessDenied | If the user cannot be modified in this context |
$k.exception.ObjectNotFound | If the user has no user account |