2022-08-10 05:10:47 +00:00
|
|
|
// Package router configures web routes.
|
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/config"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/controller/account"
|
2022-08-13 22:39:31 +00:00
|
|
|
"git.kirsle.net/apps/gosocial/pkg/controller/admin"
|
2022-08-10 05:10:47 +00:00
|
|
|
"git.kirsle.net/apps/gosocial/pkg/controller/api"
|
2022-08-15 00:45:55 +00:00
|
|
|
"git.kirsle.net/apps/gosocial/pkg/controller/block"
|
2022-08-14 05:44:57 +00:00
|
|
|
"git.kirsle.net/apps/gosocial/pkg/controller/friend"
|
2022-08-14 00:42:42 +00:00
|
|
|
"git.kirsle.net/apps/gosocial/pkg/controller/inbox"
|
2022-08-10 05:10:47 +00:00
|
|
|
"git.kirsle.net/apps/gosocial/pkg/controller/index"
|
2022-08-12 06:03:06 +00:00
|
|
|
"git.kirsle.net/apps/gosocial/pkg/controller/photo"
|
2022-08-10 05:10:47 +00:00
|
|
|
"git.kirsle.net/apps/gosocial/pkg/middleware"
|
|
|
|
)
|
|
|
|
|
|
|
|
func New() http.Handler {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
|
|
// Register controller endpoints.
|
|
|
|
mux.HandleFunc("/", index.Create())
|
|
|
|
mux.HandleFunc("/login", account.Login())
|
|
|
|
mux.HandleFunc("/logout", account.Logout())
|
|
|
|
mux.HandleFunc("/signup", account.Signup())
|
2022-08-14 21:40:57 +00:00
|
|
|
mux.HandleFunc("/forgot-password", account.ForgotPassword())
|
|
|
|
mux.HandleFunc("/settings/confirm-email", account.ConfirmEmailChange())
|
2022-08-10 05:10:47 +00:00
|
|
|
|
2022-08-13 22:39:31 +00:00
|
|
|
// Login Required. Pages that non-certified users can access.
|
2022-08-10 05:10:47 +00:00
|
|
|
mux.Handle("/me", middleware.LoginRequired(account.Dashboard()))
|
2022-08-11 03:59:59 +00:00
|
|
|
mux.Handle("/settings", middleware.LoginRequired(account.Settings()))
|
2022-08-14 21:40:57 +00:00
|
|
|
mux.Handle("/account/delete", middleware.LoginRequired(account.Delete()))
|
2022-08-11 03:59:59 +00:00
|
|
|
mux.Handle("/u/", middleware.LoginRequired(account.Profile()))
|
2022-08-12 06:03:06 +00:00
|
|
|
mux.Handle("/photo/upload", middleware.LoginRequired(photo.Upload()))
|
2022-08-13 06:11:36 +00:00
|
|
|
mux.Handle("/photo/u/", middleware.LoginRequired(photo.UserPhotos()))
|
|
|
|
mux.Handle("/photo/edit", middleware.LoginRequired(photo.Edit()))
|
|
|
|
mux.Handle("/photo/delete", middleware.LoginRequired(photo.Delete()))
|
2022-08-13 22:39:31 +00:00
|
|
|
mux.Handle("/photo/certification", middleware.LoginRequired(photo.Certification()))
|
2022-08-14 00:42:42 +00:00
|
|
|
mux.Handle("/messages", middleware.LoginRequired(inbox.Inbox()))
|
|
|
|
mux.Handle("/messages/read/", middleware.LoginRequired(inbox.Inbox()))
|
|
|
|
mux.Handle("/messages/compose", middleware.LoginRequired(inbox.Compose()))
|
2022-08-14 05:44:57 +00:00
|
|
|
mux.Handle("/friends", middleware.LoginRequired(friend.Friends()))
|
|
|
|
mux.Handle("/friends/add", middleware.LoginRequired(friend.AddFriend()))
|
2022-08-15 00:45:55 +00:00
|
|
|
mux.Handle("/users/block", middleware.LoginRequired(block.BlockUser()))
|
|
|
|
mux.Handle("/users/blocked", middleware.LoginRequired(block.Blocked()))
|
2022-08-14 23:27:57 +00:00
|
|
|
mux.Handle("/admin/unimpersonate", middleware.LoginRequired(admin.Unimpersonate()))
|
2022-08-13 22:39:31 +00:00
|
|
|
|
|
|
|
// Certification Required. Pages that only full (verified) members can access.
|
|
|
|
mux.Handle("/photo/gallery", middleware.CertRequired(photo.SiteGallery()))
|
2022-08-14 05:44:57 +00:00
|
|
|
mux.Handle("/members", middleware.CertRequired(account.Search()))
|
2022-08-13 22:39:31 +00:00
|
|
|
|
|
|
|
// Admin endpoints.
|
|
|
|
mux.Handle("/admin", middleware.AdminRequired(admin.Dashboard()))
|
|
|
|
mux.Handle("/admin/photo/certification", middleware.AdminRequired(photo.AdminCertification()))
|
2022-08-14 23:27:57 +00:00
|
|
|
mux.Handle("/admin/user-action", middleware.AdminRequired(admin.UserActions()))
|
2022-08-10 05:10:47 +00:00
|
|
|
|
|
|
|
// JSON API endpoints.
|
|
|
|
mux.HandleFunc("/v1/version", api.Version())
|
|
|
|
mux.HandleFunc("/v1/users/me", api.LoginOK())
|
|
|
|
|
|
|
|
// Static files.
|
|
|
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(config.StaticPath))))
|
|
|
|
|
|
|
|
// Global middlewares.
|
|
|
|
withSession := middleware.Session(mux)
|
|
|
|
withCSRF := middleware.CSRF(withSession)
|
|
|
|
withRecovery := middleware.Recovery(withCSRF)
|
|
|
|
withLogger := middleware.Logging(withRecovery)
|
|
|
|
return withLogger
|
|
|
|
}
|