Skip to content

Instantly share code, notes, and snippets.

@johnhamelink
Created July 14, 2016 10:04
Show Gist options
  • Select an option

  • Save johnhamelink/6d53cee6d8a1920129f5766057781e34 to your computer and use it in GitHub Desktop.

Select an option

Save johnhamelink/6d53cee6d8a1920129f5766057781e34 to your computer and use it in GitHub Desktop.
defp ensure_sso_defaults(changeset) do
# One of these fields needs to exist
# for us to overwrite the email & password
is_sso = (
get_field(changeset, :digits_id) ||
get_field(changeset, :facebook_id) ||
get_field(changeset, :sms_verification_id)
)
changeset =
if is_sso do
# If the email or password fields aren't set,
# then set them.
if email = get_field(changeset, :email) == nil do
changeset
|> put_change(:email,
"#{SecureRandom.urlsafe_base64(16)}@email.com")
else
changeset
end
if password = get_field(changeset, :password) == nil do
changeset
|> put_change(:encrypted_password,
"#{SecureRandom.urlsafe_base64(16)}")
else
changeset
end
else
changeset
end
changeset
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment