refac: separated api content into sub-packages & renamed usecases

This commit is contained in:
Florian Sylvain
2025-03-13 19:43:12 +01:00
parent 7e29c08ea9
commit 4d6054e22b
38 changed files with 181 additions and 152 deletions
+36
View File
@@ -0,0 +1,36 @@
package pages
import (
"GoCMS/api"
"GoCMS/api/controllers/auth"
"log"
"net/http"
"github.com/go-chi/jwtauth/v5"
)
func PostRegisterPendingPage(w http.ResponseWriter, r *http.Request) {
token, _ := jwtauth.VerifyRequest(
auth.Token, r,
jwtauth.TokenFromCookie,
jwtauth.TokenFromHeader,
jwtauth.TokenFromQuery)
userId := token.PrivateClaims()["user_id"].(float64)
err := api.Container.DeleteUserUseCase.DeleteUser(uint32(userId))
if err != nil {
log.Println(err)
r.Method = http.MethodGet
http.Redirect(w, r, "/register/pending", http.StatusSeeOther)
}
auth.RemoveJwtCookie(w)
http.Redirect(w, r, "/register", http.StatusSeeOther)
}
func GetRegisterPendingPage(w http.ResponseWriter, _ *http.Request) {
registerPendingTmpl, _ := api.Container.GetPageUseCase.GetPage("registerPending", map[string]interface{}{
"Head": headTmpl,
})
_, _ = w.Write(registerPendingTmpl)
}