Skip to content

Instantly share code, notes, and snippets.

@stephanos
Last active December 11, 2020 18:36
Show Gist options
  • Save stephanos/3efc2d54122d28928c05b06f60929fdf to your computer and use it in GitHub Desktop.
Save stephanos/3efc2d54122d28928c05b06f60929fdf to your computer and use it in GitHub Desktop.
defmodule Auth do
def login(email, password) do
case UserRepo.find_by_email(email) do
{:ok, user} ->
password_hash = BCrypt.hash(password)
cond do
user.hash != hash -> :error
user.active == false -> :error
user.deleted_at != nil -> :error
true ->
UserRepo.update_last_login_date(user, DateTime.utc_now())
{:ok, user}
end
_ -> :error
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment