Created
June 24, 2016 12:32
-
-
Save dgladkov/b2dae866792ba9953b0070dec5ecf4b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.User do | |
use MyApp.Web, :model | |
schema "users" do | |
field :email, :string | |
field :encrypted_password, :string | |
field :is_admin, :boolean, default: false | |
field :password, :string, virtual: true | |
timestamps | |
end | |
@allowed_fields [ | |
:email, | |
:encrypted_password, | |
:is_admin, | |
:password, | |
] | |
@sensitive_fields [ | |
:is_admin, | |
] | |
def changeset(model, params \\ :empty) do | |
model | |
|> cast(params, @allowed_fields) | |
end | |
def secure_changeset(model, params \\ :empty) do | |
Enum.reduce(@sensitive_fields, changeset(model, params), &(delete_change(&2, &1))) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment