Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make current password optional when editing user? #74

Closed
kidbombay opened this issue Jan 27, 2019 · 3 comments
Closed

Make current password optional when editing user? #74

kidbombay opened this issue Jan 27, 2019 · 3 comments

Comments

@kidbombay
Copy link

Is there a way to make current password optional when riding user?

@danschultzer
Copy link
Collaborator

danschultzer commented Jan 27, 2019

Yeah, you just have to override the changeset:

defmodule MyApp.Users.User do
  use Ecto.Schema
  use Pow.Ecto.Schema

  # ...

  def changeset(user_or_changeset, attrs) do
    user_or_changeset
    |> pow_user_id_field_changeset(attrs)
    |> pow_password_changeset(attrs)
  end
end

@danschultzer
Copy link
Collaborator

Obviously this makes the current password irrelevant, as it should be if users can edit their information without the current password, but if you want to make it actually optional (so if used it has to be the correct password) you would need to add it as a custom changeset method:

  def changeset(user_or_changeset, attrs) do
    user_or_changeset
    |> maybe_validate_current_password(attrs)
    |> pow_user_id_field_changeset(attrs)
    |> pow_password_changeset(attrs)
  end

  defp maybe_validate_current_password(user_or_changeset, attrs) do
    case current_password_entered?(attrs) do
      false -> user_or_changeset
      true  -> pow_current_password_changeset(user_or_changeset, attrs)
    end
  end 

@kidbombay
Copy link
Author

Thank you!

axelclark added a commit to axelclark/ex338 that referenced this issue Jul 16, 2019
* Fix bug when updating user from admin page
* See pow-auth/pow#74
* Closes #630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants