Skip to content

Commit

Permalink
Update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
danschultzer committed Apr 11, 2024
1 parent 4281316 commit afc7532
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.0.38 (TBA)

### Bug fixes

* [`Pow.Ecto.Schema.Changeset`] Fixed issue with schemas having a `:data` field not being handled correctly in changeset functions

## v1.0.37 (2024-03-03)

### Bug fixes
Expand Down
9 changes: 9 additions & 0 deletions lib/pow/ecto/schema/changeset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ defmodule Pow.Ecto.Schema.Changeset do

do_confirm_password_changeset(user_or_changeset, params)
end

def confirm_password_changeset(user_or_changeset, %{"confirm_password" => password_confirmation} = params, _config) do
params =
params
Expand All @@ -119,6 +120,7 @@ defmodule Pow.Ecto.Schema.Changeset do

convert_confirm_password_param(user_or_changeset, params)
end

def confirm_password_changeset(user_or_changeset, params, _config),
do: do_confirm_password_changeset(user_or_changeset, params)

Expand Down Expand Up @@ -164,6 +166,7 @@ defmodule Pow.Ecto.Schema.Changeset do
defp reset_current_password_field(%Changeset{data: user} = changeset) do
%{changeset | data: reset_current_password_field(user)}
end

defp reset_current_password_field(user) do
%{user | current_password: nil}
end
Expand All @@ -183,6 +186,7 @@ defmodule Pow.Ecto.Schema.Changeset do

defp maybe_validate_current_password(%Changeset{data: %{password_hash: nil}} = changeset, _config),
do: changeset

defp maybe_validate_current_password(changeset, config) do
changeset = Changeset.validate_required(changeset, [:current_password])

Expand Down Expand Up @@ -222,13 +226,15 @@ defmodule Pow.Ecto.Schema.Changeset do

false
end

def verify_password(%{password_hash: password_hash}, password, config) do
apply_password_verify_function(config, [password, password_hash])
end

defp maybe_require_password(%Changeset{data: %{password_hash: nil}} = changeset) do
Changeset.validate_required(changeset, [:password])
end

defp maybe_require_password(changeset), do: changeset

defp maybe_validate_password(changeset, config) do
Expand All @@ -250,11 +256,13 @@ defmodule Pow.Ecto.Schema.Changeset do
defp maybe_put_password_hash(%Changeset{valid?: true, changes: %{password: password}} = changeset, config) do
Changeset.put_change(changeset, :password_hash, hash_password(password, config))
end

defp maybe_put_password_hash(changeset, _config), do: changeset

defp maybe_validate_password_hash(%Changeset{valid?: true} = changeset) do
Changeset.validate_required(changeset, [:password_hash])
end

defp maybe_validate_password_hash(changeset), do: changeset

defp hash_password(password, config) do
Expand Down Expand Up @@ -413,6 +421,7 @@ defmodule Pow.Ecto.Schema.Changeset do
_label, error -> {:halt, error}
end)
end

defp validate_dns_labels({:error, error}), do: {:error, error}

defp validate_dns_label(label) do
Expand Down
3 changes: 1 addition & 2 deletions test/pow/ecto/schema/changeset_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ defmodule Pow.Ecto.Schema.ChangesetTest do
schema "users" do
pow_user_fields()

field(:data, :string)
field :data, :string
end
end

Expand All @@ -436,7 +436,6 @@ defmodule Pow.Ecto.Schema.ChangesetTest do

test "pow_current_password_changeset/2" do
password_hash = Password.pbkdf2_hash(@password)

user = %UserDataAttribute{password_hash: password_hash}

assert UserDataAttribute.changeset(user, %{})
Expand Down

0 comments on commit afc7532

Please sign in to comment.