/**
 * 程序
 */
package controllers

import (
    "github.com/astaxie/beego"
    "github.com/astaxie/beego/cache"
    "github.com/astaxie/beego/utils/captcha"
)

type LoginController struct {
    beego.Controller
}

var cpt *captcha.Captcha

func init() {
    // use beego cache system store the captcha data
    store := cache.NewMemoryCache()
    cpt = captcha.NewWithFilter("/captcha/", store)
}

func (this *LoginController) Index() {

    if this.Ctx.Input.Method() == "POST" {
     // 验证输入
        this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
        this.TplNames = "login.html"
    } else {
        this.TplNames = "login.html"
    }

}

/**
 * 视图 login.html
 */
{{.Success}}
   <form method="post" action="/">
    <input type="text" name="captcha" />
        {{create_captcha}}<br />
    <input type="submit" value="提交" />
  </form>

附带第三方包:
go get github.com/astaxie/beego/cache
go get github.com/astaxie/beego/utils/captcha 

 童飞

转载于:https://www.cnblogs.com/yunkeji/p/4070854.html

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐