- user2
This commit is contained in:
@@ -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:用户名,email,mobile"
|
||||
// @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:用户名,email,mobile"
|
||||
// @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
|
||||
|
||||
41
controllers/cms_user2.go
Normal file
41
controllers/cms_user2.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/mobile"
|
||||
_ "git.rosy.net.cn/jx-callback/business/auth2/authprovider/password"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type User2Controller struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title 用户注册
|
||||
// @Description 用户注册
|
||||
// @Param payload formData string true "json数据,User对象(手机号必填)"
|
||||
// @Param mobileVerifyCode formData string true "手机验证码(通过auth2.SendVerifyCode获得)"
|
||||
// @Param authToken formData string false "之前通过login得到的认证TOKEN(可以为空)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /RegisterUser [post]
|
||||
func (c *User2Controller) RegisterUser() {
|
||||
c.callRegisterUser(func(params *tUser2RegisterUserParams) (retVal interface{}, errCode string, err error) {
|
||||
var (
|
||||
user model.User
|
||||
inAuthInfo *auth2.AuthInfo
|
||||
)
|
||||
if params.AuthToken != "" {
|
||||
inAuthInfo, err = auth2.GetTokenInfo(params.AuthToken)
|
||||
}
|
||||
if err == nil {
|
||||
if err = jxutils.Strings2Objs(params.Payload, &user); err == nil {
|
||||
retVal, err = cms.RegisterUser(&user, params.MobileVerifyCode, inAuthInfo)
|
||||
}
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user