- fix bugs in auth2

This commit is contained in:
gazebo
2019-03-05 14:18:40 +08:00
parent da3a9b8c22
commit cba9265eab
2 changed files with 11 additions and 8 deletions

View File

@@ -48,18 +48,21 @@ func (a *Auther) VerifySecret(userID, passMD5 string) (authBind *model.AuthBind,
func (a *Auther) ChangePassword(userID, oldPassMD5, newPassMD5 string) (err error) {
var authBind *model.AuthBind
db := dao.GetDB()
salt := utils.GetUUID()
encryptPwd := a.encryptPassword(newPassMD5, salt)
if authBind, err = dao.GetAuthBind(db, "", AuthType, userID); err == nil {
if err = a.checkPassword(authBind, oldPassMD5); err == nil || authBind.AuthSecret == "" { // 如果原密码为空,不判断原密码,代表重置密码
authBind.AuthSecret = newPassMD5
_, err = dao.UpdateEntity(db, authBind, "AuthSecret")
_, err = dao.UpdateEntityLogically(db, authBind, map[string]interface{}{
"AuthSecret": encryptPwd,
"AuthSecret2": salt,
}, "admin", nil)
}
} else if dao.IsNoRowsError(err) {
salt := utils.GetUUID()
err = a.AddAuthBind(&model.AuthBind{
UserID: userID,
Type: AuthType,
AuthID: userID,
AuthSecret: a.encryptPassword(newPassMD5, salt),
AuthSecret: encryptPwd,
AuthSecret2: salt,
}, "admin")
}

View File

@@ -36,14 +36,14 @@ func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBind *model.AuthBin
sessionInfo, err := api.WeixinMiniAPI.SNSCode2Session(jsCode)
if err == nil {
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
sessionKey := sessionInfo.SessionKey
sessionInfo.SessionKey = ""
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.Type = AuthTypeMP
authBind.Type = AuthTypeMini
authBind.AuthID = sessionInfo.OpenID
authBind.DetailData = string(utils.MustMarshal(sessionInfo))
authBind.UserData = sessionKey
@@ -54,7 +54,7 @@ func (a *MiniAuther) VerifySecret(dummy, jsCode string) (authBind *model.AuthBin
}
if err == nil && len(authBindList) == 0 {
authBind = &model.AuthBind{
Type: AuthTypeMP,
Type: AuthTypeMini,
AuthID: sessionInfo.OpenID,
AuthID2: sessionInfo.UnionID,
DetailData: string(utils.MustMarshal(sessionInfo)),