Created
September 22, 2015 02:30
-
-
Save luketlancaster/e919873e65ea9c0d1f16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Support.Router do | |
use Support.Web, :router | |
pipeline :browser do | |
plug :accepts, ["html"] | |
plug :fetch_session | |
plug :fetch_flash | |
plug :protect_from_forgery | |
plug :put_secure_browser_headers | |
plug :assign_current_user | |
end | |
pipeline :api do | |
plug :accepts, ["json"] | |
end | |
scope "/api", Support do | |
pipe_through :api | |
resources "/users", UserController, except: [:new, :edit, :create, :delete] | |
end | |
scope "/", Support do | |
pipe_through :browser # Use the default browser stack | |
get "/register", RegistrationController, :new | |
post "/register", RegistrationController, :create | |
get "/login", SessionController, :new | |
post "/login", SessionController, :create | |
delete "/logout", SessionController, :delete | |
get "/", PageController, :index | |
end | |
defp assign_current_user(conn, _) do | |
if current_user_id = get_session(conn, :current_user) do | |
user = Support.Repo.get(Support.User, current_user_id) | |
assign(conn, :current_user, user) | |
else | |
assign(conn, :current_user, nil) | |
end | |
end | |
# Other scopes may use custom stacks. | |
# scope "/api", Support do | |
# pipe_through :api | |
# end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment