Skip to content

Commit

Permalink
cast current_password and add as virtual field (#5806)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed May 9, 2024
1 parent 1ca00c0 commit 24390df
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions priv/templates/phx.gen.auth/schema.ex
Expand Up @@ -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}" %>)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 24390df

Please sign in to comment.