diff options
| author | 2025-10-28 23:15:23 +0700 | |
|---|---|---|
| committer | 2025-10-28 23:15:23 +0700 | |
| commit | bda4faeeed4d9859cfe8afd7952a751683d74bd8 (patch) | |
| tree | 464c18fed0c21b63b65425f48a3a790229461058 /internal/router/handlers/api-v1-email-is-in-verification.go | |
| parent | dd69b45d3a41be2b5c38892c3b107770a0f859f2 (diff) | |
| parent | 1862f232eb70105340a91e74a5630c233a411bca (diff) | |
| download | web-0.11.1.tar.gz web-0.11.1.zip | |
v0.11.1 (#18)v0.11.1
- refactor: make structurized implementation of routes + separate
identity of router
- feat: update go to 1.25
- feat: update all dependencies
- debug: display routes when debug logs turned on
Diffstat (limited to 'internal/router/handlers/api-v1-email-is-in-verification.go')
| -rw-r--r-- | internal/router/handlers/api-v1-email-is-in-verification.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/internal/router/handlers/api-v1-email-is-in-verification.go b/internal/router/handlers/api-v1-email-is-in-verification.go new file mode 100644 index 0000000..4f05f48 --- /dev/null +++ b/internal/router/handlers/api-v1-email-is-in-verification.go @@ -0,0 +1,59 @@ +package handlers + +import ( + "fmt" + "html/template" + "strings" + + "github.com/SayaAndy/saya-today-web/internal/router" + "github.com/gofiber/fiber/v2" +) + +type OngoingVerificationHandler struct { + router.BasicHandler +} + +func init() { + router.Routes = append(router.Routes, &OngoingVerificationHandler{}) +} + +func (r *OngoingVerificationHandler) Filter() (method string, path string) { + return "GET", "/api/v1/email/is-in-verification" +} + +func (r *OngoingVerificationHandler) IsTemplated() bool { + return false +} + +func (r *OngoingVerificationHandler) TemplatesToInject() []string { + return []string{"views/partials/personal-page-status.html"} +} + +func (r *OngoingVerificationHandler) ToCache() router.CacheSetting { + return router.Disabled +} + +func (r *OngoingVerificationHandler) ToValidateLang() router.LangSetting { + return router.InReferer +} + +func (r *OngoingVerificationHandler) Render(c *fiber.Ctx, supplements *router.Supplements, lang string, templateMap fiber.Map) (statusCode int, err error) { + isAllowed, whenAllowed, codeExpiry := supplements.Mailer.IsAllowedToRetryVerification(c.IP()) + + sterileDataset := make(map[string]any) + sterileDataset["code-expiry-time"] = template.HTMLAttr(fmt.Sprintf("data-code-expiry-time=\"%d\"", codeExpiry.UnixMilli())) + + templateMap["StatusId"] = "email-message" + templateMap["DataAttributes"] = sterileDataset + + if !isAllowed { + sterileDataset["striked-end-time"] = template.HTMLAttr(fmt.Sprintf("data-striked-end-time=\"%d\"", whenAllowed.UnixMilli())) + templateMap["Status"] = "Neutral" + templateMap["Message"] = strings.ReplaceAll(supplements.Localization[lang].UserProfile.DelayTilVerification, "{}", whenAllowed.Format("2006-01-02 15:04:05 MST")) + } else { + templateMap["Status"] = "OK" + templateMap["Message"] = "" + } + + return fiber.StatusOK, nil +} |