File tree Expand file tree Collapse file tree 5 files changed +23
-28
lines changed Expand file tree Collapse file tree 5 files changed +23
-28
lines changed Original file line number Diff line number Diff line change @@ -378,6 +378,15 @@ func (ctx *APIContext) HasAPIError() bool {
378
378
return hasErr .(bool )
379
379
}
380
380
381
+ // GetErrMsg returns error message in form validation.
382
+ func (ctx * APIContext ) GetErrMsg () string {
383
+ msg , _ := ctx .Data ["ErrorMsg" ].(string )
384
+ if msg == "" {
385
+ msg = "invalid form data"
386
+ }
387
+ return msg
388
+ }
389
+
381
390
// NotFoundOrServerError use error check function to determine if the error
382
391
// is about not found. It responds with 404 status code for not found error,
383
392
// or error context description for logging purpose of 500 server error.
Original file line number Diff line number Diff line change @@ -34,10 +34,9 @@ type Base struct {
34
34
35
35
Resp ResponseWriter
36
36
Req * http.Request
37
+ Data middleware.ContextData // data used by MVC templates, it's also used to pass data between middlewares/handler
37
38
38
39
Locale translation.Locale
39
-
40
- Data middleware.ContextData // data used by MVC templates
41
40
}
42
41
43
42
func (b * Base ) Deadline () (deadline time.Time , ok bool ) {
@@ -75,15 +74,6 @@ func (b *Base) GetData() middleware.ContextData {
75
74
return b .Data
76
75
}
77
76
78
- func (b * Base ) GetErrMsg () string {
79
- return b .Data ["ErrorMsg" ].(string )
80
- }
81
-
82
- func (b * Base ) HasValue (name string ) bool {
83
- _ , ok := b .Data [name ]
84
- return ok
85
- }
86
-
87
77
// AppendAccessControlExposeHeaders append headers by name to "Access-Control-Expose-Headers" header
88
78
func (b * Base ) AppendAccessControlExposeHeaders (names ... string ) {
89
79
val := b .RespHeader ().Get ("Access-Control-Expose-Headers" )
Original file line number Diff line number Diff line change @@ -190,3 +190,12 @@ func (ctx *Context) HasError() bool {
190
190
ctx .Data ["Flash" ] = ctx .Flash
191
191
return hasErr .(bool )
192
192
}
193
+
194
+ // GetErrMsg returns error message in form validation.
195
+ func (ctx * Context ) GetErrMsg () string {
196
+ msg , _ := ctx .Data ["ErrorMsg" ].(string )
197
+ if msg == "" {
198
+ msg = "invalid form data"
199
+ }
200
+ return msg
201
+ }
Original file line number Diff line number Diff line change @@ -10,10 +10,9 @@ import (
10
10
// ResponseWriter represents a response writer for HTTP
11
11
type ResponseWriter interface {
12
12
http.ResponseWriter
13
- Flush ()
13
+ http. Flusher
14
14
Status () int
15
15
Before (func (ResponseWriter ))
16
- Size () int
17
16
}
18
17
19
18
var _ ResponseWriter = & Response {}
@@ -27,11 +26,6 @@ type Response struct {
27
26
beforeExecuted bool
28
27
}
29
28
30
- // Size return written size
31
- func (r * Response ) Size () int {
32
- return r .written
33
- }
34
-
35
29
// Write writes bytes to HTTP endpoint
36
30
func (r * Response ) Write (bs []byte ) (int , error ) {
37
31
if ! r .beforeExecuted {
@@ -65,7 +59,7 @@ func (r *Response) WriteHeader(statusCode int) {
65
59
}
66
60
}
67
61
68
- // Flush flush cached data
62
+ // Flush flushes cached data
69
63
func (r * Response ) Flush () {
70
64
if f , ok := r .ResponseWriter .(http.Flusher ); ok {
71
65
f .Flush ()
Original file line number Diff line number Diff line change @@ -247,15 +247,8 @@ func SubmitInstall(ctx *context.Context) {
247
247
ctx .Data ["CurDbType" ] = form .DbType
248
248
249
249
if ctx .HasError () {
250
- if ctx .HasValue ("Err_SMTPUser" ) {
251
- ctx .Data ["Err_SMTP" ] = true
252
- }
253
- if ctx .HasValue ("Err_AdminName" ) ||
254
- ctx .HasValue ("Err_AdminPasswd" ) ||
255
- ctx .HasValue ("Err_AdminEmail" ) {
256
- ctx .Data ["Err_Admin" ] = true
257
- }
258
-
250
+ ctx .Data ["Err_SMTP" ] = ctx .Data ["Err_SMTPUser" ] != nil
251
+ ctx .Data ["Err_Admin" ] = ctx .Data ["Err_AdminName" ] != nil || ctx .Data ["Err_AdminPasswd" ] != nil || ctx .Data ["Err_AdminEmail" ] != nil
259
252
ctx .HTML (http .StatusOK , tplInstall )
260
253
return
261
254
}
You can’t perform that action at this time.
0 commit comments