package models

import (
	"math/rand"
	"strconv"
	"time"

	"github.com/astaxie/beego"
)

func FormValidation(c *beego.Controller) {
	PostFormSession, _ := strconv.Atoi(c.GetString("FormSession"))
	if c.GetSession("FormSession") != PostFormSession {
		c.Ctx.Output.ContentType("text/html;chart=utf8")
		c.Ctx.Output.Body([]byte("<script>alert('表单重复提交了,已被拦截,生效一个');location.href='../'</script>"))
		return
	}
}
func FormSessionStart(c *beego.Controller) {
	rand.Seed(time.Now().UnixNano())
	t := rand.Intn(999)
	c.SetSession("FormSession", t)
	c.Data["FormSession"] = t
}
