Skip to content

Commit

Permalink
define put_email_hash function, #29
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLab committed Dec 4, 2019
1 parent 4a7f135 commit 6e68240
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/app/ctx/person.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,28 @@ defmodule App.Ctx.Person do
end

@doc false
def changeset(person, %{"email" => email} = attrs) do
def changeset(person, attrs) do
person
|> cast(attrs, [:username, :email, :givenName, :familyName, :password_hash, :key_id, :locale, :picture])
|> validate_required([:username, :email, :givenName, :familyName, :password_hash, :key_id])
|> put_change(:email_hash, email )
|> put_email_hash()
end

def google_changeset(profile, %{"email" => email} = attrs) do
def google_changeset(profile, attrs) do
profile
|> cast(attrs, [:email, :givenName, :familyName, :picture, :locale])
|> validate_required([:email])
|> put_change(:email_hash, email )
|> put_email_hash()
end

defp put_email_hash(changeset) do
case changeset do
%{valid?: true, changes: %{email: email}} ->
put_change(changeset, :email_hash, email)

_ ->
changeset
end
end

@doc """
Expand Down

0 comments on commit 6e68240

Please sign in to comment.