用户修改属性时的最后修改人从jxadmin改为用户id

用户注册时也记录相应的最后登录信息
This commit is contained in:
gazebo
2019-10-09 11:06:08 +08:00
parent 1c7edc4b86
commit 3855e79809
5 changed files with 25 additions and 18 deletions

View File

@@ -50,7 +50,7 @@ func (a *Auther) VerifySecret(userID, passMD5 string) (authBindEx *auth2.AuthBin
}
// 特殊接口
func (a *Auther) ChangePassword(userID, oldPassMD5, newPassMD5 string) (err error) {
func (a *Auther) ChangePassword(userID, userName, oldPassMD5, newPassMD5 string) (err error) {
var authBind *model.AuthBind
db := dao.GetDB()
salt := utils.GetUUID()
@@ -60,7 +60,7 @@ func (a *Auther) ChangePassword(userID, oldPassMD5, newPassMD5 string) (err erro
_, err = dao.UpdateEntityLogically(db, authBind, map[string]interface{}{
"AuthSecret": encryptPwd,
"AuthSecret2": salt,
}, model.AdminName, nil)
}, userName, nil)
}
} else if dao.IsNoRowsError(err) {
err = a.AddAuthBind(&auth2.AuthBindEx{
@@ -71,7 +71,7 @@ func (a *Auther) ChangePassword(userID, oldPassMD5, newPassMD5 string) (err erro
AuthSecret: encryptPwd,
AuthSecret2: salt,
},
}, model.AdminName)
}, userName)
}
return err
}

View File

@@ -139,7 +139,6 @@ func (c *OrderManager) OnOrderComments(orderCommentList []*model.OrderComment) (
}
if err == nil {
if isNewComment {
// dao.WrapAddIDCULEntity(orderComment, model.AdminName)
err = dao.CreateEntity(db, comment2)
} else if comment2 != nil {
_, err = dao.UpdateEntity(db, comment2)

View File

@@ -55,7 +55,7 @@ func (*UserProvider) GetUser(authID, authIDType string) (user auth2.IUser) {
func (*UserProvider) UpdateUserMobile(userID string, mobile string) (err error) {
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
"Mobile": mobile,
}, model.AdminName, map[string]interface{}{
}, userID, map[string]interface{}{
"UserID": userID,
})
return err
@@ -64,7 +64,7 @@ func (*UserProvider) UpdateUserMobile(userID string, mobile string) (err error)
func (*UserProvider) UpdateUserEmail(userID string, email string) (err error) {
_, err = dao.UpdateEntityLogically(dao.GetDB(), &model.User{}, map[string]interface{}{
"Email": email,
}, model.AdminName, map[string]interface{}{
}, userID, map[string]interface{}{
"UserID": userID,
})
return err
@@ -83,7 +83,8 @@ func (*UserProvider) UpdateUserType(userID string, userTypeMask int8, updateType
} else {
user.Type = userTypeMask
}
_, err = dao.UpdateEntity(db, user, "Type")
dao.WrapUpdateULEntity(user, userID)
_, err = dao.UpdateEntity(db, user, "Type", model.FieldUpdatedAt, model.FieldLastOperator)
}
return err
}
@@ -93,7 +94,7 @@ func (*UserProvider) UpdateLastLogin(userID string, lastLoginType, fromIP string
"LastLoginAt": utils.Time2Pointer(time.Now()),
"LastLoginType": lastLoginType,
"LastLoginIP": fromIP,
}, model.AdminName, map[string]interface{}{
}, userID, map[string]interface{}{
"UserID": userID,
})
return err
@@ -126,6 +127,7 @@ func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVeri
user.Type |= model.UserTypeStoreBoss
}
if err = CreateUser(user, utils.LimitUTF8StringLen(ctx.GetRealRemoteIP()+","+inAuthInfo.GetAuthID(), 32)); err == nil {
userProvider.UpdateLastLogin(user.GetID(), inAuthInfo.GetAuthType(), ctx.GetRealRemoteIP())
TryAddStoreBossRole4User(ctx, user)
if outAuthInfo, err = auth2.BindUser(mobileAuth, user); err == nil && inAuthInfo != nil {
err = auth2.AddAuthBind(&outAuthInfo.UserBasic, inAuthInfo)

View File

@@ -107,10 +107,13 @@ func UpdateEntityLogically(db *DaoDB, item interface{}, kvs map[string]interface
model.FieldDeletedAt: utils.DefaultTimeValue,
})
}
return UpdateEntityByKV(db, item, utils.MergeMaps(kvs, map[string]interface{}{
model.FieldUpdatedAt: time.Now(),
model.FieldLastOperator: userName,
}), conditions)
params := map[string]interface{}{
model.FieldUpdatedAt: time.Now(),
}
if userName != "" {
params[model.FieldLastOperator] = userName
}
return UpdateEntityByKV(db, item, utils.MergeMaps(kvs, params), conditions)
}
// 此函数会更新同步标志
@@ -133,11 +136,14 @@ func UpdateEntityLogicallyAndUpdateSyncStatus(db *DaoDB, item interface{}, kvs m
for i := 0; i < valueRows.Len(); i++ {
value := reflect.Indirect(valueRows.Index(i))
status := value.FieldByName(syncStatusFieldName).Int() | int64(valueMask)
num2, err2 := UpdateEntityByKV(db, value.Interface(), utils.MergeMaps(kvs, map[string]interface{}{
model.FieldUpdatedAt: time.Now(),
model.FieldLastOperator: userName,
syncStatusFieldName: status,
}), nil)
params := map[string]interface{}{
model.FieldUpdatedAt: time.Now(),
syncStatusFieldName: status,
}
if userName != "" {
params[model.FieldLastOperator] = userName
}
num2, err2 := UpdateEntityByKV(db, value.Interface(), utils.MergeMaps(kvs, params), nil)
if err = err2; err == nil {
num += num2
} else {

View File

@@ -290,7 +290,7 @@ func (c *Auth2Controller) ChangePassword() {
c.callChangePassword(func(params *tAuth2ChangePasswordParams) (retVal interface{}, errCode string, err error) {
authInfo, err := params.Ctx.GetV2AuthInfo()
if err == nil {
err = password.AutherObj.ChangePassword(authInfo.GetID(), params.OldPwd, params.NewPwd)
err = password.AutherObj.ChangePassword(authInfo.GetID(), params.Ctx.GetUserName(), params.OldPwd, params.NewPwd)
}
return retVal, "", err
})