Today I am creating a new project with a phoenix framework, adding a singup function. My problem is that I do not know how to create and verify a confirmation field, for example, for a user password. I did not find anything in this thread.
Below my current code is nothing special.
My current form template
<%= form_for @changeset, @action, fn f -> %>
<%= if f.errors != [] do %>
<% end %>
<div class="form-group">
<%= label f, :username, "User name" %>
<%= text_input f, :username, class: "form-control" %>
</div>
<div class="form-group">
<%= label f, :password, "Password" %>
<%= password_input f, :password, class: "form-control" %>
</div>
<div class="form-group">
<%= label f, :password_confirmation, "Password confirmation" %>
<%= password_input f, :password_confirmation, class: "form-control" %>
</div>
<% end %>
My current model
defmodule Project.User do
use Project.Web, :model
schema "users" do
field :username, :string
field :password, :string
timestamps
end
@required_fields ["username", "password"]
@optional_fields []
def changeset(model, params \\ :empty) do
model
|> cast(params, @required_fields, @optional_fields)
end
end
source
share