This commit is contained in:
gazebo
2019-03-03 22:20:07 +08:00
parent af38ab535b
commit 6793e7443d
16 changed files with 330 additions and 59 deletions

View File

@@ -23,25 +23,42 @@ type Auth2Controller struct {
beego.Controller
}
// @Title 生成captcha
// @Description 生成captcha
// @Param width formData int true "图片宽"
// @Param height formData int true "图片高"
// @Param captchaLen formData int false "验证码长度"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /CreateCaptcha [post]
func (c *Auth2Controller) CreateCaptcha() {
c.callCreateCaptcha(func(params *tAuth2CreateCaptchaParams) (retVal interface{}, errCode string, err error) {
retVal, err = auth2.CreateCaptcha(params.Width, params.Height, params.CaptchaLen)
return retVal, "", err
})
}
// @Title 发送验证码
// @Description 发送验证码
// @Param captchaID formData string true "图片验证码ID"
// @Param captchaValue formData string true "图片验证码值"
// @Param authID formData string true "手机号或邮件"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SendVerifyCode [post]
func (c *Auth2Controller) SendVerifyCode() {
c.callSendVerifyCode(func(params *tAuth2SendVerifyCodeParams) (retVal interface{}, errCode string, err error) {
err = auth2.SendVerifyCode(params.AuthID)
err = auth2.SendVerifyCode(params.CaptchaID, params.CaptchaValue, params.AuthID)
return retVal, "", err
})
}
// @Title 登录接口
// @Description 登录接口(微信与公众号登录不能直接调用此接口)
// @Param authType formData string true "登录类型,当前支持[password本地账号密码mobile手机短信weixin:微信登录weixinmp微信公众号登录weixinmini小程序登录]"
// @Param authSecret formData string true "不同登录类型的登录秘密"
// @Param authID formData string false "登录ID登录类型为password时依赖于authIDType其它为相应登录类型的id"
// @Param authIDType formData string false "只有在登录类型为password才有意义分别为userID2用户名emailmobile"
// @Param authType formData string true "登录类型,当前支持[localpass本地账号密码mobile手机短信weixin:微信登录weixinsns微信公众号登录weixinmini小程序登录]"
// @Param authSecret formData string true "不同登录类型的登录秘密如果是localpass登录类型是md5后的值空串不要md5"
// @Param authID formData string false "登录ID登录类型为localpass时依赖于authIDType其它为相应登录类型的id"
// @Param authIDType formData string false "只有在登录类型为localpass时才有意义分别为userID2用户名emailmobile"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /Login [post]
@@ -140,7 +157,7 @@ func (c *Auth2Controller) AddAuthBind() {
c.callAddAuthBind(func(params *tAuth2AddAuthBindParams) (retVal interface{}, errCode string, err error) {
authInfo, err2 := c.getAuth2Info(params.Ctx)
if err := err2; err == nil {
newAuthInfo, err2 := auth2.GetUserInfo(params.AuthToken)
newAuthInfo, err2 := auth2.GetTokenInfo(params.AuthToken)
if err = err2; err == nil {
err = auth2.AddAuthBind(authInfo, newAuthInfo)
}
@@ -152,7 +169,7 @@ func (c *Auth2Controller) AddAuthBind() {
// @Title 删除认证方式
// @Description 删除认证方式
// @Param token header string true "认证token"
// @Param authType formData string true "登录类型,当前支持[weixin:微信登录weixinmp微信公众号登录weixinmini小程序登录]"
// @Param authType formData string true "登录类型,当前支持[weixin:微信登录weixinsns微信公众号登录weixinmini小程序登录]"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RemoveAuthBind [post]
@@ -166,6 +183,20 @@ func (c *Auth2Controller) RemoveAuthBind() {
})
}
// @Title 修改(或初始化)密码
// @Description 修改(或初始化)密码
// @Param token header string true "认证token"
// @Param oldPwd query string false "原密码md5如果是重置或新设为空"
// @Param newPwd query string true "新密码md5"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ChangePassword [put]
func (c *Auth2Controller) ChangePassword() {
c.callChangePassword(func(params *tAuth2ChangePasswordParams) (retVal interface{}, errCode string, err error) {
return retVal, "", err
})
}
func (c *Auth2Controller) getAuth2Info(ctx *jxcontext.Context) (authInfo *auth2.AuthInfo, err error) {
if authInfo, ok := ctx.GetLoginInfo().(*auth2.AuthInfo); ok {
return authInfo, err