Doc
  • Get Started
  • Academy
  • Library
  • Languages iconEnglish
    • Português

›Resources

Libraries

  • Overview
  • Introduction

Resources & Objects

    Resources

    • App
    • Auth
    • Component
    • Config
    • Convert
    • CORS
    • Cron
    • Crypto
    • CSV
    • DB
    • Env
    • Error
    • Exec
    • Firebase
    • Form
    • Group
    • Header
    • HTML
    • Jasper
    • Jwt
    • Lang
    • Log
    • Monitor
    • OS
    • Out
    • PDF
    • RabbitMQ
    • Random
    • Remote
    • Form
    • Req
    • Res
    • Server
    • Setup
    • SMTP
    • Storage
    • Template
    • Time
    • Uid
    • Url
    • User
    • Val
    • WebSocket
    • XLS
    • XML

    Objects

    • Async
    • CheckExists
    • Column
    • DataItem
    • DataSchema
    • DBBatch
    • DBSearchResult
    • File
    • Index
    • InputStream
    • OSCommand
    • OutputStream
    • RandomString
    • RemoteResponse
    • Sequence
    • Service
    • SMTPConfig
    • Table
    • Values
    • XLSPosition

App Folders

  • Application folder structure
  • Config
  • DB
  • Public
  • Server
  • Storage
  • UI

User

Management of the users of the application and obtaining the data of the authenticated user.


all


_user.all() : List

Description

Gets the list of data for all users.

How To Use
// Returns all existing users.
_out.json(_user.all())
Return

( List )

List of all data for all users.


allByCode


_user.allByCode(code: string) : 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
NAMETYPEDESCRIPTION
codestringAlternative code that users may have associated.
Return

( List )

List of users found for the alternative code.


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
NAMETYPEDESCRIPTION
dataUserValuesData 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
NAMETYPEDESCRIPTION
userDataValuesData 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
NAMETYPEDESCRIPTION
codestringAlternative 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
NAMETYPEDESCRIPTION
mailstringUser 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
NAMETYPEDESCRIPTION
namestringFull 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
NAMETYPEDESCRIPTION
userstringUsername 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
NAMETYPEDESCRIPTION
idintNumeric 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
NAMETYPEDESCRIPTION
idOrUidOrUsernamestringIt can be either an ID, or a UUID, or the username.
Return

( Values )

User data found.


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.


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.


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
NAMETYPEDESCRIPTION
idintThe user's ID (numeric identifier).
Return

( boolean )

It was successfully deleted.


search


_user.search(term: string) : 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
NAMETYPEDESCRIPTION
termstringSearch key.
Return

( 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
NAMETYPEDESCRIPTION
termstringSearch key.
Return

( Values )

User data found.


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(userData: int, changePassword: 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
NAMETYPEDESCRIPTION
userDataintUser data to update the information stored in the database.
changePasswordValuesWhether to change the password or password.
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
NAMETYPEDESCRIPTION
idintThe user's ID (numeric identifier).
userDataValuesUser data to update the information stored in the database.
changePasswordbooleanWhether 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
NAMETYPEDESCRIPTION
userDataValuesUser 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
NAMETYPEDESCRIPTION
userDataValuesUser data to update the information stored in the database.
changePasswordbooleanWhether to change the password or password.
Return

( boolean )

It was successfully updated.


← UrlVal →
  • all
  • allByCode
  • code
  • create
  • createIfNotExists
  • data
  • firstByCode
  • firstByMail
  • firstByName
  • firstByUser
  • get
  • id
  • name
  • remove
  • search
  • searchFirst
  • uid
  • update

Open Source

Download

admin@netuno.org

support@netuno.org

Copyright © Sitana 2022