85 lines
2.3 KiB
Elixir
85 lines
2.3 KiB
Elixir
defmodule DexiWeb.Router do
|
|
use DexiWeb, :router
|
|
|
|
import DexiWeb.UserAuth
|
|
|
|
pipeline :browser do
|
|
plug :accepts, ["html"]
|
|
plug :fetch_session
|
|
plug :fetch_live_flash
|
|
plug :put_root_layout, html: {DexiWeb.Layouts, :root}
|
|
plug :protect_from_forgery
|
|
plug :put_secure_browser_headers
|
|
plug DexiWeb.SessionIdPlug
|
|
plug :fetch_current_scope
|
|
end
|
|
|
|
pipeline :api do
|
|
plug :accepts, ["json"]
|
|
end
|
|
|
|
pipeline :authenticated_user do
|
|
plug :require_authenticated_user
|
|
end
|
|
|
|
pipeline :admin_user do
|
|
plug :require_admin
|
|
end
|
|
|
|
scope "/", DexiWeb do
|
|
pipe_through :browser
|
|
|
|
get "/", PageController, :home
|
|
get "/session/:message_id", SessionController, :create
|
|
delete "/logout", SessionController, :delete
|
|
|
|
live_session :public, on_mount: [{DexiWeb.UserAuth, :mount_current_scope}] do
|
|
live "/login", LoginLive, :index
|
|
end
|
|
end
|
|
|
|
scope "/", DexiWeb do
|
|
pipe_through [:browser, :authenticated_user]
|
|
|
|
live_session :authenticated,
|
|
on_mount: [{DexiWeb.UserAuth, :require_authenticated}] do
|
|
live "/account", ProfileLive, :edit
|
|
end
|
|
end
|
|
|
|
scope "/admin", DexiWeb.Admin do
|
|
pipe_through [:browser, :authenticated_user, :admin_user]
|
|
|
|
live_session :admin, on_mount: [{DexiWeb.UserAuth, :require_admin}] do
|
|
live "/users", UsersLive, :index
|
|
end
|
|
end
|
|
|
|
scope "/api", DexiWeb do
|
|
pipe_through :api
|
|
|
|
get "/signature/:message_id", DeadDropController, :show
|
|
post "/signature/:message_id", DeadDropController, :login
|
|
|
|
get "/sign/:message_id", SignTxController, :show
|
|
post "/sign/:message_id", SignTxController, :sign
|
|
end
|
|
|
|
# Enable LiveDashboard and Swoosh mailbox preview in development
|
|
if Application.compile_env(:dexi, :dev_routes) do
|
|
# If you want to use the LiveDashboard in production, you should put
|
|
# it behind authentication and allow only admins to access it.
|
|
# If your application does not have an admins-only section yet,
|
|
# you can use Plug.BasicAuth to set up some basic authentication
|
|
# as long as you are also using SSL (which you should anyway).
|
|
import Phoenix.LiveDashboard.Router
|
|
|
|
scope "/dev" do
|
|
pipe_through :browser
|
|
|
|
live_dashboard "/dashboard", metrics: DexiWeb.Telemetry
|
|
forward "/mailbox", Plug.Swoosh.MailboxPreview
|
|
end
|
|
end
|
|
end
|