Merge remote-tracking branch 'origin/mark' into yonghui
This commit is contained in:
@@ -76,7 +76,7 @@ type CaptchaInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IAuther interface {
|
type IAuther interface {
|
||||||
SendVerifyCode(authID string) (err error)
|
SendVerifyCode(authID string) (verifyCode string, err error)
|
||||||
// 负责验证secret,并找到相应的用户返回(password,email,mobile类型的不负责用户查找)如果找不到用户UserID为空
|
// 负责验证secret,并找到相应的用户返回(password,email,mobile类型的不负责用户查找)如果找不到用户UserID为空
|
||||||
VerifySecret(authID, authSecret string) (authBindEx *AuthBindEx, err error)
|
VerifySecret(authID, authSecret string) (authBindEx *AuthBindEx, err error)
|
||||||
AddAuthBind(authBindEx *AuthBindEx, userName string) (err error)
|
AddAuthBind(authBindEx *AuthBindEx, userName string) (err error)
|
||||||
@@ -195,9 +195,9 @@ func CreateCaptcha(width, height, captchaLen int) (captchaInfo *CaptchaInfo, err
|
|||||||
return captchaInfo, err
|
return captchaInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendVerifyCode(authToken, captchaID, captchaValue, authID string) (err error) {
|
func SendVerifyCode(authToken, captchaID, captchaValue, authID string) (verfifyCode string, authInfo *AuthInfo, err error) {
|
||||||
if authToken != "" {
|
if authToken != "" {
|
||||||
_, err = GetTokenInfo(authToken)
|
authInfo, err = GetTokenInfo(authToken)
|
||||||
} else if captchaID != "" && captchaValue != "" {
|
} else if captchaID != "" && captchaValue != "" {
|
||||||
if !(TestCaptchaMap[captchaID] == captchaValue || captcha.VerifyString(captchaID, captchaValue)) {
|
if !(TestCaptchaMap[captchaID] == captchaValue || captcha.VerifyString(captchaID, captchaValue)) {
|
||||||
err = ErrCaptchaIsNotOk
|
err = ErrCaptchaIsNotOk
|
||||||
@@ -210,10 +210,10 @@ func SendVerifyCode(authToken, captchaID, captchaValue, authID string) (err erro
|
|||||||
if handler := authers[authType]; handler == nil {
|
if handler := authers[authType]; handler == nil {
|
||||||
err = ErrIllegalAuthType
|
err = ErrIllegalAuthType
|
||||||
} else {
|
} else {
|
||||||
err = handler.SendVerifyCode(authID)
|
verfifyCode, err = handler.SendVerifyCode(authID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return verfifyCode, authInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 账号密码时:authIDType可能是:UserIDID,UserIDID2,UserIDMobile,UserIDEmail,authSecret是密码的sha1
|
// 账号密码时:authIDType可能是:UserIDID,UserIDID2,UserIDMobile,UserIDEmail,authSecret是密码的sha1
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UserBasic struct {
|
type UserBasic struct {
|
||||||
UserID string `json:"userID"`
|
UserID string `json:"userID"`
|
||||||
UserID2 string `json:"userID2"`
|
UserID2 string `json:"userID2"`
|
||||||
Mobile string `json:"mobile"`
|
Mobile string `json:"mobile"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserBasic) GetID() string {
|
func (u *UserBasic) GetID() string {
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ func (a *DefAuther) UnbindAuth(userID, authType, userName string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *DefAuther) SendVerifyCode(authID string) error {
|
func (a *DefAuther) SendVerifyCode(authID string) (verifyCode string, err error) {
|
||||||
return errors.New("当前登录类型不支持此操作")
|
return "", errors.New("当前登录类型不支持此操作")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 此函数为空
|
// 此函数为空
|
||||||
|
|||||||
@@ -43,15 +43,15 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 特殊接口
|
// 特殊接口
|
||||||
func (a *Auther) SendVerifyCode(mobileNumber string) error {
|
func (a *Auther) SendVerifyCode(mobileNumber string) (verifyCode string, err error) {
|
||||||
code := a.GenerateVerifyCode(mobileNumber)
|
verifyCode = a.GenerateVerifyCode(mobileNumber)
|
||||||
smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||||
response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_175583158", string(utils.MustMarshal(map[string]interface{}{
|
response, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_175583158", string(utils.MustMarshal(map[string]interface{}{
|
||||||
"code": code,
|
"code": verifyCode,
|
||||||
})))
|
})))
|
||||||
a.SaveVerifyCode(mobileNumber, code)
|
a.SaveVerifyCode(mobileNumber, verifyCode)
|
||||||
if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
if err == nil && response.Code == aliyunsmsclient.ResponseCodeOk {
|
||||||
// a.SaveVerifyCode(mobileNumber, code)
|
// a.SaveVerifyCode(mobileNumber, verifyCode)
|
||||||
} else {
|
} else {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if warningMap[response.Code] == 1 {
|
if warningMap[response.Code] == 1 {
|
||||||
@@ -64,7 +64,7 @@ func (a *Auther) SendVerifyCode(mobileNumber string) error {
|
|||||||
globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
globals.SugarLogger.Warnf("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return verifyCode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Auther) VerifySecret(mobileNumber, code string) (authBindEx *auth2.AuthBindEx, err error) {
|
func (a *Auther) VerifySecret(mobileNumber, code string) (authBindEx *auth2.AuthBindEx, err error) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/password"
|
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/password"
|
||||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
@@ -66,7 +67,13 @@ func (c *Auth2Controller) CreateCaptcha() {
|
|||||||
// @router /SendVerifyCode [post]
|
// @router /SendVerifyCode [post]
|
||||||
func (c *Auth2Controller) SendVerifyCode() {
|
func (c *Auth2Controller) SendVerifyCode() {
|
||||||
c.callSendVerifyCode(func(params *tAuth2SendVerifyCodeParams) (retVal interface{}, errCode string, err error) {
|
c.callSendVerifyCode(func(params *tAuth2SendVerifyCodeParams) (retVal interface{}, errCode string, err error) {
|
||||||
err = auth2.SendVerifyCode(params.AuthToken, params.CaptchaID, params.CaptchaValue, params.AuthID)
|
code, authInfo, err := auth2.SendVerifyCode(params.AuthToken, params.CaptchaID, params.CaptchaValue, params.AuthID)
|
||||||
|
if err == nil && authInfo != nil {
|
||||||
|
user, err2 := dao.GetUserByID(dao.GetDB(), "user_id", authInfo.GetID())
|
||||||
|
if err2 == nil && user.Type&(model.UserTypeBoss|model.UserTypeOperator) != 0 {
|
||||||
|
retVal = code
|
||||||
|
}
|
||||||
|
}
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user