Files
leanote/app/controllers/CaptchaController.go

47 lines
861 B
Go
Raw Normal View History

2014-10-22 16:20:45 +08:00
package controllers
import (
"github.com/revel/revel"
2015-11-13 17:58:41 +08:00
// "encoding/json"
// "gopkg.in/mgo.v2/bson"
2014-10-22 16:20:45 +08:00
. "github.com/leanote/leanote/app/lea"
"github.com/leanote/leanote/app/lea/captcha"
2015-11-13 17:58:41 +08:00
// "github.com/leanote/leanote/app/types"
// "io/ioutil"
// "fmt"
// "math"
// "os"
// "path"
// "strconv"
2014-10-22 16:20:45 +08:00
"net/http"
2017-11-30 18:10:59 +08:00
"io"
2014-10-22 16:20:45 +08:00
)
// 验证码服务
type Captcha struct {
BaseController
}
type Ca string
2015-11-13 17:58:41 +08:00
2014-10-22 16:20:45 +08:00
func (r Ca) Apply(req *revel.Request, resp *revel.Response) {
2015-11-13 17:58:41 +08:00
resp.WriteHeader(http.StatusOK, "image/png")
2014-10-22 16:20:45 +08:00
}
func (c Captcha) Get() revel.Result {
c.Response.ContentType = "image/png"
image, str := captcha.Fetch()
2017-11-30 18:10:59 +08:00
out := io.Writer(c.Response.GetWriter())
image.WriteTo(out)
2015-11-13 17:58:41 +08:00
2021-03-26 14:19:53 +08:00
sessionId := c.GetSession("_ID")
2015-11-13 17:58:41 +08:00
// LogJ(c.Session)
// Log("------")
// Log(str)
// Log(sessionId)
Log("..")
2014-10-22 16:20:45 +08:00
sessionService.SetCaptcha(sessionId, str)
2015-11-13 17:58:41 +08:00
2014-10-22 16:20:45 +08:00
return c.Render()
2015-11-13 17:58:41 +08:00
}