sso

verification_code_controller.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package controllers
  2. import (
  3. "SSO/enums"
  4. "SSO/service"
  5. "SSO/utils"
  6. )
  7. type CodeController struct {
  8. BaseController
  9. }
  10. func (this *CodeController) Prepare() {
  11. this.EnableXSRF = false
  12. }
  13. func (this *CodeController) Post() {
  14. mobile := this.GetString("phone")
  15. aespass := this.GetString("aespass")
  16. utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  17. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  18. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  19. this.ServeJSON()
  20. return
  21. }
  22. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  23. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  24. this.ServeJSON()
  25. } else {
  26. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  27. "msg": "短信发送成功,有效期为10分钟",
  28. })
  29. this.ServeJSON()
  30. }
  31. }
  32. func (this *CodeController) RegistCode() {
  33. mobile := this.GetString("phone")
  34. aespass := this.GetString("aespass")
  35. utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  36. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  37. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  38. this.ServeJSON()
  39. return
  40. }
  41. if service.IsMobileRegister(mobile) == true {
  42. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileRegistered)
  43. this.ServeJSON()
  44. return
  45. }
  46. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  47. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  48. this.ServeJSON()
  49. } else {
  50. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  51. "msg": "短信发送成功,有效期为10分钟",
  52. })
  53. this.ServeJSON()
  54. }
  55. }