chiya/lib/chiya_web/router.ex

147 lines
4.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
2023-03-15 15:58:17 +01:00
plug :put_root_layout, {ChiyaWeb.Layouts, :root_app}
2023-03-05 16:07:40 +01:00
plug :protect_from_forgery
plug :put_secure_browser_headers
2023-03-05 16:13:00 +01:00
plug :fetch_current_user
plug :fetch_settings
2023-03-05 16:07:40 +01:00
end
2023-03-09 21:43:56 +01:00
pipeline :public do
2023-03-15 15:58:17 +01:00
plug :put_root_layout, {ChiyaWeb.Layouts, :root_public}
2023-03-09 21:43:56 +01:00
plug :fetch_identities
2023-03-31 12:15:07 +02:00
plug :fetch_public_channels
2023-03-09 21:43:56 +01:00
end
2023-03-05 16:07:40 +01:00
pipeline :api do
plug :accepts, ["json"]
end
pipeline :indie do
plug :accepts, ["json", "html"]
end
2023-03-05 16:07:40 +01:00
# Other scopes may use custom stacks.
2023-03-22 07:31:38 +01:00
scope "/api", ChiyaWeb do
pipe_through :api
get "/admin/notes", ApiController, :notes
end
2023-03-05 16:07:40 +01:00
2023-05-31 21:56:42 +02:00
## Indie routes
scope "/indie" do
forward "/micropub",
PlugMicropub,
2023-06-11 09:18:00 +02:00
handler: ChiyaWeb.Indie.MicropubHandler,
2023-05-31 21:56:42 +02:00
json_encoder: Jason
end
2023-03-05 16:07:40 +01:00
# 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]
live "/", AdminHomeLive, :index
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 21:45:43 +01:00
resources "/identities", IdentityController
2023-05-09 16:18:10 +02:00
resources "/comments", CommentController, only: [:index, :show]
2023-06-06 22:00:42 +02:00
resources "/tokens", TokenController, only: [:index, :show, :new, :create, :delete]
2023-03-09 07:28:06 +01:00
2023-04-07 11:37:55 +02:00
get "/notes/import", NoteController, :import_prepare
post "/notes/import", NoteController, :import_run
2023-03-09 07:28:06 +01:00
live "/notes/:id", NoteShowLive, :show
2023-03-31 22:20:32 +02:00
get "/notes/:id/raw", NoteController, :raw
2023-05-21 09:53:17 +02:00
get "/notes/:id/publish", NoteController, :publish
get "/notes/:id/unpublish", NoteController, :unpublish
get "/notes/:id/image/:image_id", NoteController, :edit_image
put "/notes/:id/image/:image_id", NoteController, :update_image
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
2023-06-02 07:07:22 +02:00
get "/note/:slug", PageController, :note
get "/channel/:slug", PageController, :channel
get "/tagged-with/:slug", PageController, :tag
2023-04-30 13:35:22 +02:00
2023-06-02 07:31:47 +02:00
get "/about", PageController, :about
2023-07-03 20:46:16 +02:00
get "/", PageController, :home
2023-06-11 20:49:18 +02:00
# TODO: Comments are disabled for now
# and need a better submit/approve flow
# post "/note/:slug/comment", CommentController, :create
2023-03-09 15:50:22 +01:00
end
2023-03-05 16:07:40 +01:00
end