diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-07-15 16:52:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-15 11:52:03 +0300 |
commit | 9672085d940830f2e2e6d6f71e0e9900db5284a4 (patch) | |
tree | cd6a6df1dabe542cf832d3ce0921fb268fe4305a /modules/web/middleware/flash.go | |
parent | faf28b28233b18289e0a398ea22265bb87b1e1b5 (diff) | |
download | gitea-9672085d940830f2e2e6d6f71e0e9900db5284a4.tar.gz gitea-9672085d940830f2e2e6d6f71e0e9900db5284a4.zip |
Fix "Flash" message usage (#25895)
Resolve https://github.com/go-gitea/gitea/pull/25820/files#r1264309059
Diffstat (limited to 'modules/web/middleware/flash.go')
-rw-r--r-- | modules/web/middleware/flash.go | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/modules/web/middleware/flash.go b/modules/web/middleware/flash.go index fa29ddeffc..41f3aac27c 100644 --- a/modules/web/middleware/flash.go +++ b/modules/web/middleware/flash.go @@ -5,17 +5,6 @@ package middleware import "net/url" -// flashes enumerates all the flash types -const ( - SuccessFlash = "SuccessMsg" - ErrorFlash = "ErrorMsg" - WarnFlash = "WarningMsg" - InfoFlash = "InfoMsg" -) - -// FlashNow FIXME: -var FlashNow bool - // Flash represents a one time data transfer between two requests. type Flash struct { DataStore ContextDataStore @@ -27,15 +16,12 @@ func (f *Flash) set(name, msg string, current ...bool) { if f.Values == nil { f.Values = make(map[string][]string) } - isShow := false - if (len(current) == 0 && FlashNow) || - (len(current) > 0 && current[0]) { - isShow = true - } - - if isShow { + showInCurrentPage := len(current) > 0 && current[0] + if showInCurrentPage { + // assign it to the context data, then the template can use ".Flash.XxxMsg" to render the message f.DataStore.GetData()["Flash"] = f } else { + // the message map will be saved into the cookie and be shown in next response (a new page response which decodes the cookie) f.Set(name, msg) } } |