package controllers import ( "Yunlot/lib" "Yunlot/logs" "Yunlot/models/Account" beego "github.com/beego/beego/v2/server/web" ) type UserController struct { beego.Controller } //验证码 func (c *UserController) SandVerify() { bzd_phone := c.GetString("phone") _, is := Account.Redis_Verify_Get(bzd_phone) if is { c.Data["json"] = lib.JSONR{Code: 201, Msg: "不能重复发送!"} c.ServeJSON() return } Code := lib.Message_Sand_Verify(bzd_phone) logs.Println(bzd_phone, Code) //Code := "123" Account.Redis_Verify_Set(bzd_phone, Code) c.Data["json"] = lib.JSONR{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 验证登录 func (c *UserController) Register() { bzd_phone := c.GetString("phone") bzd_Code := c.GetString("code") r, is := Account.Redis_Verify_Get(bzd_phone) if !is { c.Data["json"] = lib.JSONR{Code: 201, Msg: "验证码错误!"} c.ServeJSON() return } println(r) if r != bzd_Code { c.Data["json"] = lib.JSONR{Code: 202, Msg: "验证码错误!"} c.ServeJSON() return } User_r := Account.User{T_user: bzd_phone} if !User_r.Read() { User_r.T_uuid = lib.GetRandstring(8, "", 0) User_r.T_State = 1 User_r.Add() } Account.Redis_Verify_DelK(bzd_phone) // 删除验证码 User_r.T_tokey = Account.Add_Tokey(User_r.T_uuid) c.Data["json"] = lib.JSONR{Code: 200, Msg: "ok!", Data: User_r} c.ServeJSON() return }