Hash :
60c50e63
Author :
Thomas de Grivel
Date :
2021-11-19T17:46:49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
defmodule KmxgitWeb.Router do
use KmxgitWeb, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {KmxgitWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
# Our pipeline implements "maybe" authenticated. We'll use the `:ensure_auth` below for when we need to make sure someone is logged in.
pipeline :auth do
plug Kmxgit.UserManager.Pipeline
end
# We use ensure_auth to fail if there is no one logged in
pipeline :ensure_auth do
plug Guardian.Plug.EnsureAuthenticated
end
pipeline :admin do
plug Kmxgit.Plug.EnsureAdmin
plug :put_root_layout, {KmxgitWeb.LayoutView, "admin.html"}
end
# maybe logged in
scope "/", KmxgitWeb do
pipe_through [:browser, :auth]
get "/", PageController, :index
get "/_new_admin", PageController, :new_admin
post "/_new_admin", PageController, :new_admin_post
scope "/_sessions" do
get "/new", SessionController, :new
post "/new", SessionController, :login
get "/logout", SessionController, :logout
end
get "/_register", RegistrationController, :new
post "/_register", RegistrationController, :register
end
# definitely logged in, will redirect to login page
scope "/", KmxgitWeb do
pipe_through [:browser, :auth, :ensure_auth]
scope "/_new" do
get "/organisation", OrganisationController, :new
post "/organisation", OrganisationController, :create
get "/:owner", RepositoryController, :new
post "/:owner", RepositoryController, :create
end
scope "/_edit/" do
get "/organisation/:slug", OrganisationController, :edit
put "/organisation/:slug", OrganisationController, :update
get "/user/:login", UserController, :edit
put "/user/:login", UserController, :update
get "/:owner/*slug", RepositoryController, :edit
put "/:owner/*slug", RepositoryController, :update
end
scope "/admin", Admin, as: "admin" do
pipe_through :admin
get "/", DashboardController, :index
resources "/organisations", OrganisationController
resources "/users", UserController
import Phoenix.LiveDashboard.Router
live_dashboard "/dashboard", metrics: KmxgitWeb.Telemetry
end
end
# maybe logged in
scope "/", KmxgitWeb do
pipe_through [:browser, :auth]
get "/:slug", SlugController, :show
delete "/:slug", SlugController, :delete
get "/:owner/*slug", RepositoryController, :show
delete "/:owner/*slug", RepositoryController, :delete
end
# Other scopes may use custom stacks.
# scope "/api", KmxgitWeb do
# pipe_through :api
# end
# Enables the Swoosh mailbox preview in development.
#
# Note that preview only shows emails that were sent by the same
# node running the Phoenix server.
if Mix.env() == :dev do
scope "/dev" do
pipe_through :browser
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end
end