diff --git a/app/controllers/admin/AdminUserController.go b/app/controllers/admin/AdminUserController.go index 6f70079..e44eb4f 100644 --- a/app/controllers/admin/AdminUserController.go +++ b/app/controllers/admin/AdminUserController.go @@ -3,7 +3,7 @@ package admin import ( "github.com/revel/revel" . "github.com/leanote/leanote/app/lea" - "time" +// "time" "github.com/leanote/leanote/app/info" ) @@ -50,16 +50,17 @@ func (c AdminUser) Register(email, pwd string) revel.Result { } // 修改帐户 -func (c AdminUser) UpdateAccount(userId string) revel.Result { +func (c AdminUser) ResetPwd(userId string) revel.Result { userInfo := userService.GetUserInfo(userId) c.RenderArgs["userInfo"] = userInfo - return c.RenderTemplate("admin/user/update_account.html"); + return c.RenderTemplate("admin/user/reset_pwd.html"); } -func (c AdminUser) DoUpdateAccount(userId, accountType string, accountStartTime, accountEndTime string, maxImageNum, maxImageSize, maxAttachNum, maxAttachSize, maxPerAttachSize int) revel.Result { +func (c AdminUser) DoResetPwd(userId, pwd string) revel.Result { re := info.NewRe(); - s, _ := time.Parse("2006-01-02 15:04:02", accountStartTime) - e, _ := time.Parse("2006-01-02 15:04:02", accountEndTime) - re.Ok = userService.UpdateAccount(userId, accountType, s, e, maxImageNum, maxImageSize, maxAttachNum, maxAttachSize, maxPerAttachSize ) + if re.Ok, re.Msg = Vd("password", pwd); !re.Ok { + return c.RenderRe(re); + } + re.Ok, re.Msg = userService.ResetPwd(c.GetUserId(), userId, pwd) return c.RenderRe(re) } \ No newline at end of file diff --git a/app/service/UserService.go b/app/service/UserService.go index 3bce643..8b0ac4d 100644 --- a/app/service/UserService.go +++ b/app/service/UserService.go @@ -254,26 +254,22 @@ func (this *UserService) UpdatePwd(userId, oldPwd, pwd string) (bool, string) { return ok, "" } +// 管理员重置密码 +func (this *UserService) ResetPwd(adminUserId, userId, pwd string) (ok bool, msg string) { + adminInfo := this.GetUserInfoByAny(adminUsername) + if adminInfo.UserId.Hex() != adminUserId { + return + } + ok = db.UpdateByQField(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, "Pwd", Md5(pwd)) + return +} + // 修改主题 func (this *UserService) UpdateTheme(userId, theme string) (bool) { ok := db.UpdateByQField(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, "Theme", theme) return ok } -// 帐户类型设置 -func (this *UserService) UpdateAccount(userId, accountType string, accountStartTime, accountEndTime time.Time, - maxImageNum, maxImageSize, maxAttachNum, maxAttachSize, maxPerAttachSize int) bool { - return db.UpdateByQI(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, info.UserAccount{ - AccountType: accountType, - AccountStartTime: accountStartTime, - AccountEndTime: accountEndTime, - MaxImageNum: maxImageNum, - MaxImageSize: maxImageSize, - MaxAttachNum: maxAttachNum, - MaxAttachSize: maxAttachSize, - MaxPerAttachSize: maxPerAttachSize, - }) -} //--------------- // 修改email @@ -366,7 +362,11 @@ func (this *UserService) ListUsers(pageNumber, pageSize int, sortField string, i skipNum, sortFieldR := parsePageAndSort(pageNumber, pageSize, sortField, isAsc) query := bson.M{} if email != "" { - query["Email"] = bson.M{"$regex": bson.RegEx{".*?" + email + ".*", "i"}} + orQ := []bson.M{ + bson.M{"Email": bson.M{"$regex": bson.RegEx{".*?" + email + ".*", "i"}}}, + bson.M{"Username": bson.M{"$regex": bson.RegEx{".*?" + email + ".*", "i"}}}, + } + query["$or"] = orQ } q := db.Users.Find(query); // 总记录数 diff --git a/app/views/admin/user/add.html b/app/views/admin/user/add.html index c7cfac3..9ef59ef 100644 --- a/app/views/admin/user/add.html +++ b/app/views/admin/user/add.html @@ -42,7 +42,7 @@ $(function() { var t = this; if($("#add_user_form").valid()) { $(t).button('loading'); - ajaxPost("/auth/doRegister", getFormJsonData("add_user_form"), function(ret){ + ajaxPost("/adminUser/register", getFormJsonData("add_user_form"), function(ret){ $(t).button('reset') if(!ret.Ok) { art.alert(ret.Msg); diff --git a/app/views/admin/user/list.html b/app/views/admin/user/list.html index aee5a62..3c5e2ff 100644 --- a/app/views/admin/user/list.html +++ b/app/views/admin/user/list.html @@ -4,16 +4,8 @@
- -
@@ -21,7 +13,7 @@
- + @@ -99,7 +91,8 @@ {{.CreatedTime|datetime}} - Send Email + Reset Password + Send Email {{end}} @@ -109,16 +102,8 @@