Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule Cvapp.Auth do
- import Comeonin.Bcrypt, only: [checkpw: 2, dummy_checkpw: 0]
- import Plug.Conn
- def login(conn, user) do
- conn
- |> assign(:current_user, user)
- |> Guardian.Plug.sign_in(user, :access)
- end
- def login_by_email_and_pass(conn, email, given_pass, opts) do
- repo = Keyword.fetch!(opts, :repo)
- user = repo.get_by(Cvapp.User, email: email)
- cond do
- user && checkpw(given_pass, user.password_hash) ->
- {:ok, login(conn, user)}
- user ->
- {:error, :unauthorized, conn}
- true ->
- dummy_checkpw()
- {:error, :not_found, conn}
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement