From 1592e9c04dd73e26fb35cab9e9370f89b414c8c8 Mon Sep 17 00:00:00 2001 From: supiyun Date: Mon, 16 Mar 2015 17:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81reload=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当页面放置一段时间,验证码将从缓存中失效。当用户再来刷新验证码将出现验证码404。对于reload操作应该直接生成验证码。 --- utils/captcha/captcha.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/utils/captcha/captcha.go b/utils/captcha/captcha.go index 62adc81d..14c6c3b3 100644 --- a/utils/captcha/captcha.go +++ b/utils/captcha/captcha.go @@ -132,15 +132,6 @@ func (c *Captcha) Handler(ctx *context.Context) { 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 { chars = c.genRandChars() 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) 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)