User.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package controllers
  2. import (
  3. "Yunlot/lib"
  4. "Yunlot/logs"
  5. "Yunlot/models/Account"
  6. beego "github.com/beego/beego/v2/server/web"
  7. )
  8. type UserController struct {
  9. beego.Controller
  10. }
  11. //验证码
  12. func (c *UserController) SandVerify() {
  13. bzd_phone := c.GetString("phone")
  14. _, is := Account.Redis_Verify_Get(bzd_phone)
  15. if is {
  16. c.Data["json"] = lib.JSONR{Code: 201, Msg: "不能重复发送!"}
  17. c.ServeJSON()
  18. return
  19. }
  20. Code := lib.Message_Sand_Verify(bzd_phone)
  21. logs.Println(bzd_phone, Code)
  22. //Code := "123"
  23. Account.Redis_Verify_Set(bzd_phone, Code)
  24. c.Data["json"] = lib.JSONR{Code: 200, Msg: "ok!"}
  25. c.ServeJSON()
  26. return
  27. }
  28. // 验证登录
  29. func (c *UserController) Register() {
  30. bzd_phone := c.GetString("phone")
  31. bzd_Code := c.GetString("code")
  32. r, is := Account.Redis_Verify_Get(bzd_phone)
  33. if !is {
  34. c.Data["json"] = lib.JSONR{Code: 201, Msg: "验证码错误!"}
  35. c.ServeJSON()
  36. return
  37. }
  38. println(r)
  39. if r != bzd_Code {
  40. c.Data["json"] = lib.JSONR{Code: 202, Msg: "验证码错误!"}
  41. c.ServeJSON()
  42. return
  43. }
  44. User_r := Account.User{T_user: bzd_phone}
  45. if !User_r.Read() {
  46. User_r.T_uuid = lib.GetRandstring(8, "", 0)
  47. User_r.T_State = 1
  48. User_r.Add()
  49. }
  50. Account.Redis_Verify_DelK(bzd_phone) // 删除验证码
  51. User_r.T_tokey = Account.Add_Tokey(User_r.T_uuid)
  52. c.Data["json"] = lib.JSONR{Code: 200, Msg: "ok!", Data: User_r}
  53. c.ServeJSON()
  54. return
  55. }