yunkeji

 

/**
 * 程序
 */
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 

 童飞

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2021-12-04
  • 2021-11-11
  • 2021-08-23
  • 2021-08-11
  • 2022-12-23
  • 2021-09-24
猜你喜欢
  • 2021-11-15
  • 2022-01-08
  • 2021-10-24
  • 2021-09-26
  • 2022-12-23
相关资源
相似解决方案