package controller import ( "net/http" "video_course/service" "github.com/mojocn/base64Captcha" ) type Auth struct { BaseController } //// SignUp godoc //// @Summary 用户添加 //// @tags Auth //// @Description 用户添加 //// @Accept x-www-form-urlencoded //// @Produce json //// @Param userCode formData string true "用户名" //// @Param password formData string true "密码" //// @Param email formData string false "邮箱" //// @Param phone formData string false "手机号" //// @Param name formData string false "姓名" //// @Success 200 {object} controller.ResponseBase //// @Router /Auth/SignUp [post] //func (a *Auth) HttpPostSignUp() (err error) { // userCode := a.Ctx().PostForm("userCode") // test := a.PostFromInt("test") // test2 := a.PostFromIntPtr("test2") // logrus.Info(userCode, test, test2) // // a.Ctx().JSON(http.StatusOK, newResponseBase()) // return //} type ResponseVerifyPic struct { Id string Pic string } // GenVerifyPic godoc // @Summary 获取验证图片 // @tags Auth // @Description 获取验证图片和验证id // @Accept x-www-form-urlencoded // @Param height formData string true "高" // @Param width formData string true "宽" // @Param noiseCount formData string true "噪点数量" // @Param length formData string true "验证码字数" // @Param source formData string true "验证码取值范围 比如 1234567890 或者 abcdef等" // @Produce json // @Success 200 {object} controller.ResponseVerifyPic // @Router /Auth/GenVerifyPic [post] func (a *Auth) GenVerifyPic() (err error) { config := &base64Captcha.DriverString{} config.Height = a.postIntNecessary("height") config.Width = a.postIntNecessary("width") config.NoiseCount = a.postIntNecessary("noiseCount") config.Length = a.postIntNecessary("length") config.Source = a.Ctx().PostForm("source") if config.Source == "" { config.Source = "1234567890" } id, pic := service.Auth{}.GenVerifyPic(config) r := ResponseVerifyPic{ id, pic, } a.Ctx().JSON(http.StatusOK, r) return } // GetPhoneVFCode godoc // @Summary 手机获取验证码 // @tags Auth // @Description 手机获取验证码 // @Accept x-www-form-urlencoded // @Produce json // @Param picCode formData string true "图形验证码,目前不起作用" // @Param phone formData string true "手机号" // @Param codeType formData int true "验证码类型 1:登录" // @Success 200 {object} controller.ResponseBase // @Router /Auth/GetPhoneVFCode [post] func (a *Auth) GetPhoneVFCode() (err error) { picCode := a.Ctx().PostForm("picCode") phone := a.postString("phone", true) codeType := a.postIntNecessary("codeType") //picId := a.Ctx().PostForm("picId") //picCode := a.Ctx().PostForm("picCode") err = service.Auth{}.GenVFCode(codeType, phone, a.getIp(), picCode) if err != nil { return } a.Ctx().JSON(http.StatusOK, newResponseBase()) return } type StandardResponse struct { ResponseBase Rs map[string]string } // PhoneSignIn godoc // @Summary 手机验证码登录 // @tags Auth // @Description 手机验证码登录 // @Accept x-www-form-urlencoded // @Produce json // @Param phone formData string true "手机号" // @Param smsCode formData int true "验证码" // @Success 200 {object} controller.ResponseBase // @Router /Auth/PhoneSignIn [post] func (a *Auth) PhoneSignIn() (err error) { phone := a.postString("phone", true) smsCode := a.postString("smsCode", true) session, err := service.Auth{}.PhoneSignIn(phone, smsCode, a.getIp()) if err != nil { return } r := StandardResponse{ ResponseBase: newResponseBase(), Rs: map[string]string{ "token": session.Token, }, } a.Ctx().JSON(http.StatusOK, r) return }