houyaf 3 lat temu
rodzic
commit
ed62960df9

+ 9 - 0
service/system/user_service.go

@@ -16,6 +16,7 @@ type UserService interface {
     GetById(ocId, groupId, userId int64) (*viewmodels.UserInfo, error)
     Create(ocTypeId int64, user *viewmodels.UserInfo) error
     Update(user *viewmodels.UserInfo) error
+    UpdatePassword(ocId, userId int64, pwd string) error
     ResetPassword(ocId, userId int64) error
     ChangeStatus(ocId, userId, status int64) error
     Delete(m map[string]interface{}) error
@@ -219,6 +220,14 @@ func (s *userService) Update(user *viewmodels.UserInfo) error {
     return err
 }
 
+func (s *userService) UpdatePassword(ocId, userId int64, pwd string) error {
+    hashedPwd := utils.GetMD5String(pwd)
+    data := &datamodels.Account{
+        Password: hashedPwd,
+    }
+    return s.accountRepo.Update(ocId, userId, data)
+}
+
 func (s *userService) ResetPassword(ocId, userId int64) error {
     pwd := utils.GetMD5String("888888")
     data := &datamodels.Account{

+ 16 - 4
web/controllers/user_controller.go

@@ -17,6 +17,7 @@ func (c *UserController) BeforeActivation(b mvc.BeforeActivation) {
     b.Handle("GET",         "/{groupId:int64}/{accountId:int64}",           "GetById"         )
     b.Handle("POST",        "/add",                                         "Create"          )
     b.Handle("PUT",         "/update",                                      "Update"          )
+    b.Handle("PUT",         "/updatePassword/{pwd: string}",                "UpdatePassword"  )
     b.Handle("PUT",         "/resetPassword/{userId:int64}",                "ResetPassword"   )
     b.Handle("PUT",         "/updateStatus/{userId:int64}/{status:int64}",  "UpdateStatus"    )
     b.Handle("DELETE",      "/{accountId:int64}",                           "DeleteById"      )
@@ -27,7 +28,7 @@ func (c *UserController) BeforeActivation(b mvc.BeforeActivation) {
     b.Handle("GET",         "/select",                                      "SelectUser"      )
 }
 
-func (c *UserController) GetPage() *JsonResult {
+func (c *UserController) GetPage()*JsonResult {
     params    := c.buildParams()
     data, err := c.Service.GetPage(params)
     if err != nil {
@@ -47,7 +48,7 @@ func (c *UserController) GetList() *JsonResult {
     }
 }
 
-func (c *UserController) GetById(groupId, accountId int64) *JsonResult {
+func (c *UserController) GetById(groupId, accountId int64)*JsonResult {
     ocId      := c.GetCurOcId()
     data, err := c.Service.GetById(ocId, groupId, accountId)
     if err != nil {
@@ -89,6 +90,17 @@ func (c *UserController) Update() *JsonResult {
     }
 }
 
+func (c *UserController) UpdatePassword(psw string)*JsonResult{
+    ocId   := c.GetCurOcId()
+    userId := c.GetCurUserId()
+    err    := c.Service.UpdatePassword(ocId, userId, psw)
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("密码更新成功", nil)
+    }
+}
+
 func (c *UserController) ResetPassword(userId int64)*JsonResult{
     ocId := c.GetCurOcId()
     err  := c.Service.ResetPassword(ocId, userId)
@@ -99,7 +111,7 @@ func (c *UserController) ResetPassword(userId int64)*JsonResult{
     }
 }
 
-func (c *UserController) UpdateStatus(userId, status int64) *JsonResult{
+func (c *UserController) UpdateStatus(userId, status int64)*JsonResult{
     ocId := c.GetCurOcId()
     err  := c.Service.ChangeStatus(ocId, userId, status)
     if err != nil {
@@ -109,7 +121,7 @@ func (c *UserController) UpdateStatus(userId, status int64) *JsonResult{
     }
 }
 
-func (c *UserController) DeleteById(accountId int64) *JsonResult {
+func (c *UserController) DeleteById(accountId int64)*JsonResult {
     ocId   := c.GetCurOcId()
     userId := c.GetCurUserId()