Skip to content

Commit 4281316

Browse files
oivoodoodanschultzer
authored andcommitted
fix type issue if the user model has attribute with data name
1 parent 52368f6 commit 4281316

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

lib/pow/ecto/schema/changeset.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ defmodule Pow.Ecto.Schema.Changeset do
161161
|> Changeset.prepare_changes(&Changeset.delete_change(&1, :current_password))
162162
end
163163

164-
defp reset_current_password_field(%{data: user} = changeset) do
164+
defp reset_current_password_field(%Changeset{data: user} = changeset) do
165165
%{changeset | data: reset_current_password_field(user)}
166166
end
167167
defp reset_current_password_field(user) do
@@ -181,7 +181,7 @@ defmodule Pow.Ecto.Schema.Changeset do
181181
end
182182
defp maybe_validate_email_format(changeset, _type, _config), do: changeset
183183

184-
defp maybe_validate_current_password(%{data: %{password_hash: nil}} = changeset, _config),
184+
defp maybe_validate_current_password(%Changeset{data: %{password_hash: nil}} = changeset, _config),
185185
do: changeset
186186
defp maybe_validate_current_password(changeset, config) do
187187
changeset = Changeset.validate_required(changeset, [:current_password])
@@ -192,7 +192,7 @@ defmodule Pow.Ecto.Schema.Changeset do
192192
end
193193
end
194194

195-
defp validate_current_password(%{data: user, changes: %{current_password: password}} = changeset, config) do
195+
defp validate_current_password(%Changeset{data: user, changes: %{current_password: password}} = changeset, config) do
196196
user
197197
|> verify_password(password, config)
198198
|> case do
@@ -226,7 +226,7 @@ defmodule Pow.Ecto.Schema.Changeset do
226226
apply_password_verify_function(config, [password, password_hash])
227227
end
228228

229-
defp maybe_require_password(%{data: %{password_hash: nil}} = changeset) do
229+
defp maybe_require_password(%Changeset{data: %{password_hash: nil}} = changeset) do
230230
Changeset.validate_required(changeset, [:password])
231231
end
232232
defp maybe_require_password(changeset), do: changeset

test/pow/ecto/schema/changeset_test.exs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,33 @@ defmodule Pow.Ecto.Schema.ChangesetTest do
418418
assert Changeset.validate_email("john.doe@#{String.duplicate("x", 64)}.com") == {:error, "dns label too long"}
419419
assert Changeset.validate_email("john.doe@#{String.duplicate("x", 64)}.example.com") == {:error, "dns label too long"}
420420
end
421+
422+
defmodule UserDataAttribute do
423+
@moduledoc false
424+
use Ecto.Schema
425+
use Pow.Ecto.Schema
426+
427+
schema "users" do
428+
pow_user_fields()
429+
430+
field(:data, :string)
431+
end
432+
end
433+
434+
describe "User struct with data field" do
435+
@password "password"
436+
437+
test "pow_current_password_changeset/2" do
438+
password_hash = Password.pbkdf2_hash(@password)
439+
440+
user = %UserDataAttribute{password_hash: password_hash}
441+
442+
assert UserDataAttribute.changeset(user, %{})
443+
assert UserDataAttribute.pow_changeset(user, %{})
444+
assert UserDataAttribute.pow_verify_password(user, @password)
445+
assert UserDataAttribute.pow_user_id_field_changeset(user, %{})
446+
assert UserDataAttribute.pow_password_changeset(user, %{})
447+
assert UserDataAttribute.pow_current_password_changeset(user, %{"current_password" => @password})
448+
end
449+
end
421450
end

0 commit comments

Comments
 (0)