sso

verification_code_controller.go 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 beego.AppConfig.String("runmode") == "dev" {
  47. // if strings.HasPrefix(mobile, "12") {
  48. // this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  49. // "msg": "短信发送成功,有效期为10分钟",
  50. // })
  51. // this.ServeJSON()
  52. // return
  53. // }
  54. // }
  55. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  56. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  57. this.ServeJSON()
  58. } else {
  59. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  60. "msg": "短信发送成功,有效期为10分钟",
  61. })
  62. this.ServeJSON()
  63. }
  64. }