This commit is contained in:
Mirai Kumiko 2025-07-04 10:25:40 +02:00
parent b35e18cd20
commit 82f55f7afe
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
80 changed files with 6687 additions and 5 deletions

View file

@ -1,6 +1,8 @@
defmodule NullaWeb.Router do
use NullaWeb, :router
import NullaWeb.UserAuth
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
@ -8,10 +10,12 @@ defmodule NullaWeb.Router do
plug :put_root_layout, html: {NullaWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
end
pipeline :api do
plug :accepts, ["json"]
plug :fetch_api_user
end
scope "/", NullaWeb do
@ -20,10 +24,15 @@ defmodule NullaWeb.Router do
get "/", PageController, :home
end
# Other scopes may use custom stacks.
# scope "/api", NullaWeb do
# pipe_through :api
# end
scope "/api", NullaWeb do
pipe_through :api
resources "/actors", ActorController, except: [:new, :edit]
resources "/notes", NoteController, except: [:new, :edit]
resources "/media_attachments", MediaAttachmentController, except: [:new, :edit]
resources "/relations", RelationController, except: [:new, :edit]
resources "/activities", ActivityController, except: [:new, :edit]
end
# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:nulla, :dev_routes) do
@ -41,4 +50,42 @@ defmodule NullaWeb.Router do
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end
## Authentication routes
scope "/", NullaWeb do
pipe_through [:browser, :redirect_if_user_is_authenticated]
live_session :redirect_if_user_is_authenticated,
on_mount: [{NullaWeb.UserAuth, :redirect_if_user_is_authenticated}] do
live "/users/register", UserRegistrationLive, :new
live "/users/log_in", UserLoginLive, :new
live "/users/reset_password", UserForgotPasswordLive, :new
live "/users/reset_password/:token", UserResetPasswordLive, :edit
end
post "/users/log_in", UserSessionController, :create
end
scope "/", NullaWeb do
pipe_through [:browser, :require_authenticated_user]
live_session :require_authenticated_user,
on_mount: [{NullaWeb.UserAuth, :ensure_authenticated}] do
live "/users/settings", UserSettingsLive, :edit
live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email
end
end
scope "/", NullaWeb do
pipe_through [:browser]
delete "/users/log_out", UserSessionController, :delete
live_session :current_user,
on_mount: [{NullaWeb.UserAuth, :mount_current_user}] do
live "/users/confirm/:token", UserConfirmationLive, :edit
live "/users/confirm", UserConfirmationInstructionsLive, :new
end
end
end