@@ -20,7 +20,7 @@ type BaseController struct {
20
20
actionName string
21
21
}
22
22
23
- //初始化参数
23
+ // 初始化参数
24
24
func (s * BaseController ) Prepare () {
25
25
s .Data ["web_base_url" ] = beego .AppConfig .String ("web_base_url" )
26
26
controllerName , actionName := s .GetControllerAndAction ()
@@ -33,6 +33,9 @@ func (s *BaseController) Prepare() {
33
33
timestamp := s .GetIntNoErr ("timestamp" )
34
34
configKey := beego .AppConfig .String ("auth_key" )
35
35
timeNowUnix := time .Now ().Unix ()
36
+ if configKey == "" {
37
+ configKey = crypt .GetRandomString (128 )
38
+ }
36
39
if ! (md5Key != "" && (math .Abs (float64 (timeNowUnix - int64 (timestamp ))) <= 20 ) && (crypt .Md5 (configKey + strconv .Itoa (timestamp )) == md5Key )) {
37
40
if s .GetSession ("auth" ) != true {
38
41
s .Redirect (beego .AppConfig .String ("web_base_url" )+ "/login/index" , 302 )
@@ -62,7 +65,7 @@ func (s *BaseController) Prepare() {
62
65
s .Data ["allow_user_change_username" ], _ = beego .AppConfig .Bool ("allow_user_change_username" )
63
66
}
64
67
65
- //加载模板
68
+ // 加载模板
66
69
func (s * BaseController ) display (tpl ... string ) {
67
70
s .Data ["web_base_url" ] = beego .AppConfig .String ("web_base_url" )
68
71
var tplname string
@@ -86,19 +89,19 @@ func (s *BaseController) display(tpl ...string) {
86
89
s .TplName = tplname
87
90
}
88
91
89
- //错误
92
+ // 错误
90
93
func (s * BaseController ) error () {
91
94
s .Data ["web_base_url" ] = beego .AppConfig .String ("web_base_url" )
92
95
s .Layout = "public/layout.html"
93
96
s .TplName = "public/error.html"
94
97
}
95
98
96
- //getEscapeString
99
+ // getEscapeString
97
100
func (s * BaseController ) getEscapeString (key string ) string {
98
101
return html .EscapeString (s .GetString (key ))
99
102
}
100
103
101
- //去掉没有err返回值的int
104
+ // 去掉没有err返回值的int
102
105
func (s * BaseController ) GetIntNoErr (key string , def ... int ) int {
103
106
strv := s .Ctx .Input .Query (key )
104
107
if len (strv ) == 0 && len (def ) > 0 {
@@ -108,7 +111,7 @@ func (s *BaseController) GetIntNoErr(key string, def ...int) int {
108
111
return val
109
112
}
110
113
111
- //获取去掉错误的bool值
114
+ // 获取去掉错误的bool值
112
115
func (s * BaseController ) GetBoolNoErr (key string , def ... bool ) bool {
113
116
strv := s .Ctx .Input .Query (key )
114
117
if len (strv ) == 0 && len (def ) > 0 {
@@ -118,29 +121,29 @@ func (s *BaseController) GetBoolNoErr(key string, def ...bool) bool {
118
121
return val
119
122
}
120
123
121
- //ajax正确返回
124
+ // ajax正确返回
122
125
func (s * BaseController ) AjaxOk (str string ) {
123
126
s .Data ["json" ] = ajax (str , 1 )
124
127
s .ServeJSON ()
125
128
s .StopRun ()
126
129
}
127
130
128
- //ajax错误返回
131
+ // ajax错误返回
129
132
func (s * BaseController ) AjaxErr (str string ) {
130
133
s .Data ["json" ] = ajax (str , 0 )
131
134
s .ServeJSON ()
132
135
s .StopRun ()
133
136
}
134
137
135
- //组装ajax
138
+ // 组装ajax
136
139
func ajax (str string , status int ) map [string ]interface {} {
137
140
json := make (map [string ]interface {})
138
141
json ["status" ] = status
139
142
json ["msg" ] = str
140
143
return json
141
144
}
142
145
143
- //ajax table返回
146
+ // ajax table返回
144
147
func (s * BaseController ) AjaxTable (list interface {}, cnt int , recordsTotal int , kwargs map [string ]interface {}) {
145
148
json := make (map [string ]interface {})
146
149
json ["rows" ] = list
@@ -157,7 +160,7 @@ func (s *BaseController) AjaxTable(list interface{}, cnt int, recordsTotal int,
157
160
s .StopRun ()
158
161
}
159
162
160
- //ajax table参数
163
+ // ajax table参数
161
164
func (s * BaseController ) GetAjaxParams () (start , limit int ) {
162
165
return s .GetIntNoErr ("offset" ), s .GetIntNoErr ("limit" )
163
166
}
0 commit comments