User
Management of the users of the application and obtaining the data of the authenticated user.
all
_user.all() : java.util.List
Description
Gets the list of data for all users.
How To Use
// Returns all existing users.
_out.json(_user.all())
Return
( java.util.List )
List of all data for all users.
allByCode
_user.allByCode(code: string) : java.util.List
Description
Gets all users from the alternative code.
How To Use
// Lists users who have the sample code in the log.
const users = _user.allByCode("sample")
for (const user of users) {
_log.info(`User ${user.getString("name")}`)
}
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
code | string | Alternative code that users may have associated. |
Return
( java.util.List )
List of users found for the alternative code.
allProvidersData
_user.allProvidersData() : Values
Return
( Values )
_user.allProvidersData(userId: int) : Values
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
userId | int |
Return
( Values )
code
_user.code() : string
Description
Gets the alternative code of the user who is authenticated.
How To Use
// Auxiliary code of the authenticated user.
_log.info(`User Code: ${_user.code()}`)
Return
( string )
Auxiliary code of the logged user.
create
_user.create(dataUser: Values) : int
Description
Creates the new user.
How To Use
// Create a new user:
const group = _group.firstByCode("samle")_user.create(
_val.map()
.set("name", "Full Name")
.set("mail", "user@sample.com")
.set("user", "username")
.set("pass", "SecretPassword123")
.set("group_id", group.getInt("id"))
// It is optional to define an auxiliary alternative code:
.set("code", "example-alternative-identification")
)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
dataUser | Values | Data of the user to be created. |
Return
( int )
User ID that was created.
createIfNotExists
_user.createIfNotExists(userData: Values) : boolean
Description
Creates the user if it does not exist yet.
How To Use
// Create a new user if it doesn't exist yet:
const group = _group.firstByCode("generic")
_user.createIfNotExists(
_val.map()
.set("name", "Full Name")
.set("mail", "user@sample.com")
.set("user", "username")
.set("pass", "SecretPassword123")
.set("group_id", group.getInt("id"))
// It is optional to define an auxiliary alternative code:
.set("code", "example-alternative-identification")
)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
userData | Values | Data of the user to be created if it does not exist yet. |
Return
( boolean )
It was successfully created.
data
_user.data() : Values
Description
It obtains all the data information of the user who is authenticated.
How To Use
// All information of the authenticated user.
_out.json(_user.data())
Return
( Values )
All data of the logged user.
firstByCode
_user.firstByCode(code: string) : Values
Description
Gets a user's data from the alternate code.
How To Use
// User who has the sample code.
const user = _user.firstByCode("sample")
_out.json(user)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
code | string | Alternative code that the user may have associated. |
Return
( Values )
User data found with the alternative code.
firstByMail
_user.firstByMail(mail: string) : Values
Description
Retrieves a user's data from email.
How To Use
// User obtained from email.
const user = _user.firstByMail("user@example.com")
_out.json(user)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
string | User e-mail. |
Return
( Values )
User data found with the email.
firstByName
_user.firstByName(name: string) : Values
Description
Gets a user's data from the full name.
How To Use
// User who has the full name.
const user = _user.firstByName("Full Name")
_out.json(user)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
name | string | Full name of the user. |
Return
( Values )
User data found with full name.
firstByUser
_user.firstByUser(user: string) : Values
Description
It obtains a user's data from the user name, the same name used in the login.
How To Use
// User from username.
const user = _user.firstByMail("user@example.com")
_out.json(user)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
user | string | Username of the user. |
Return
( Values )
User data found with username.
get
_user.get(id: int) : Values
Description
Gets a user's data from the ID (numeric identifier).
How To Use
// User obtained from the ID.
const user = _user.get(1)
_out.json(user)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | Numeric identifier of the user. |
Return
( Values )
User data found.
_user.get(idOrUidOrUsername: string) : Values
Description
It obtains a user's data from the ID (numeric identifier), the UUID (universal unique identifier) or the user name.
How To Use
// User obtained from the UUID.
const user = _user.get("7901e01c-c53e-42c2-980d-9f928090422f")
_out.json(user)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
idOrUidOrUsername | string | It can be either an ID, or a UUID, or the username. |
Return
( Values )
User data found.
hasProvider
_user.hasProvider(userId: int, providerCode: string) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
userId | int | |
providerCode | string |
Return
( boolean )
_user.hasProvider(providerCode: string) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
providerCode | string |
Return
( boolean )
id
_user.id() : int
Description
Gets the numeric identifier of who is authenticated.
How To Use
// Authenticated user ID.
_log.info(`User ID: ${_user.id()}`)
Return
( int )
ID (numeric identifier) of the logged in user.
load
_user.load() : User
Return
( User )
name
_user.name() : string
Description
Gets the full name of the user who is authenticated.
How To Use
// Authenticated user name.
_log.info(`Full name of the User: ${_user.name()}`)
Return
( string )
Full name of the logged in user.
noPassword
_user.noPassword(active: boolean) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
active | boolean |
Return
( boolean )
_user.noPassword(id: int, active: boolean) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | |
active | boolean |
Return
( boolean )
password
_user.password(id: int, password: string) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | |
password | string |
Return
( boolean )
_user.password(password: string) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
password | string |
Return
( boolean )
providerData
_user.providerData(userId: int, providerCode: string) : Values
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
userId | int | |
providerCode | string |
Return
( Values )
_user.providerData(providerCode: string) : Values
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
providerCode | string |
Return
( Values )
providerDataByUid
_user.providerDataByUid(uid: string) : Values
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
uid | string |
Return
( Values )
providerLDAP
_user.providerLDAP(active: boolean) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
active | boolean |
Return
( boolean )
_user.providerLDAP(id: int, active: boolean) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | |
active | boolean |
Return
( boolean )
remove
_user.remove(id: int) : boolean
Description
Removes the user referring to the passed ID.
How To Use
// Removes the user:
const user = _user.firstByCode("sample")
_user.remove(
user.getInt("id")
)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | The user's ID (numeric identifier). |
Return
( boolean )
It was successfully deleted.
search
_user.search(term: string) : java.util.List
Description
Searches for users who have an occurrence in the data with the past search text.
How To Use
// Searches for users with the surname "Last Name".
const users = _user.search("Last Name")
for (const user of users) {
_log.info(`User found ${user.getString("name")}`)
}
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
term | string | Search key. |
Return
( java.util.List )
List of user data found.
searchFirst
_user.searchFirst(term: string) : Values
Description
The first result of the user search that has any occurrence in the past term data.
How To Use
// The first user to have an e-mail with @example.com.
const user = _user.search("@example.com")
_out.json(user)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
term | string | Search key. |
Return
( Values )
User data found.
setNoPassword
_user.setNoPassword(active: boolean) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
active | boolean |
Return
( boolean )
_user.setNoPassword(id: int, active: boolean) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | |
active | boolean |
Return
( boolean )
setPassword
_user.setPassword(id: int, password: string) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | |
password | string |
Return
( boolean )
_user.setPassword(password: string) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
password | string |
Return
( boolean )
setProviderLDAP
_user.setProviderLDAP(active: boolean) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
active | boolean |
Return
( boolean )
_user.setProviderLDAP(id: int, active: boolean) : boolean
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | |
active | boolean |
Return
( boolean )
uid
_user.uid() : string
Description
Gets the universal unique identifier of who is authenticated.
How To Use
// UUID of the authenticated user.
_log.info(`User UID: ${_user.uid()}`)
Return
( string )
UUID (universal unique identifier) of the logged in user.
update
_user.update(id: int, userData: Values) : boolean
Description
Updates user data for the past ID.
How To Use
// Updates the user:
const userData = _user.firstByMail("user.mail@example.com")
userData.set("pass", "NewSecretPassword123")
_user.update(
userData.getInt("id"),
userData,
true
)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | The user's ID (numeric identifier). |
userData | Values | User data to update the information stored in the database. |
Return
( boolean )
It was successfully updated.
_user.update(id: int, userData: Values, changePassword: boolean) : boolean
Description
Updates user data for the past ID.
How To Use
// Updates the user:
const userData = _user.firstByMail("user.mail@example.com")
userData.set("pass", "NewSecretPassword123")
_user.update(
userData.getInt("id"),
userData,
true
)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
id | int | The user's ID (numeric identifier). |
userData | Values | User data to update the information stored in the database. |
changePassword | boolean | Whether to change the password or password. |
Return
( boolean )
It was successfully updated.
_user.update(userData: Values) : boolean
Description
Updates user data for the ID defined in the passed data structure.
How To Use
// Updates the user:
const userData = _user.firstByMail("user.mail@example.com")
userData.set("pass", "NewSecretPassword123")
_user.update(
userData,
true
)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
userData | Values | User data to update the information stored in the database. |
Return
( boolean )
It was successfully updated.
_user.update(userData: Values, changePassword: boolean) : boolean
Description
Updates user data for the ID defined in the passed data structure.
How To Use
// Updates the user:
const userData = _user.firstByMail("user.mail@example.com")
userData.set("pass", "NewSecretPassword123")
_user.update(
userData,
true
)
Attributes
NAME | TYPE | DESCRIPTION |
---|---|---|
userData | Values | User data to update the information stored in the database. |
changePassword | boolean | Whether to change the password or password. |
Return
( boolean )
It was successfully updated.
user
_user.user() : string
Description
Gets the full username of who is authenticated.
How To Use
// Authenticated username.
_log.info(`Full name of the User: ${_user.user()}`)
Return
( string )
Username of the logged in user.