func (c *WechatController) Bind() {
	mailStr := c.Ctx.Input.Params[":mail"]
	passwdStr := c.Ctx.Input.Params[":passwd"]
	wechatStr := c.Ctx.Input.Params[":wechat"]
	user, err := models.GetZyUserAccountByMail(mailStr)
	if err != nil {
		c.Data["json"] = err.Error()
	} else {

		tmpPasswd := user.HashedPasswd
		tmpPasswdSalt := user.PasswdSalt

		var data string = passwdStr + "{" + tmpPasswdSalt + "}"
		// SHA1 hash
		hash := sha1.New()
		hash.Write([]byte(data))
		hashBytes := hash.Sum(nil)
		hexString := hex.EncodeToString(hashBytes)
		if tmpPasswd == hexString { //密码正确
			v := &models.ZyWechat{
				UserId: user.Id,
				Wechat: wechatStr,
			}
			models.AddZyWechat(v)
		}
	}

}
Example #2
0
// @Title Post
// @Description create ZyWechat
// @Param	body		body 	models.ZyWechat	true		"body for ZyWechat content"
// @Success 200 {int} models.ZyWechat.Id
// @Failure 403 body is empty
// @router / [post]
func (c *ZyWechatController) Post() {
	var v models.ZyWechat
	json.Unmarshal(c.Ctx.Input.RequestBody, &v)
	if id, err := models.AddZyWechat(&v); err == nil {
		c.Data["json"] = map[string]int64{"id": id}
	} else {
		c.Data["json"] = err.Error()
	}
	c.ServeJson()
}