Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active July 8, 2017 06:52
Show Gist options
  • Save shankardevy/ffdbd8e0802d65d22db22c291c3bd760 to your computer and use it in GitHub Desktop.
Save shankardevy/ffdbd8e0802d65d22db22c291c3bd760 to your computer and use it in GitHub Desktop.
defmodule Mango.CRM do
alias Mango.Repo
alias Mango.CRM.Customer
def build_customer(attrs \\ %{}) do
%Customer{}
|> Customer.changeset(attrs)
end
def create_customer(attrs) do
attrs
|> build_customer
|> Repo.insert
end
def get_customer_by_email(email), do: Repo.get_by(Customer, email: email)
def get_customer_by_credentials(%{"email" => email, "password" => pass} ) do
customer = get_customer_by_email(email)
cond do
customer && Comeonin.Bcrypt.checkpw(pass, customer.password_hash) ->
customer
true ->
:error
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment