Hey there!
Firstly, I just wanted to thank you for this wonderful lib, it's really made auth and related functionality a breeze!
We are using the EmailConfirmation extension with a custom controller flow, but want to add the ability for a user to undo a current email change.
The scenario might be:
What would you suggest is the best way to do this?
TY!
Sebastian
Thanks!
You just need to submit the same email as the account currently has to reset it: https://github.com/danschultzer/pow/blob/v1.0.24/lib/extensions/email_confirmation/ecto/schema.ex#L77-L78
The way you present it to the end-user is up to you. E.g. if you use a link then you could call Pow.Plug.update_user/2 in the controller:
case Pow.Plug.update_user(conn, %{"email" => conn.assigns.current_user.email}) do
{:ok, _user, conn} ->
# Redirect
{:error, changeset, conn} ->
# show error
end
The above assume that the user is already signed in using the current_user assign. You could also set up a specific context function for it that calls the changeset function in PowEmailConfirmation.Ecto.Schema.
Thanks @danschultzer makes sense!
@danschultzer One thing we're noticing is Pow.Plug.update_user requires a current_password is there a way to bypass this?
Oh right! In this case you could just set up a changeset function that uses the PowEmailConfirmation changeset directly. Could look like this (not tested):
# User schema
def reset_email_confirmation_changeset(user) do
attrs = %{email: user.email}
user
|> change()
|> PowEmailConfirmation.Ecto.Schema.changeset(attrs, @pow_extension_config)
end
# Users context
def reset_email_confirmation(user) do
user
|> User.reset_email_confirmation_changeset()
|> Repo.update()
end