amelinium.model.user

added in 1.0.0

amelinium service, user model.

account-type

(account-type db user-identity)(account-type db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns an account type of the existing user. Optional identity-type can be given to constrain the given identity.

auth-by-session

(auth-by-session settings-src smap)

Gets authentication configuration (AuthConfig) for the given user identified by a session object. Uses cached user props provided by amelinium.model.user/prop-of.

auth-by-user-id

(auth-by-user-id settings-src user-id)

Gets authentication configuration (AuthConfig) for the given user. Uses cached user props provided by amelinium.model.user/prop-by-id.

auth-config

(auth-config req user-identity)(auth-config req user-identity identity-type)

Returns user authentication configuration for the user specified by user-identity and optional identity-type (which can be :email, :phone, :id or :uid). If the identity type is not given it will be guessed.

The resulting map will be an authentication configuration (AuthConfig record) obtained for an account type associated with a user entry, or a generic authentication configuration if account type could not be found because either user does not exist in an authentication database or there is no account type specified for the user.

The returned record will have extra entries present (available only via its map interface):

  • :identity/type (detected or given identity type),
  • :user/account-type (detected account type or nil if it couldn’t be obtained),
  • :user/properties (user properties obtained when querying the database).

create

(create db email token code)

Creates new user account identified with the given e-mail email by checking if it was successfully confirmed. Token (token) or code (code) must be provided to authorize operation. Returns a map with :created? set to true if user account is created.

create-or-get-shared-suite-id

(create-or-get-shared-suite-id db suite)

Gets shared suite ID on a basis of its JSON content. If it does not exist, it is created. If the value of suite is a fixed-precision integer, it is returned.

create-with-code

(create-with-code db email code)

create-with-code-query

create-with-token

(create-with-token db token)

create-with-token-query

created

(created db user-identity)(created db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns the existing user’s creation time. Optional identity-type can be given to constrain the given identity.

created-by

(created-by db user-identity)(created-by db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns the existing user’s creator ID. Optional identity-type can be given to constrain the given identity.

del-setting!

(del-setting! db user-id)(del-setting! db user-id setting-id)(del-setting! db user-id setting-id & setting-ids)

Deletes one or more settings for a given user from a database.

email

(email db user-identity)(email db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns an e-mail of the existing user. Optional identity-type can be given to constrain the given identity.

existing

(existing db user-identity)(existing db identity-type user-identity)

Returns user identity record (of type amelinium.Identity) if a user specified by the given user-identity with optional identity-type exists. Otherwise it returns nil.

exists?

(exists? db user-identity)(exists? db identity-type user-identity)

Returns true if a user specified by the given user-identity with optional identity-type exists. Returns false otherwise.

find-id

(find-id db user-spec)

Gets user ID on a basis of a map with :id key or on a basis of a map with :uid key or on a basis of a number, a string or a keyword being ID, email, phone or UID. User must exist in a database. Uses cached properties if possible.

first-name

(first-name db user-identity)(first-name db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a first name of the existing user. Optional identity-type can be given to constrain the given identity.

generate-password

(generate-password auth-config password)

Creates a password for the given authentication config. Returns a map of shared part ID and an intrinsic part as two keys: password-suite-id and :password.

get-id

(get-id db user-identity)(get-id db identity-type user-identity)

Takes a user identity user-identity and a database connectable object and returns a numerical user ID (not cached). Optional identity type will constrain the identity to be treated as it will be of certain type.

This function is using query-id to perform the actual query on a database using identity record created with amelinium.identify/of or amelinium.identity/of-type.

This function is used by cache-backed functions id, id-of, trusted-id and trusted-id-of to communicate with a database.

get-ids

(get-ids db user-identities)(get-ids db identity-type user-identities)

Takes user identities and a database connectable object, and returns a numerical user IDs (not cached). Optional identity type will constrain the identity to be treated as it will be of certain type. Returns a map with amelinium.Identity objects as keys and numerical identifiers as values.

This function is using query-ids to perform the actual query on a database using identity records created with amelinium.identify/of or amelinium.identity/of-type.

This function is used by cache-backed functions ids, ids-of, trusted-ids and trusted-ids-of to communicate with a database.

get-login-data

(get-login-data auth-source email)(get-login-data auth-source email account-type)

Returns data required for user to log in, including password information.

get-password-suites

(get-password-suites auth-source email)(get-password-suites auth-source email account-type)

Returns password information.

get-setting

(get-setting db user-id setting-id)

Gets user setting and de-serializes it to a Clojure data structure.

get-shared-suite

(get-shared-suite db suite-id)

Gets shared suite by its ID as a JSON string.

get-shared-suite-id

(get-shared-suite-id db suite)

Gets shared suite ID on a basis of its JSON content. If the value of suite is a fixed-precision integer, it is returned.

get-user-by-email

(get-user-by-email db email)

Given an email, returns the user data in a form of lazy map.

get-user-by-id

(get-user-by-id db id)

Given a user ID, returns the user data in a form of lazy map.

get-user-by-uid

(get-user-by-uid db uid)

Given a database connectable object db and a UID uid, returns the user data in a form of lazy map.

hard-locked

(hard-locked db user-identity)(hard-locked db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a time of the account’s hard-lock (if any). Optional identity-type can be given to constrain the given identity.

hard-locked

(hard-locked db user-identity)(hard-locked db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a time of the account’s hard-lock (if any). Optional identity-type can be given to constrain the given identity.

id

(id db user-identity)(id db identity-type user-identity)

Takes a user identity, optional identity type and a database connectable object, and returns a numerical user ID (cached).

Optional identity type will constrain the identity to be treated as it will be of certain type.

id-of

(id-of identity-type db user-identity)

Like id but identity-type is a first argument.

identity-cache

ids

(ids db user-identities)(ids db identity-type user-identities)

Takes user identities, optional identity type and a database connectable object, and returns a map with amelinium.Identity keys and numerical user IDs values (cached).

Optional identity type will constrain the identities to be treated as they will be of certain type.

ids-of

(ids-of identity-type db user-identities)

Like ids but identity-type is a first argument.

insert-shared-suite-query

last-attempt

(last-attempt db user-identity)(last-attempt db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a time of last log-in attempt of the existing user. Optional identity-type can be given to constrain the given identity.

last-failed-ip

(last-failed-ip db user-identity)(last-failed-ip db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a last IP address from which the user has failed to log in successfully. Optional identity-type can be given to constrain the given identity.

last-login

(last-login db user-identity)(last-login db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a time of last successful log-in of the existing user. Optional identity-type can be given to constrain the given identity.

last-name

(last-name db user-identity)(last-name db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a last name of the existing user. Optional identity-type can be given to constrain the given identity.

last-ok-ip

(last-ok-ip db user-identity)(last-ok-ip db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a last IP address from which the user has logged in successfully. Optional identity-type can be given to constrain the given identity.

login-attempts

(login-attempts db user-identity)(login-attempts db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a number of login attempts of the existing user. Optional identity-type can be given to constrain the given identity.

login-data-queries

login-failed-update-query

login-query

login-query-atypes-post

login-query-atypes-pre

login-query-atypes-single

make-user-data

(make-user-data auth-settings params)

Creates user data record by getting values from the given authentication settings and parameters map. If :password parameter is present it will make JSON password suite.

make-user-data-simple

(make-user-data-simple auth-settings params)

Creates simple user data record (only db, phone and email) by getting values from the given authentication settings and parameters map.

make-user-password

(make-user-password auth-src password)(make-user-password auth-src password account-type)

Creates user password (of type PasswordData) on a basis of authentication source auth-src, a plain password string password and optional account type account-type.

Authentication source can be a request map, AuthSettings record or AuthConfig record. If this is a request map then authentication settings are looked up under the :auth/setup key.

The account-type argument is used to select authentication configuration (of type AuthConfig) specific to a user from the given or obtained authentication settings.

If account-type argument is not given and the given authentication source is not of type AuthConfig then the default authentication configuration associated with detected authentication settings is used.

If account-type argument is not given or is set to nil or false, and the given authentication source is already of type AuthConfig then it has no impact on the authentication configuration being used.

If account-type argument is given and is not nil or false, and the given authentication source is already of type AuthConfig then it will be used only if it is configured to handle the given account type. If it is does not, password data record with nil values associated with each field is returned.

middle-name

(middle-name db user-identity)(middle-name db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a middle name of the existing user. Optional identity-type can be given to constrain the given identity.

password-data-queries

password-query

password-query-atypes-post

password-query-atypes-pre

password-query-atypes-single

phone

(phone db user-identity)(phone db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a phone number of the existing user. Optional identity-type can be given to constrain the given identity.

prepare-password-suites

(prepare-password-suites db suites)(prepare-password-suites db shared-suite user-suite)

Creates a password suites without saving it into a database. Uses database to store the given, shared password suite if it does not exist yet. Returns a map with two keys: :password (JSON-encoded password ready to be saved into a database which should be given as an argument) and :password-suite-id (integer identifier of a shared suite ID which exists on a database).

prop

(prop db prop-id user-identity)(prop db prop-id user-identity & identities)

For the given database connectable object db, property identifier prop-id, and identifiable object user-identity, returns user’s property. If multiple identities are given, returns a map of amelinium.Identity records associated with selected property values. (cached)

prop-by-id

(prop-by-id db prop-id user-id)(prop-by-id db prop-id user-id & ids)

Returns user property prop-id for the given user ID user-id or a map of user properties keyed with their IDs if multiple IDs are given (cached).

prop-by-id-or-default

(prop-by-id-or-default db prop default id)(prop-by-id-or-default db prop default id & ids)

Returns user property prop for the given user ID id or a map of user property keyed with its ID if multiple IDs are given (cached). If the property is not found the default value, given as default, is returned instead of nil.

prop-by-ids

(prop-by-ids db prop-id ids)

Returns property prop-id for the given user IDs ids (cached).

prop-cols

prop-del

(prop-del db user-id k)

Deletes property of a user with the given ID user-id by setting it to nil.

prop-get-locked

(prop-get-locked db user-id)(prop-get-locked db user-id & ids)

Using the database connectable object db, returns the hard-lock status for the user account of the given ID user-id. Uses cached property.

prop-get-roles

(prop-get-roles smap-or-user-id opts context)(prop-get-roles smap-or-user-id opts)

prop-of

(prop-of identity-type db prop-id user-identity)(prop-of identity-type db prop-id user-identity & identities)

For the given identity type identity-type, database connectable object db, property identifier prop-id, and identifiable object user-identity, returns user’s property. If multiple identities are given, returns a map of amelinium.Identity records associated with selected property values. Identity type(s) must be of the given type. (cached)

prop-set

(prop-set db user-id k v)

Sets property k of a user identified with the given ID user-id to value v.

props

(props db user-identity)(props db user-identity & identities)

For the given database connectable object db and identifiable object user-identity, returns user’s properties as a map. If multiple identities are given, returns a sequence of maps. (cached)

props-by-id

(props-by-id db user-id)(props-by-id db user-id & ids)

Returns user properties for the given user ID user-id (cached).

props-by-ids

(props-by-ids db ids)

Returns user properties for each of the given user IDs ids (cached).

props-cache

props-del

(props-del db user-id)

Deletes all properties of a user identified with the given ID user-id.

props-of

(props-of identity-type db user-identity)(props-of identity-type db user-identity & identities)

For the given database connectable object db, identity type identity-type and identifiable object user-identity, returns user’s properties as a map. If multiple identities are given, returns a map keyed with amelinium.Identity records. The given identity must be of the given type. (cached)

props-set

(props-set db user-id keys-vals)

Sets properties of a user identified with the given ID user-id.

put-setting!

(put-setting! db user-id setting-id value)(put-setting! db user-id setting-id value & pairs)

Stores one or more settings of the given user in a database. Maximum object size is 32 KB.

query-id

multimethod

(query-id db identity-type user-identity)

Performs an ID-getting query for the given identity and identity type (must be a keyword). This method is used to get user ID for the given identity of a known type.

query-id-std

(query-id-std db colspec query user-identity)

Converts the given user identity user-identity to a database-suitable value and then performs a SQL query query with the obtained value as a parameter. Returns query result as vector. This is a standard querying function applicable to many simple database schemas. Used primarily as a default operation in method definitions of query-id.

query-ids

multimethod

(query-ids db identity-type user-identities)

Performs a multiple IDs-getting SQL query for the given identity and identity type (must be a keyword). This method is used to get user IDs for the given identities of known types.

query-ids-std

(query-ids-std db colspec query user-identities)

Converts the given user identities user-identities to a database-suitable values and then performs a SQL query query with the obtained value as parameters added using “IN(…)” clause. Returns query result as vector. Used primarily as a default operation in method definitions of query-ids.

seq-prop

(seq-prop db prop-id user-identities)(seq-prop db prop-id identity-type user-identities)

For the given database connectable object db, property identifier prop-id, optional identity type identity-type and identifiable objects user-identities, returns a map of amelinium.Identity records associated with selected property values. Each given identity must be of the given type if identity-type is used. (cached)

seq-prop-by-id

(seq-prop-by-id db prop-id user-ids)

Returns user property prop-id for the given user IDs user-ids (cached).

seq-prop-of

(seq-prop-of identity-type db prop-id user-identities)

The same as seq-prop but identity-type is a mandatory first argument. (cached)

seq-props

(seq-props db identity-type user-identities)(seq-props db user-identities)

For the given database connectable object db, optional identity type identity-type and identifiable object user-identity, returns users’ properties as map keyed with amelinium.Identity records. The given identities must be of the given type if the type is given. (cached)

seq-props-by-id

(seq-props-by-id db ids)

Returns user properties for each of the given user IDs ids (cached).

session

(session db user-identity)(session db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a session of the existing user. Optional identity-type can be given to constrain the given identity.

Be aware that this operation will only work if the identity type is a session. There is no parsing of session ID, nor getting it from a database.

setting

(setting db user-id setting-id)

setting-del

(setting-del db user-id)(setting-del db user-id setting-id)(setting-del db user-id setting-id & more)

setting-set

(setting-set db user-id setting-id value)(setting-set db user-id setting-id value & pairs)

settings-cache

shared-suite-by-id-query

shared-suite-query

soft-lock-update-query

soft-locked

(soft-locked db user-identity)(soft-locked db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a time of the account’s soft-lock (if any). Optional identity-type can be given to constrain the given identity.

trusted-id

(trusted-id db user-identity)(trusted-id db identity-type user-identity)

Takes a user identity, optional identity type and a database connectable object, and returns a numerical user ID (cached).

When the given identity is of type :id (a numerical identifier), it will NOT interact with a database but simply trust that the ID exists and will simply return it.

Optional identity type will constrain the identity to be treated as it will be of certain type.

trusted-id-of

(trusted-id-of identity-type db user-identity)

Like trusted-id but identity-type is a first argument.

trusted-ids

(trusted-ids db user-identities)(trusted-ids db identity-type user-identities)

Takes user identities, optional identity type and a database connectable object, and returns a map with amelinium.Identity keys and numerical user IDs values (cached).

When any of the given identities is of type :id (a numerical identifier), it will NOT interact with a database to get the ID but simply trust that this ID exists and will simply put it into a map.

Optional identity type will constrain the identities to be treated as they will be of certain type.

trusted-ids-of

(trusted-ids-of identity-type db user-identities)

Like trusted-ids but identity-type is a first argument.

uid

(uid db user-identity)(uid db identity-type user-identity)

For the given database connectable object db and user identity user-identity returns a UID of the existing user. Optional identity-type can be given to constrain the given identity.

update-identity

(update-identity identity-type db token code user-identity)(update-identity identity-type db code user-identity)(update-identity identity-type db token nil)(update-identity identity-type db token)

Updates user’s identity identified by user-identity and code, or by token. Code or token must exist in a database.

update-identity-query-code

update-identity-query-token

update-identity-with-code

(update-identity-with-code identity-type db code user-identity)

update-identity-with-token

(update-identity-with-token identity-type db token)

update-login-failed

(update-login-failed auth-config user-id ip-address)(update-login-failed db user-id ip-address max-attempts attempt-expires-after-secs)

Updates users table with failed login data (attempts, IP address) according to authentication configuration and sets a soft lock if a number of attempts exceeded the configured value.

update-login-ok

(update-login-ok db id ip)

update-password

(update-password db id suites)(update-password db id shared-suite user-suite)

Updates password information for the given user by updating suite ID and intrinsic password in an authorization database. Additionally :last_attempt and :last_failed_ip properties are deleted and :login_attempts is set to 0.