1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 13:30:56 +00:00

验证码reload问题

当页面放置一段时间,验证码将从缓存中失效。当用户再来刷新验证码将出现验证码404。对于reload操作应该直接生成验证码。
This commit is contained in:
supiyun 2015-03-16 17:40:55 +08:00 committed by astaxie
parent bf6b0d3e1f
commit 1592e9c04d

View File

@ -132,15 +132,6 @@ func (c *Captcha) Handler(ctx *context.Context) {
key := c.key(id) key := c.key(id)
if v, ok := c.store.Get(key).([]byte); ok {
chars = v
} else {
ctx.Output.SetStatus(404)
ctx.WriteString("captcha not found")
return
}
// reload captcha
if len(ctx.Input.Query("reload")) > 0 { if len(ctx.Input.Query("reload")) > 0 {
chars = c.genRandChars() chars = c.genRandChars()
if err := c.store.Put(key, chars, c.Expiration); err != nil { if err := c.store.Put(key, chars, c.Expiration); err != nil {
@ -149,6 +140,14 @@ func (c *Captcha) Handler(ctx *context.Context) {
beego.Error("Reload Create Captcha Error:", err) beego.Error("Reload Create Captcha Error:", err)
return return
} }
} else {
if v, ok := c.store.Get(key).([]byte); ok {
chars = v
} else {
ctx.Output.SetStatus(404)
ctx.WriteString("captcha not found")
return
}
} }
img := NewImage(chars, c.StdWidth, c.StdHeight) img := NewImage(chars, c.StdWidth, c.StdHeight)