auth.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package controller
  2. import (
  3. "net/http"
  4. "video_course/service"
  5. "github.com/sirupsen/logrus"
  6. "github.com/mojocn/base64Captcha"
  7. )
  8. type Auth struct {
  9. BaseController
  10. }
  11. // SignUp godoc
  12. // @Summary 用户添加
  13. // @tags Auth
  14. // @Description 用户添加
  15. // @Accept x-www-form-urlencoded
  16. // @Produce json
  17. // @Param userCode formData string true "用户名"
  18. // @Param password formData string true "密码"
  19. // @Param email formData string false "邮箱"
  20. // @Param phone formData string false "手机号"
  21. // @Param name formData string false "姓名"
  22. // @Success 200 {object} controller.ResponseBase
  23. // @Router /Auth/SignUp [post]
  24. func (a *Auth) HttpPostSignUp() (err error) {
  25. userCode := a.Ctx().PostForm("userCode")
  26. test := a.PostFromInt("test")
  27. test2 := a.PostFromIntPtr("test2")
  28. logrus.Info(userCode, test, test2)
  29. a.Ctx().JSON(http.StatusOK, newResponseBase())
  30. return
  31. }
  32. type ResponseVerifyPic struct {
  33. Id string
  34. Pic string
  35. }
  36. // GenVerifyPic godoc
  37. // @Summary 获取验证图片
  38. // @tags Auth
  39. // @Description 获取验证图片和验证id
  40. // @Accept x-www-form-urlencoded
  41. // @Param height formData string true "高"
  42. // @Param width formData string true "宽"
  43. // @Param noiseCount formData string true "噪点数量"
  44. // @Param length formData string true "验证码字数"
  45. // @Param source formData string true "验证码取值范围 比如 1234567890 或者 abcdef等"
  46. // @Produce json
  47. // @Success 200 {object} controller.ResponseVerifyPic
  48. // @Router /Auth/GenVerifyPic [post]
  49. func (a *Auth) GenVerifyPic() (err error) {
  50. config := &base64Captcha.DriverString{}
  51. config.Height = a.postIntNecessary("height")
  52. config.Width = a.postIntNecessary("width")
  53. config.NoiseCount = a.postIntNecessary("noiseCount")
  54. config.Length = a.postIntNecessary("length")
  55. config.Source = a.Ctx().PostForm("source")
  56. if config.Source == "" {
  57. config.Source = "1234567890"
  58. }
  59. id, pic := service.Auth{}.GenVerifyPic(config)
  60. r := ResponseVerifyPic{
  61. id,
  62. pic,
  63. }
  64. a.Ctx().JSON(http.StatusOK, r)
  65. return
  66. }
  67. // GetPhoneVFCode godoc
  68. // @Summary 手机获取验证码
  69. // @tags Auth
  70. // @Description 手机获取验证码
  71. // @Accept x-www-form-urlencoded
  72. // @Produce json
  73. // @Param phone formData string true "手机号"
  74. // @Param codeType formData int true "验证码类型 1:登录"
  75. // @Param picId formData string true "图形验证码id"
  76. // @Param picCode formData string true "图形验证码"
  77. // @Success 200 {object} controller.ResponseBase
  78. // @Router /Auth/GetPhoneVFCode [post]
  79. func (a *Auth) GetPhoneVFCode() (err error) {
  80. phone := a.postString("phone", true)
  81. codeType := a.postIntNecessary("codeType")
  82. picId := a.Ctx().PostForm("picId")
  83. picCode := a.Ctx().PostForm("picCode")
  84. service.Auth{}.GenVFCode(codeType, phone, a.getIp(), picId, picCode)
  85. a.json(newResponseBase())
  86. return
  87. }