Current section

Files

Jump to
ash_authentication lib ash_authentication strategies password resettable.ex
Raw

lib/ash_authentication/strategies/password/resettable.ex

defmodule AshAuthentication.Strategy.Password.Resettable do
@moduledoc """
The entity used to store password reset information.
"""
@default_lifetime_days 3
defstruct token_lifetime: @default_lifetime_days * 24,
request_password_reset_action_name: nil,
password_reset_action_name: nil,
sender: nil
@type t :: %__MODULE__{
token_lifetime: hours :: pos_integer,
request_password_reset_action_name: atom,
password_reset_action_name: atom,
sender: {module, keyword}
}
@doc false
@spec entity :: struct()
def entity do
%Spark.Dsl.Entity{
name: :resettable,
describe: "Configure password reset options for the resource",
target: __MODULE__,
schema: [
token_lifetime: [
type: :pos_integer,
doc: """
How long should the reset token be valid, in hours.
Defaults to #{@default_lifetime_days} days.
""",
default: @default_lifetime_days * 24
],
request_password_reset_action_name: [
type: :atom,
doc: """
The name to use for the action which generates a password reset token.
If not present it will be generated by prepending the strategy name
with `request_password_reset_with_`.
""",
required: false
],
password_reset_action_name: [
type: :atom,
doc: """
The name to use for the action which actually resets the user's
password.
If not present it will be generated by prepending the strategy name
with `password_reset_with_`.
""",
required: false
],
sender: [
type:
{:spark_function_behaviour, AshAuthentication.Sender,
{AshAuthentication.SenderFunction, 3}},
doc: """
How to send the password reset instructions to the user.
Allows you to glue sending of reset instructions to [swoosh](https://hex.pm/packages/swoosh), [ex_twilio](https://hex.pm/packages/ex_twilio) or whatever notification system is appropriate for your application.
Accepts a module, module and opts, or a function that takes a record, reset token and options.
See `AshAuthentication.Sender` for more information.
""",
required: true
]
]
}
end
end