# Class User

User

#### Indexable

- [key: string]: any

- Defined in packages/saltcorn-data/models/user.ts:73

##### Index

### Constructors

constructor

### Properties

_attributes
api_token?
disabled
email
id?
language?
last_mobile_login?
password
reset_password_expiry?
reset_password_token?
role_id
verification_token?
verified_on?

### Accessors

session_object
table

### Methods

auth_method_allowed
changePasswordTo
checkPassword
delete
destroy_sessions
getNewAPIToken
getNewResetToken
listApiTokens
relogin
removeAPIToken
revokeApiToken
revokeOriginalApiToken
send_verification_email
set_language
set_to_verified
update
updateLastMobileLogin
authenticate
count
create
destroy_all_tenant_sessions
find
findByApiToken
findForSession
findOne
findOrCreateByAttribute
generate_password
get_roles
hashPassword
lightDarkMode
matches_existing_user
nonEmpty
resetPasswordWithToken
unacceptable_password_reason
valid_email
verifyWithToken

## Constructors

### constructor

- new User(o: User | UserCfg): User

  User constructor

  #### Parameters

  - o: User | UserCfg

  #### Returns User

  - Defined in packages/saltcorn-data/models/user.ts:93

## Properties

### _attributes

_attributes: GenObj

- Defined in packages/saltcorn-data/models/user.ts:77

### `Optional` api_token

api_token?: string | null

- Defined in packages/saltcorn-data/models/user.ts:78

### disabled

disabled: boolean

- Defined in packages/saltcorn-data/models/user.ts:81

### email

email: string

- Defined in packages/saltcorn-data/models/user.ts:74

### `Optional` id

id?: number

- Defined in packages/saltcorn-data/models/user.ts:82

### `Optional` language

language?: string

- Defined in packages/saltcorn-data/models/user.ts:76

### `Optional` last_mobile_login

last_mobile_login?: Date | null

- Defined in packages/saltcorn-data/models/user.ts:86

### password

password: string

- Defined in packages/saltcorn-data/models/user.ts:75

### `Optional` reset_password_expiry

reset_password_expiry?: Date | null

- Defined in packages/saltcorn-data/models/user.ts:84

### `Optional` reset_password_token

reset_password_token?: string | null

- Defined in packages/saltcorn-data/models/user.ts:83

### role_id

role_id: number

- Defined in packages/saltcorn-data/models/user.ts:85

### `Optional` verification_token

verification_token?: string

- Defined in packages/saltcorn-data/models/user.ts:79

### `Optional` verified_on

verified_on?: Date

- Defined in packages/saltcorn-data/models/user.ts:80

## Accessors

### session_object

- get session_object(): any

  Create session object for user

  #### Returns any

  - Defined in packages/saltcorn-data/models/user.ts:266

### `Static` table

- get table(): Table

  #### Returns Table

  - Defined in packages/saltcorn-data/models/user.ts:292

## Methods

### auth_method_allowed

- auth_method_allowed(method_name: string): boolean

  #### Parameters

  - method_name: string

  #### Returns boolean

  - Defined in packages/saltcorn-data/models/user.ts:313

### changePasswordTo

- changePasswordTo(newpw: string, expireToken?: boolean): Promise<void>

  Change password

  #### Parameters

  - newpw: string

    new password string

  - `Optional` expireToken: boolean

    if true than force reset password token

  #### Returns Promise<void>

  no result

  - Defined in packages/saltcorn-data/models/user.ts:140

### checkPassword

- checkPassword(pw: string): boolean

  Check password

  #### Parameters

  - pw: string

    password string

  #### Returns boolean

  - Defined in packages/saltcorn-data/models/user.ts:130

### delete

- delete(): Promise<void>

  Delete user based on session object

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:457

### destroy_sessions

- destroy_sessions(): Promise<void>

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:786

### getNewAPIToken

- getNewAPIToken(): Promise<string>

  Add new API token to user

  #### Returns Promise<string>

  - Defined in packages/saltcorn-data/models/user.ts:516

### getNewResetToken

- getNewResetToken(): Promise<string>

  Get new reset token

  #### Returns Promise<string>

  - Defined in packages/saltcorn-data/models/user.ts:503

### listApiTokens

- listApiTokens(): Promise<
  { created_at: string
  | Date; id: number; token: string }[],
  >

  List API tokens for this user

  #### Returns Promise<{ created_at: string | Date; id: number; token: string }[]>

  - Defined in packages/saltcorn-data/models/user.ts:548

### relogin

- relogin(req: any): Promise<void>

  #### Parameters

  - req: any

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:814

### removeAPIToken

- removeAPIToken(): Promise<null>

  Remove API token for user

  #### Returns Promise<null>

  - Defined in packages/saltcorn-data/models/user.ts:533

### revokeApiToken

- revokeApiToken(tokenId: number): Promise<void>

  Revoke a single API token by id

  #### Parameters

  - tokenId: number

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:566

### revokeOriginalApiToken

- revokeOriginalApiToken(): Promise<void>

  Revoke original API token stored on users.api_token Also delete any matching row from _sc_api_tokens for this user

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:578

### send_verification_email

- send_verification_email(
  req?: any,
  opts?: { new_verification_token?: string },
  ): Promise<any>

  #### Parameters

  - `Optional` req: any
  - `Optional` opts: { new_verification_token?: string }

  #### Returns Promise<any>

  - Defined in packages/saltcorn-data/models/user.ts:321

### set_language

- set_language(language: string): Promise<void>

  Set language for User in database

  #### Parameters

  - language: string

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:474

### set_to_verified

- set_to_verified(): Promise<true>

  #### Returns Promise<true>

  - Defined in packages/saltcorn-data/models/user.ts:691

### update

- update(row: Partial<User>, plainPassword?: string): Promise<void>

  Update User

  #### Parameters

  - row: Partial<User>
  - `Optional` plainPassword: string

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:483

### updateLastMobileLogin

- updateLastMobileLogin(date: Date | null): Promise<void>

  update 'last_mobile_login' columnwill

  #### Parameters

  - date: Date | null

    new login_date or null for logout (invalidates all jwts)

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:827

### `Static` authenticate

- authenticate(uo: Row): Promise<false | User>

  Authenticate User

  #### Parameters

  - uo: Row

    user object

  #### Returns Promise<false | User>

  - Defined in packages/saltcorn-data/models/user.ts:301

### `Static` count

- count(where?: Where): Promise<number>

  Count users in database

  #### Parameters

  - `Optional` where: Where

  #### Returns Promise<number>

  - Defined in packages/saltcorn-data/models/user.ts:760

### `Static` create

- create(uo: GenObj): Promise<User | ErrorMessage>

  Create user

  #### Parameters

  - uo: GenObj

    user object

  #### Returns Promise<User | ErrorMessage>

  - Defined in packages/saltcorn-data/models/user.ts:191

### `Static` destroy_all_tenant_sessions

- destroy_all_tenant_sessions(tenant?: string): Promise<void>

  #### Parameters

  - `Optional` tenant: string

  #### Returns Promise<void>

  - Defined in packages/saltcorn-data/models/user.ts:799

### `Static` find

- find(where: Where, selectopts?: SelectOptions): Promise<User[]>

  Find users list

  #### Parameters

  - where: Where

    where object

  - `Optional` selectopts: SelectOptions

    select options

  #### Returns Promise<User[]>

  - Defined in packages/saltcorn-data/models/user.ts:425

### `Static` findByApiToken

- findByApiToken(token: string): Promise<User | undefined>

  Find user by API token

  #### Parameters

  - token: string

  #### Returns Promise<User | undefined>

  - Defined in packages/saltcorn-data/models/user.ts:593

### `Static` findForSession

- findForSession(where: Where): Promise<false | User>

  Find users list

  #### Parameters

  - where: Where

    where object

  #### Returns Promise<false | User>

  - Defined in packages/saltcorn-data/models/user.ts:334

### `Static` findOne

- findOne(where: Where): Promise<User | undefined>

  Find one user

  #### Parameters

  - where: Where

    where object

  #### Returns Promise<User | undefined>

  - Defined in packages/saltcorn-data/models/user.ts:438

### `Static` findOrCreateByAttribute

- findOrCreateByAttribute(
  k: string,
  v: any,
  uo?: any,
  ): Promise<false | User | ErrorMessage>

  Find or Create User

  #### Parameters

  - k: string
  - v: any
  - `Optional` uo: any = {}

  #### Returns Promise<false | User | ErrorMessage>

  - Defined in packages/saltcorn-data/models/user.ts:158

### `Static` generate_password

- generate_password(): string

  Generate password

  #### Returns string

  - Defined in packages/saltcorn-data/models/user.ts:776

### `Static` get_roles

- get_roles(): Promise<Row[]>

  Get available roles

  #### Returns Promise<Row[]>

  - Defined in packages/saltcorn-data/models/user.ts:768

### `Static` hashPassword

- hashPassword(pw: string): Promise<string>

  Get bcrypt hash for Password

  #### Parameters

  - pw: string

    password string

  #### Returns Promise<string>

  - Defined in packages/saltcorn-data/models/user.ts:121

### `Static` lightDarkMode

- lightDarkMode(user?: UserLike): "dark" | "light" | "auto"

  Return the light/dark mode (`"light"`, `"dark"` or `"auto"`) of the given user, or public if no user is given.

  #### Parameters

  - `Optional` user: UserLike

    User object

  #### Returns "dark" | "light" | "auto"

  #### Example

      User.lightDarkMode(user)

  - Defined in packages/saltcorn-data/models/user.ts:846

### `Static` matches_existing_user

- matches_existing_user(uo: Row): Promise<boolean>

  #### Parameters

  - uo: Row

  #### Returns Promise<boolean>

  - Defined in packages/saltcorn-data/models/user.ts:249

### `Static` nonEmpty

- nonEmpty(): Promise<boolean>

  Check that user table is not empty in database

  #### Returns Promise<boolean>

  true if there are users in db

  #### Deprecated

  use method count()

  - Defined in packages/saltcorn-data/models/user.ts:448

### `Static` resetPasswordWithToken

- resetPasswordWithToken(
  email: {
  confirm_password: string;
  email: string;
  password: string;
  reset_password_token: string;
  },
  ): Promise<ErrorMessage | SuccessMessage>

  Reset password using token

  #### Parameters

  - email: {
    confirm_password: string;
    email: string;
    password: string;
    reset_password_token: string;
    }

    email address string

  #### Returns Promise<ErrorMessage | SuccessMessage>

  - Defined in packages/saltcorn-data/models/user.ts:713

### `Static` unacceptable_password_reason

- unacceptable_password_reason(pw: string): string | undefined

  Validate password

  #### Parameters

  - pw: string

  #### Returns string | undefined

  - Defined in packages/saltcorn-data/models/user.ts:615

### `Static` valid_email

- valid_email(email: string): boolean

  Validate email

  #### Parameters

  - email: string

  #### Returns boolean

  - Defined in packages/saltcorn-data/models/user.ts:664

### `Static` verifyWithToken

- verifyWithToken(
  email: { email: string; verification_token: string },
  ): Promise<true | ErrorMessage>

  Verification with token

  #### Parameters

  - email: { email: string; verification_token: string }

    email string

  #### Returns Promise<true | ErrorMessage>

  true if verification passed, error string if not

  - Defined in packages/saltcorn-data/models/user.ts:674