Last active
January 6, 2016 19:04
-
-
Save cjbell/16270772bd0c4697d958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Controllers.Helpers do | |
import Plug.Conn | |
import Phoenix.Controller | |
def render_blank(conn) do | |
conn | |
|> send_resp(204, "") | |
end | |
def render_error(conn, status, opts) do | |
conn | |
|> put_status(status) | |
|> render(MyApp.ErrorView, "#{status}.json", opts) | |
end | |
def ensure_current_user(conn, _) do | |
case conn.assigns.current_user do | |
nil -> render_error(conn, 401, message: "unauthorized") | |
current_user -> conn | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment