chiya/lib/chiya_web/router.ex

108 lines
3 KiB
Elixir
Raw Normal View History

2023-03-05 16:07:40 +01:00
defmodule ChiyaWeb.Router do
use ChiyaWeb, :router
2023-03-05 16:13:00 +01:00
import ChiyaWeb.UserAuth
2023-03-09 21:43:56 +01:00
import ChiyaWeb.GlobalAssigns
2023-03-05 16:13:00 +01:00
2023-03-05 16:07:40 +01:00
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {ChiyaWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
2023-03-05 16:13:00 +01:00
plug :fetch_current_user
2023-03-05 16:07:40 +01:00
end
2023-03-09 21:43:56 +01:00
pipeline :public do
plug :fetch_settings
plug :fetch_identities
end
2023-03-05 16:07:40 +01:00
pipeline :api do
plug :accepts, ["json"]
end
# Other scopes may use custom stacks.
# scope "/api", ChiyaWeb do
# pipe_through :api
# end
# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:chiya, :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: ChiyaWeb.Telemetry
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end
2023-03-05 16:13:00 +01:00
## Administrator routes
scope "/admin", ChiyaWeb do
pipe_through [:browser, :require_authenticated_user]
resources "/channels", ChannelController
2023-03-09 07:28:06 +01:00
resources "/notes", NoteController, except: [:show]
2023-03-07 23:05:25 +01:00
resources "/settings", SettingController, singleton: true
2023-03-09 07:28:06 +01:00
live "/notes/:id", NoteShowLive, :show
end
2023-03-05 16:13:00 +01:00
## Authentication routes
scope "/", ChiyaWeb do
pipe_through [:browser, :redirect_if_user_is_authenticated]
live_session :redirect_if_user_is_authenticated,
on_mount: [{ChiyaWeb.UserAuth, :redirect_if_user_is_authenticated}] do
2023-03-07 21:15:26 +01:00
live "/user/register", UserRegistrationLive, :new
live "/user/log_in", UserLoginLive, :new
live "/user/reset_password", UserForgotPasswordLive, :new
live "/user/reset_password/:token", UserResetPasswordLive, :edit
2023-03-05 16:13:00 +01:00
end
2023-03-07 21:15:26 +01:00
post "/user/log_in", UserSessionController, :create
2023-03-05 16:13:00 +01:00
end
scope "/", ChiyaWeb do
pipe_through [:browser, :require_authenticated_user]
live_session :require_authenticated_user,
on_mount: [{ChiyaWeb.UserAuth, :ensure_authenticated}] do
2023-03-07 21:24:24 +01:00
live "/user", UserProfileLive, :show
2023-03-07 21:15:26 +01:00
live "/user/settings", UserSettingsLive, :edit
live "/user/settings/confirm_email/:token", UserSettingsLive, :confirm_email
2023-03-05 16:13:00 +01:00
end
end
scope "/", ChiyaWeb do
pipe_through [:browser]
2023-03-07 21:15:26 +01:00
delete "/user/log_out", UserSessionController, :delete
2023-03-05 16:13:00 +01:00
live_session :current_user,
on_mount: [{ChiyaWeb.UserAuth, :mount_current_user}] do
2023-03-07 21:15:26 +01:00
live "/user/confirm/:token", UserConfirmationLive, :edit
live "/user/confirm", UserConfirmationInstructionsLive, :new
2023-03-05 16:13:00 +01:00
end
end
2023-03-09 15:50:22 +01:00
## Public routes
scope "/", ChiyaWeb do
2023-03-09 21:43:56 +01:00
pipe_through [:browser, :public]
2023-03-09 15:50:22 +01:00
get "/:slug", PageController, :channel
get "/", PageController, :home
end
2023-03-05 16:07:40 +01:00
end