Created
May 4, 2018 09:00
-
-
Save shahryarjb/83016dcd2c1325377b2b23a5dc326795 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 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