From 6585bd54e503a32ec829faf772cb3ee64e709422 Mon Sep 17 00:00:00 2001 From: Steffen Deusch Date: Thu, 9 May 2024 15:57:07 +0200 Subject: [PATCH] cast current_password and add as virtual field fixes https://github.com/phoenixframework/phoenix_live_view/issues/3235 --- priv/templates/phx.gen.auth/schema.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/priv/templates/phx.gen.auth/schema.ex b/priv/templates/phx.gen.auth/schema.ex index 156e5a305e..13ff8f1db5 100644 --- a/priv/templates/phx.gen.auth/schema.ex +++ b/priv/templates/phx.gen.auth/schema.ex @@ -7,6 +7,7 @@ defmodule <%= inspect schema.module %> do field :email, :string field :password, :string, virtual: true, redact: true field :hashed_password, :string, redact: true + field :current_password, :string, virtual: true, redact: true field :confirmed_at, <%= inspect schema.timestamp_type %> timestamps(<%= if schema.timestamp_type != :naive_datetime, do: "type: #{inspect schema.timestamp_type}" %>) @@ -153,6 +154,8 @@ defmodule <%= inspect schema.module %> do Validates the current password otherwise adds an error to the changeset. """ def validate_current_password(changeset, password) do + changeset = cast(changeset, %{current_password: password}, [:current_password]) + if valid_password?(changeset.data, password) do changeset else