Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active July 8, 2017 06:52

Revisions

  1. shankardevy revised this gist Jul 8, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion crm.ex
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ defmodule Mango.CRM do
    customer && Comeonin.Bcrypt.checkpw(pass, customer.password_hash) ->
    customer
    true ->
    {:error}
    :error
    end
    end
    end
  2. shankardevy created this gist Jul 8, 2017.
    27 changes: 27 additions & 0 deletions crm.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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