Advertisement
Guest User

Untitled

a guest
May 24th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. defmodule Cvapp.Auth do
  2. import Comeonin.Bcrypt, only: [checkpw: 2, dummy_checkpw: 0]
  3. import Plug.Conn
  4.  
  5. def login(conn, user) do
  6. conn
  7. |> assign(:current_user, user)
  8. |> Guardian.Plug.sign_in(user, :access)
  9. end
  10.  
  11. def login_by_email_and_pass(conn, email, given_pass, opts) do
  12. repo = Keyword.fetch!(opts, :repo)
  13. user = repo.get_by(Cvapp.User, email: email)
  14.  
  15. cond do
  16. user && checkpw(given_pass, user.password_hash) ->
  17. {:ok, login(conn, user)}
  18. user ->
  19. {:error, :unauthorized, conn}
  20. true ->
  21. dummy_checkpw()
  22. {:error, :not_found, conn}
  23. end
  24. end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement