Skip to content

Instantly share code, notes, and snippets.

@shahryarjb
Created May 4, 2018 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahryarjb/83016dcd2c1325377b2b23a5dc326795 to your computer and use it in GitHub Desktop.
Save shahryarjb/83016dcd2c1325377b2b23a5dc326795 to your computer and use it in GitHub Desktop.
defmodule TrangellCmsService.Cms.Plugs.AdminChecker do
import Plug.Conn
import Phoenix.Controller
def init(_params) do
end
def call(%Plug.Conn{params: %{"acl" => acl}} = conn, params) do
admin_checker = case acl do
"admin" ->
assign(conn, :admin_checker, params)
_ ->
conn
|> put_status(403)
|> json(%{error_code: "403", error_msg: "You don't have an access."})
|> halt()
end
admin_checker
end
def call(conn, _params) do
conn
|> put_status(404)
|> halt()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment