5be22a99 by slene Committed by asta.xie

fix captcha urlPrefix

1 parent 5d02b18d
...@@ -67,7 +67,7 @@ const ( ...@@ -67,7 +67,7 @@ const (
67 fieldIdName = "captcha_id" 67 fieldIdName = "captcha_id"
68 fieldCaptchaName = "captcha" 68 fieldCaptchaName = "captcha"
69 cachePrefix = "captcha_" 69 cachePrefix = "captcha_"
70 urlPrefix = "/captcha/" 70 defaultURLPrefix = "/captcha/"
71 ) 71 )
72 72
73 // Captcha struct 73 // Captcha struct
...@@ -76,7 +76,7 @@ type Captcha struct { ...@@ -76,7 +76,7 @@ type Captcha struct {
76 store cache.Cache 76 store cache.Cache
77 77
78 // url prefix for captcha image 78 // url prefix for captcha image
79 urlPrefix string 79 URLPrefix string
80 80
81 // specify captcha id input field name 81 // specify captcha id input field name
82 FieldIdName string 82 FieldIdName string
...@@ -155,7 +155,7 @@ func (c *Captcha) CreateCaptchaHtml() template.HTML { ...@@ -155,7 +155,7 @@ func (c *Captcha) CreateCaptchaHtml() template.HTML {
155 return template.HTML(fmt.Sprintf(`<input type="hidden" name="%s" value="%s">`+ 155 return template.HTML(fmt.Sprintf(`<input type="hidden" name="%s" value="%s">`+
156 `<a class="captcha" href="javascript:">`+ 156 `<a class="captcha" href="javascript:">`+
157 `<img onclick="this.src=('%s%s.png?reload='+(new Date()).getTime())" class="captcha-img" src="%s%s.png">`+ 157 `<img onclick="this.src=('%s%s.png?reload='+(new Date()).getTime())" class="captcha-img" src="%s%s.png">`+
158 `</a>`, c.FieldIdName, value, c.urlPrefix, value, c.urlPrefix, value)) 158 `</a>`, c.FieldIdName, value, c.URLPrefix, value, c.URLPrefix, value))
159 } 159 }
160 160
161 // create a new captcha id 161 // create a new captcha id
...@@ -224,14 +224,14 @@ func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha { ...@@ -224,14 +224,14 @@ func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha {
224 cpt.StdHeight = stdHeight 224 cpt.StdHeight = stdHeight
225 225
226 if len(urlPrefix) == 0 { 226 if len(urlPrefix) == 0 {
227 urlPrefix = urlPrefix 227 urlPrefix = defaultURLPrefix
228 } 228 }
229 229
230 if urlPrefix[len(urlPrefix)-1] != '/' { 230 if urlPrefix[len(urlPrefix)-1] != '/' {
231 urlPrefix += "/" 231 urlPrefix += "/"
232 } 232 }
233 233
234 cpt.urlPrefix = urlPrefix 234 cpt.URLPrefix = urlPrefix
235 235
236 return cpt 236 return cpt
237 } 237 }
...@@ -242,7 +242,7 @@ func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha { ...@@ -242,7 +242,7 @@ func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
242 cpt := NewCaptcha(urlPrefix, store) 242 cpt := NewCaptcha(urlPrefix, store)
243 243
244 // create filter for serve captcha image 244 // create filter for serve captcha image
245 beego.AddFilter(urlPrefix+":", "BeforeRouter", cpt.Handler) 245 beego.AddFilter(cpt.URLPrefix+":", "BeforeRouter", cpt.Handler)
246 246
247 // add to template func map 247 // add to template func map
248 beego.AddFuncMap("create_captcha", cpt.CreateCaptchaHtml) 248 beego.AddFuncMap("create_captcha", cpt.CreateCaptchaHtml)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!