func (this *TSController) PHP() { this.Info = &map[string]string{ "fail": "验证不通过", "user": "******", "ok": "成功啦!", } token := this.GetString("t") if len(token) == 0 { this.ERR("fail") return } path := PHPBHPATH if len(token) > 0 { _, err := models.NewTokenOption().Get(token) if err == nil { path = PHPPATH } } phptag := "" if this.GetString("include") == "1" { phptag = "<?php" } replaces := map[string]string{ "token": token, "domain": this.domain(), "phptag": phptag, } cc, _ := ioutil.ReadFile(path) for kk, vv := range replaces { re := regexp.MustCompile(fmt.Sprintf(`{%s}`, kk)) reByte := []byte(fmt.Sprintf("%s", vv)) cc = re.ReplaceAll(cc, reByte) } this.Ctx.Output.Body(cc) }
func (this *TSController) JS() { this.Info = &map[string]string{ "fail": "账号或密码不对", "user": "******", "ok": "成功啦!", } token := this.GetString("t") if len(token) == 0 { this.ERR("fail") return } _, err := models.NewTokenOption().Get(token) if err != nil { this.ERR("fail") return } kl, _ := this.GetInt("kl") tskl := "0" if kl > 0 { tskl = "1" } replaces := map[string]string{ "token": token, "domain": this.domain(), "tskl": tskl, } cc, _ := ioutil.ReadFile(JSPATH) for kk, vv := range replaces { re := regexp.MustCompile(fmt.Sprintf(`{%s}`, kk)) reByte := []byte(fmt.Sprintf("%s", vv)) cc = re.ReplaceAll(cc, reByte) } this.Ctx.Output.Body(cc) }
func (this *TSController) Post() { token := this.GetString("token") time := this.GetString("time") data := this.GetString("data") te := this.GetString("type") fmt.Println(data) ip := this.Ctx.Input.IP() go func(token, time, data, te, ip string) { t, err := models.NewTokenOption().Get(token) if err != nil { return } tstime, _ := strconv.ParseInt(time, 10, 64) ts := models.NewTS(data, te, ip, tstime, 0) models.NewTSOption().Insert(t.User.Name, ts) }(token, time, data, te, ip) this.Ctx.Output.Header("Access-Control-Allow-Origin", "*") this.Ctx.WriteString("") }
func (this *LoginController) DoLogin() { this.Info = &map[string]string{ "success": "登录成功", "login": "******", } name := this.GetString("name") password := this.GetString("pass") user, err := models.NewUserOption().Get(name) if err != nil || user.CheckPass(password) { this.ERR("login") return } token := models.NewToken(user, "") models.NewTokenOption().Add(token) this.SetSession("sessionVal", map[string]string{ "name": user.Name, "token": token.Token(), }) this.OK("success") }
func (this *LoginController) LoginOut() { this.DelSession("sessionVal") models.NewTokenOption().Remove(this.Token) this.CustomRedirect() }