Skip to content

Commit

Permalink
Added admin scope to router
Browse files Browse the repository at this point in the history
  • Loading branch information
riverrun committed May 27, 2015
1 parent 1c1e7a6 commit 9bab8b2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
9 changes: 9 additions & 0 deletions web/controllers/admin_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Welcome.AdminController do
use Welcome.Web, :controller

plug :action

def index(conn, _params) do
render conn, "index.html"
end
end
2 changes: 2 additions & 0 deletions web/controllers/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ defmodule Welcome.UserController do
end

def login_user(conn, _params) do
IO.puts "*****Should we be seeing this?*****"
Openmaize.Login.call(conn, [])
end

def logout(conn, _params) do
IO.puts "*****Should we be seeing this?*****"
Openmaize.Logout.call(conn, [])
end

Expand Down
35 changes: 22 additions & 13 deletions web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,38 @@ defmodule Welcome.Router do
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :open_sesame
end

pipeline :authenticate do
plug :open_maize
end

pipeline :api do
plug :accepts, ["json"]
end

scope "/", Welcome do
pipe_through :browser # Use the default browser stack
pipe_through :browser

get "/", PageController, :index, as: :root
get "/users/login", UserController, :login, as: :login
post "/users/login", UserController, :login_user, as: :login
post "/users/logout", UserController, :logout, as: :logout
resources "/users", UserController
end

def open_sesame(conn, opts \\ []) do
auth_list = ["users"]
if Enum.any?(conn.path_info, fn x -> x in auth_list end) do
Openmaize.Authenticate.call(conn, opts)
else
conn
end
scope "/users", Welcome do
pipe_through [:browser, :authenticate]

get "/login", UserController, :login, as: :login
post "/login", UserController, :login_user, as: :login
get "/logout", UserController, :logout, as: :logout
resources "/", UserController
end

scope "/admin", Welcome do
pipe_through [:browser, :authenticate]

get "/", AdminController, :index
end

def open_maize(conn, opts \\ []) do
Openmaize.Authenticate.call(conn, opts)
end
end
4 changes: 4 additions & 0 deletions web/templates/admin/index.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="jumbotron">
<h2>Hello big boss!</h2>
<p class="lead">Shouldn't you be taking it easy?</p>
</div>
2 changes: 1 addition & 1 deletion web/templates/layout/application.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="<%= login_path @conn, :login %>">Login</a></li>
<li><a href="<%= logout_path @conn, :logout, method: :post %>">Logout</a></li>
<li><a href="<%= logout_path @conn, :logout %>">Logout</a></li>
</ul>
</nav>

Expand Down
3 changes: 3 additions & 0 deletions web/views/admin_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Welcome.AdminView do
use Welcome.Web, :view
end

0 comments on commit 9bab8b2

Please sign in to comment.