@@ -45,15 +45,17 @@ type Context struct {
45
45
Flash * middleware.Flash
46
46
Session session.Store
47
47
48
- Link string // current request URL (without query string)
49
- Doer * user_model.User
48
+ Link string // current request URL (without query string)
49
+
50
+ Doer * user_model.User // current signed-in user
50
51
IsSigned bool
51
52
IsBasicAuth bool
52
53
53
- ContextUser * user_model.User
54
- Repo * Repository
55
- Org * Organization
56
- Package * Package
54
+ ContextUser * user_model.User // the user which is being visited, in most cases it differs from Doer
55
+
56
+ Repo * Repository
57
+ Org * Organization
58
+ Package * Package
57
59
}
58
60
59
61
// TrHTMLEscapeArgs runs ".Locale.Tr()" but pre-escapes all arguments with html.EscapeString.
@@ -75,17 +77,17 @@ func GetContext(req *http.Request) *Context {
75
77
return ctx
76
78
}
77
79
80
+ // ValidateContext is a special context for form validation middleware. It may be different from other contexts.
78
81
type ValidateContext struct {
79
82
* Base
80
- Locale translation.Locale
81
83
}
82
84
83
85
// GetValidateContext gets a context for middleware form validation
84
86
func GetValidateContext (req * http.Request ) (ctx * ValidateContext ) {
85
87
if ctxAPI , ok := req .Context ().Value (apiContextKey ).(* APIContext ); ok {
86
- ctx = & ValidateContext {Base : ctxAPI .Base , Locale : ctxAPI . Base . Locale }
88
+ ctx = & ValidateContext {Base : ctxAPI .Base }
87
89
} else if ctxWeb , ok := req .Context ().Value (contextKey ).(* Context ); ok {
88
- ctx = & ValidateContext {Base : ctxWeb .Base , Locale : ctxWeb . Base . Locale }
90
+ ctx = & ValidateContext {Base : ctxWeb .Base }
89
91
} else {
90
92
panic ("invalid context, expect either APIContext or Context" )
91
93
}
@@ -203,7 +205,7 @@ func (ctx *Context) HasError() bool {
203
205
if ! ok {
204
206
return false
205
207
}
206
- ctx .Flash .ErrorMsg = ctx .Data [ "ErrorMsg" ].( string )
208
+ ctx .Flash .ErrorMsg = ctx .GetErrMsg ( )
207
209
ctx .Data ["Flash" ] = ctx .Flash
208
210
return hasErr .(bool )
209
211
}
0 commit comments