sso

verification_code_controller.go 2.0KB

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