- fix bugs in auth2
This commit is contained in:
@@ -48,18 +48,21 @@ func (a *Auther) VerifySecret(userID, passMD5 string) (authBind *model.AuthBind,
|
|||||||
func (a *Auther) ChangePassword(userID, oldPassMD5, newPassMD5 string) (err error) {
|
func (a *Auther) ChangePassword(userID, oldPassMD5, newPassMD5 string) (err error) {
|
||||||
var authBind *model.AuthBind
|
var authBind *model.AuthBind
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
|
salt := utils.GetUUID()
|
||||||
|
encryptPwd := a.encryptPassword(newPassMD5, salt)
|
||||||
if authBind, err = dao.GetAuthBind(db, "", AuthType, userID); err == nil {
|
if authBind, err = dao.GetAuthBind(db, "", AuthType, userID); err == nil {
|
||||||
if err = a.checkPassword(authBind, oldPassMD5); err == nil || authBind.AuthSecret == "" { // 如果原密码为空,不判断原密码,代表重置密码
|
if err = a.checkPassword(authBind, oldPassMD5); err == nil || authBind.AuthSecret == "" { // 如果原密码为空,不判断原密码,代表重置密码
|
||||||
authBind.AuthSecret = newPassMD5
|
_, err = dao.UpdateEntityLogically(db, authBind, map[string]interface{}{
|
||||||
_, err = dao.UpdateEntity(db, authBind, "AuthSecret")
|
"AuthSecret": encryptPwd,
|
||||||
|
"AuthSecret2": salt,
|
||||||
|
}, "admin", nil)
|
||||||
}
|
}
|
||||||
} else if dao.IsNoRowsError(err) {
|
} else if dao.IsNoRowsError(err) {
|
||||||
salt := utils.GetUUID()
|
|
||||||
err = a.AddAuthBind(&model.AuthBind{
|
err = a.AddAuthBind(&model.AuthBind{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Type: AuthType,
|
Type: AuthType,
|
||||||
AuthID: userID,
|
AuthID: userID,
|
||||||
AuthSecret: a.encryptPassword(newPassMD5, salt),
|
AuthSecret: encryptPwd,
|
||||||
AuthSecret2: salt,
|
AuthSecret2: salt,
|
||||||
}, "admin")
|
}, "admin")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,14 +36,14 @@ func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBind *model.AuthBin
|
|||||||
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(jsCode)
|
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(jsCode)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
if authBind, err = dao.GetAuthBind(db, "", AuthTypeMP, sessionInfo.OpenID); dao.IsNoRowsError(err) {
|
if authBind, err = dao.GetAuthBind(db, "", AuthTypeMini, sessionInfo.OpenID); dao.IsNoRowsError(err) {
|
||||||
var authBindList []*model.AuthBind
|
var authBindList []*model.AuthBind
|
||||||
sessionKey := sessionInfo.SessionKey
|
sessionKey := sessionInfo.SessionKey
|
||||||
sessionInfo.SessionKey = ""
|
sessionInfo.SessionKey = ""
|
||||||
if sessionInfo.UnionID != "" {
|
if sessionInfo.UnionID != "" {
|
||||||
if authBindList, err = dao.GetAuthBindsByAuthID2(db, sessionInfo.UnionID, []string{AuthTypeWeixin, AuthTypeMP, AuthTypeMini}); err == nil && len(authBindList) > 0 {
|
if authBindList, err = dao.GetAuthBindsByAuthID2(db, sessionInfo.UnionID, []string{AuthTypeWeixin, AuthTypeMini, AuthTypeMini}); err == nil && len(authBindList) > 0 {
|
||||||
authBind = authBindList[0]
|
authBind = authBindList[0]
|
||||||
authBind.Type = AuthTypeMP
|
authBind.Type = AuthTypeMini
|
||||||
authBind.AuthID = sessionInfo.OpenID
|
authBind.AuthID = sessionInfo.OpenID
|
||||||
authBind.DetailData = string(utils.MustMarshal(sessionInfo))
|
authBind.DetailData = string(utils.MustMarshal(sessionInfo))
|
||||||
authBind.UserData = sessionKey
|
authBind.UserData = sessionKey
|
||||||
@@ -54,7 +54,7 @@ func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBind *model.AuthBin
|
|||||||
}
|
}
|
||||||
if err == nil && len(authBindList) == 0 {
|
if err == nil && len(authBindList) == 0 {
|
||||||
authBind = &model.AuthBind{
|
authBind = &model.AuthBind{
|
||||||
Type: AuthTypeMP,
|
Type: AuthTypeMini,
|
||||||
AuthID: sessionInfo.OpenID,
|
AuthID: sessionInfo.OpenID,
|
||||||
AuthID2: sessionInfo.UnionID,
|
AuthID2: sessionInfo.UnionID,
|
||||||
DetailData: string(utils.MustMarshal(sessionInfo)),
|
DetailData: string(utils.MustMarshal(sessionInfo)),
|
||||||
|
|||||||
Reference in New Issue
Block a user