1592e9c0 by supiyun Committed by astaxie

验证码reload问题

当页面放置一段时间,验证码将从缓存中失效。当用户再来刷新验证码将出现验证码404。对于reload操作应该直接生成验证码。
1 parent bf6b0d3e
...@@ -132,15 +132,6 @@ func (c *Captcha) Handler(ctx *context.Context) { ...@@ -132,15 +132,6 @@ func (c *Captcha) Handler(ctx *context.Context) {
132 132
133 key := c.key(id) 133 key := c.key(id)
134 134
135 if v, ok := c.store.Get(key).([]byte); ok {
136 chars = v
137 } else {
138 ctx.Output.SetStatus(404)
139 ctx.WriteString("captcha not found")
140 return
141 }
142
143 // reload captcha
144 if len(ctx.Input.Query("reload")) > 0 { 135 if len(ctx.Input.Query("reload")) > 0 {
145 chars = c.genRandChars() 136 chars = c.genRandChars()
146 if err := c.store.Put(key, chars, c.Expiration); err != nil { 137 if err := c.store.Put(key, chars, c.Expiration); err != nil {
...@@ -149,6 +140,14 @@ func (c *Captcha) Handler(ctx *context.Context) { ...@@ -149,6 +140,14 @@ func (c *Captcha) Handler(ctx *context.Context) {
149 beego.Error("Reload Create Captcha Error:", err) 140 beego.Error("Reload Create Captcha Error:", err)
150 return 141 return
151 } 142 }
143 } else {
144 if v, ok := c.store.Get(key).([]byte); ok {
145 chars = v
146 } else {
147 ctx.Output.SetStatus(404)
148 ctx.WriteString("captcha not found")
149 return
150 }
152 } 151 }
153 152
154 img := NewImage(chars, c.StdWidth, c.StdHeight) 153 img := NewImage(chars, c.StdWidth, c.StdHeight)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!