amelinium.web.controller.user
added in 1.0.0
amelinium service, web user controller functions.
auth-with-password!
(auth-with-password! req user-email password)
(auth-with-password! req user-email password sess)
(auth-with-password! req user-email password sess route-data)
(auth-with-password! req user-email password sess route-data lang)
(auth-with-password! req user-email password sess route-data lang auth-only?)
(auth-with-password! req user-email password sess route-data lang auth-only? session-key)
Authentication helper. Used by other controllers. Short-circuits on certain conditions and may emit a redirect or render a response.
authenticate!
(authenticate! req)
(authenticate! req session-key)
Logs user in when user e-mail and password are given, or checks if the session is valid to serve a current page.
Takes a request map and obtains a database connection, a client IP address and an authentication configuration from it. Also gets user’s e-mail and a password from a map associated with the :form-params
key of the req
. Calls auth-user-with-password!
to get the result or perform a redirect if the authentication was not successful.
If there is no e-mail nor password given (the value is nil
, false
or an empty string) then the authentication is not performed but instead the validity of a session is tested. If the session is invalid a redirect to the login page is performed; the destination URL is obtained by looking up the route data key :auth/login
and taking a route name associated with it, or by visiting an URL associated with the :login
route name (as default, when the previous lookup was not successful). If the destination path is parameterized with a language, the redirect will set this path parameter to a value obtained by calling the web/pick-language-str
, using language detection chain identified by the :user
key. The same language will be passed to the auth-user-with-password!
call.
If the session is valid then the given request map is returned with the :authenticated!
key set to true
.
confirmation-status!
(confirmation-status! req)
(confirmation-status! req session-key)
(confirmation-status! req session-key reason)
Renders status of identity confirmation on a basis of user’s identity and quick token obtained from form params. Identity type must belong to a group :amelinium.identity/public
.
create!
(create! req)
Verifies confirmation token or code against a database and if it matches creates an account.
identity-create!
(identity-create! req)
(identity-create! req session-invalidator)
Verifies confirmation token against a database and if it matches, updates the identity (phone or e-mail).
login!
(login! req)
(login! req session-key)
Prepares response data to be displayed on a login page.
password-change!
(password-change! req)
Changes password for the user authenticated with an old password and e-mail or sets the password for the given user-id
.
password-create!
(password-create! req)
Creates a password on a basis of a token, or on a basis of a code and identity.
password-recover!
(password-recover! req)
Initiates password recovery by sending an e-mail or SMS message with a verification code or token.
password-update!
(password-update! req)
Displays password setting form for a user authenticated with token or code.
prolong!
(prolong! req)
(prolong! req session-key)
Prepares response data to be displayed on a prolongation page.
register!
(register! req)
(register! req session-key)
Initiates user registration process by receiving e-mail, password and name.
retry-after
(retry-after expires)
Returns an expiration date and time formatted according to the RFC 1123.
verify!
(verify! req {:keys [no-data result reason db id id-type confirm-once? lang translator route-data], :or {confirm-once? true}, :as opts})
Performs the identity verification by sending an e-mail or SMS with a URL to complete confirmation. Takes a request map req
and configuration options as a map with the following keys:
:db
- database connection handler or a data source object, :id
- identity used for verification (e-mail address or a phone number), :id-type
- identity type (:email
or :phone
), :lang
- language (defaults to a result of common/pick-language
), :reason
– verification reason (:creation
, :recovery
, :change
, :unlock
), :no-data
- status to be set when there is no result from a database (default: :verify/bad-result
), :result
- a result of calling confirmation function from a model, :translator
- translation function (defaults to a result of amelinium.common/translator
), :route-data
- route data (defaults to a result of calling amelinium.http/get-route-data
), :confirm-once?
- if truthy (default) then existing confirmation will cause error response, :async/responder
- asynchronous response handler for Twilio client (default: amelinium.common.controller/verify-request-id-update
), :async/raiser
- asynchronous error handler for Twilio client (default: amelinium.common.controller/verify-process-error
).