Skip to content

Instantly share code, notes, and snippets.

@Devalo
Last active April 20, 2016 17:37
Show Gist options
  • Save Devalo/af3581ff386816c0690b1c098186ca27 to your computer and use it in GitHub Desktop.
Save Devalo/af3581ff386816c0690b1c098186ca27 to your computer and use it in GitHub Desktop.
def index(conn, _params) do
case authenticate(conn) do
%Plug.Conn{halted: true} = conn ->
conn
conn ->
users = Repo.all(User)
render conn, "index.html", users: users
end
end
defp authenticate(conn) do
if conn.assigns.current_user do
conn
else
conn
|> put_flash(:error, "You must be logged in to access this page")
|> redirect(to: page_path(conn, :index))
|> halt()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment