aboutsummaryrefslogtreecommitdiffstats
path: root/services/context
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2025-01-25 22:36:47 +0800
committerGitHub <noreply@github.com>2025-01-25 14:36:47 +0000
commit2c1ff8701a7aeafc86f87c286514768cdf121ccb (patch)
treeed398c8afa3d6b0c84136cc756f12d76dd585279 /services/context
parent6a516a0d14907d3bee390696f31bea3cd8a83418 (diff)
downloadgitea-2c1ff8701a7aeafc86f87c286514768cdf121ccb.tar.gz
gitea-2c1ff8701a7aeafc86f87c286514768cdf121ccb.zip
Refactor context flash msg and global variables (#33375)
1. add `GetSiteCookieFlashMessage` to help to parse flash message 2. clarify `handleRepoHomeFeed` logic 3. remove unnecessary global variables, use `sync.OnceValue` instead 4. add some tests for `IsUsableUsername` and `IsUsableRepoName`
Diffstat (limited to 'services/context')
-rw-r--r--services/context/context.go14
1 files changed, 3 insertions, 11 deletions
diff --git a/services/context/context.go b/services/context/context.go
index 6715c5663d..5b16f9be98 100644
--- a/services/context/context.go
+++ b/services/context/context.go
@@ -165,18 +165,10 @@ func Contexter() func(next http.Handler) http.Handler {
ctx.Base.SetContextValue(WebContextKey, ctx)
ctx.Csrf = NewCSRFProtector(csrfOpts)
- // Get the last flash message from cookie
- lastFlashCookie := middleware.GetSiteCookie(ctx.Req, CookieNameFlash)
+ // get the last flash message from cookie
+ lastFlashCookie, lastFlashMsg := middleware.GetSiteCookieFlashMessage(ctx, ctx.Req, CookieNameFlash)
if vals, _ := url.ParseQuery(lastFlashCookie); len(vals) > 0 {
- // store last Flash message into the template data, to render it
- ctx.Data["Flash"] = &middleware.Flash{
- DataStore: ctx,
- Values: vals,
- ErrorMsg: vals.Get("error"),
- SuccessMsg: vals.Get("success"),
- InfoMsg: vals.Get("info"),
- WarningMsg: vals.Get("warning"),
- }
+ ctx.Data["Flash"] = lastFlashMsg // store last Flash message into the template data, to render it
}
// if there are new messages in the ctx.Flash, write them into cookie