# default User resource change_password action
update :change_password do
# Use this action to allow users to change their password by providing
# their current password and a new password.
require_atomic? false
accept []
argument :current_password, :string, sensitive?: true, allow_nil?: false
argument :password, :string,
sensitive?: true,
allow_nil?: false,
constraints: [min_length: 8]
argument :password_confirmation, :string, sensitive?: true, allow_nil?: false
validate confirm(:password, :password_confirmation)
validate {AshAuthentication.Strategy.Password.PasswordValidation,
strategy_name: :password, password_argument: :current_password}
change {AshAuthentication.Strategy.Password.HashPasswordChange, strategy_name: :password}
end
# controller
def change_password_form(conn, _params) do
user = conn.assigns[:current_user]
form =
AshPhoenix.Form.for_update(user, :change_password, as: "user", actor: user)
|> to_form()
conn
|> render(:change_password_form, form: form)
end
# template
<.form
for={@form}
id="change-password-form"
action={~p"/settings/change-password"}
method="post"
>
<.input field={@form[:current_password]} type="password" label="Current Password" />
<.input field={@form[:password]} type="password" label="New Password" />
<.input field={@form[:password_confirmation]} type="password" label="Confirm New Password" />
<.button>Change Password</.button>
</.form>
# default User resource change_password action
update :change_password do
# Use this action to allow users to change their password by providing
# their current password and a new password.
require_atomic? false
accept []
argument :current_password, :string, sensitive?: true, allow_nil?: false
argument :password, :string,
sensitive?: true,
allow_nil?: false,
constraints: [min_length: 8]
argument :password_confirmation, :string, sensitive?: true, allow_nil?: false
validate confirm(:password, :password_confirmation)
validate {AshAuthentication.Strategy.Password.PasswordValidation,
strategy_name: :password, password_argument: :current_password}
change {AshAuthentication.Strategy.Password.HashPasswordChange, strategy_name: :password}
end
# controller
def change_password_form(conn, _params) do
user = conn.assigns[:current_user]
form =
AshPhoenix.Form.for_update(user, :change_password, as: "user", actor: user)
|> to_form()
conn
|> render(:change_password_form, form: form)
end
# template
<.form
for={@form}
id="change-password-form"
action={~p"/settings/change-password"}
method="post"
>
<.input field={@form[:current_password]} type="password" label="Current Password" />
<.input field={@form[:password]} type="password" label="New Password" />
<.input field={@form[:password_confirmation]} type="password" label="Confirm New Password" />
<.button>Change Password</.button>
</.form>