caipin 4 лет назад
Родитель
Сommit
5f76d25402

+ 1 - 1
dao/bid_account_dao.go

@@ -84,7 +84,7 @@ func (d *BidAccountDao) Create(bidsectionId int, accountData *models.CmProjectAc
 		Where("project_id=? and bidsection_id = ? and account_id= ? ", projectId, bidsectionId, accountData.Id).
 		Get(permissionAccount)
 	// 2-1
-	permiss := "{\"access\":0,\"add\":0,\"delete\":0}"
+	permiss := "{\"access\":1,\"add\":0,\"delete\":0}"
 	if permissionAccount.Id == 0 {
 		permissionAccount.ProjectId = projectId
 		permissionAccount.BidsectionId = bidsectionId

+ 18 - 0
services/backstage_service.go

@@ -29,6 +29,7 @@ type BackstageService interface {
 	ValidRuleAccountAdd(ctx iris.Context) (viewmodels.ProjectAccount, error)
 	ValidRuleAccountSave(ctx iris.Context) (viewmodels.ProjectAccount, error)
 	ValidRuleAccountEnable(ctx iris.Context) (viewmodels.ProjectAccount, error)
+	ValidRuleAccountPassword(ctx iris.Context) (viewmodels.ProjectAccount, error)
 
 	GetCldByCategoryId(categoryId string) (map[string]interface{}, error)
 	Out(ctx iris.Context) error
@@ -167,6 +168,23 @@ func (s *backstageService) ValidRuleAccountEnable(ctx iris.Context) (viewmodels.
 	return accounttVaild, nil
 }
 
+// 验证账号启用
+func (s *backstageService) ValidRuleAccountPassword(ctx iris.Context) (viewmodels.ProjectAccount, error) {
+	accounttVaild := viewmodels.ProjectAccount{}
+	err := ctx.ReadForm(&accounttVaild)
+	if err != nil {
+		log.Println("ReadForm转换异常, error=", err)
+		return accounttVaild, err
+	}
+
+	err = accounttVaild.ValidatePasswordBs()
+	if err != nil {
+		log.Println("账号密码验证, error=", err)
+		return accounttVaild, err
+	}
+	return accounttVaild, nil
+}
+
 // 验证项目用户登陆相关
 func (s *backstageService) ValidCldStaff(loginData viewmodels.StaffCld, writer http.ResponseWriter) (*viewmodels.ResultCld, error) {
 

+ 23 - 0
services/project_account_service.go

@@ -43,6 +43,7 @@ type ProjectAccountService interface {
 	SaveAccount(viewAccount viewmodels.ProjectAccount, id int, projectId int) error
 	Enable(id int, projectId int, enable int) error
 	ChangeAccount(id int, projectId int, viewAccount viewmodels.ProjectAccount) error
+	ChangeAccountBS(id int, projectId int, viewAccount viewmodels.ProjectAccount) error
 	GetProjectInfo(id int) (viewmodels.ProjectInfo, error)
 	Delete(id int, projectId int) error
 
@@ -417,6 +418,28 @@ func (s *projectAccountService) ChangeAccount(id int, projectId int, viewAccount
 	return nil
 }
 
+// 更改账号或者密码-后台
+func (s *projectAccountService) ChangeAccountBS(id int, projectId int, viewAccount viewmodels.ProjectAccount) error {
+	// 1.是否修改账号
+	field := []string{"Password"}
+	account := models.CmProjectAccount{}
+	account.Id = id
+	account.ProjectId = projectId
+
+	// 2.修改密码
+	account.Password = comm.CreatePasswordSign(viewAccount.Password, viewAccount.Account)
+
+	accountData := s.dao.Get(id, projectId)
+	if accountData.Account != viewAccount.Account {
+		account.Account = viewAccount.Account
+		field = append(field, "Account")
+	}
+
+	s.dao.Update(&account, field)
+
+	return nil
+}
+
 // 更换密码
 func (s *projectAccountService) ChangePassword(AccountData viewmodels.AccountPassword, projectId int, projectAccountId int) error {
 	// 1.获得账号

+ 41 - 41
web/backstage/project_account_bs.go

@@ -252,6 +252,47 @@ func (c *ProjectAccountBs) PostEnable() {
 	c.Ctx.JSON(iris.Map{"code": 0, "msg": "操作成功"})
 }
 
+// @Summary 设置账号密码
+// @Tags 项目设置-管理员
+// @Description 设置账号密码
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   id     body    string     true        "账号ID" default(PcqqGsn1O0jBSmLqkuOTwQ)
+// @Param   projectId     body    string     true        "项目ID"
+// @Param   account     body    string     true        "账号" default(textoopd)
+// @Param   password     body    string     true        "密码" default(ww123456)
+// @Param   X-CSRF-Token      header    string     true        "csrf"
+// @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
+// @Router /backstage/account/change [post]
+func (c *ProjectAccountBs) PostChange() {
+	// 验证内容
+	accountData, err := c.ServiceBackstage.ValidRuleAccountPassword(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	// 获得更新账号ID
+	id, err := utils.GetDecryptId(accountData.Id)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	projectId, err := utils.GetDecryptId(accountData.ProjectId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	err = c.ServiceProjectAccount.ChangeAccountBS(id, projectId, accountData)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	c.Ctx.JSON(iris.Map{"code": 0, "msg": "编辑成功"})
+}
+
 // @Summary 删除账号
 // @Tags 项目设置-管理员
 // @Description 删除账号
@@ -299,47 +340,6 @@ func (c *ProjectAccountBs) PostEnable() {
 // 	c.Ctx.JSON(iris.Map{"code": 0, "msg": "操作成功"})
 // }
 
-// @Summary 设置账号密码
-// @Tags 项目设置-管理员
-// @Description 设置账号密码
-// @Accept  json
-// @Produce  json
-// @Security ApiKeyAuth
-// @Param   id     body    string     true        "账号ID" default(PcqqGsn1O0jBSmLqkuOTwQ)
-// @Param   account     body    string     true        "账号" default(textoopd)
-// @Param   password     body    string     true        "密码" default(ww123456)
-// @Param   X-CSRF-Token      header    string     true        "csrf"
-// @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
-// @Router /backstage/account/change [post]
-func (c *ProjectAccountBs) PostChange() {
-	// 验证内容
-	AccountData, err := c.ServiceProjectAccount.ValidRule(c.Ctx)
-	if err != nil {
-		ErrMsg := utils.FormValidError(err)
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": ErrMsg})
-		return
-	} else {
-		// 获得更新账号ID
-		id, err := utils.GetDecryptId(AccountData.Id)
-		if err != nil {
-			c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
-			return
-		}
-		projectId, err := utils.GetProjectId(c.Ctx)
-		if err != nil {
-			c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
-			return
-		}
-
-		err = c.ServiceProjectAccount.ChangeAccount(id, projectId, AccountData)
-		if err != nil {
-			c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
-			return
-		}
-		c.Ctx.JSON(iris.Map{"code": 0, "msg": "编辑成功"})
-	}
-}
-
 // // @Summary 获取项目信息
 // // @Tags 项目设置-管理员
 // // @Description 获取项目信息

+ 8 - 0
web/viewmodels/project_account.go

@@ -79,6 +79,14 @@ func (l ProjectAccount) ValidateEnableBs() error {
 	)
 }
 
+func (l ProjectAccount) ValidatePasswordBs() error {
+	return validation.ValidateStruct(&l,
+		validation.Field(&l.Id, validation.Required.Error("ID不能为空")),
+		validation.Field(&l.ProjectId, validation.Required.Error("项目ID不能为空")),
+		validation.Field(&l.Password, validation.Required.Error("密码不能为空"), validation.Length(6, 18).Error("密码位数6~18之间")),
+	)
+}
+
 func (l ProjectAccount) ValidateUpdate() error {
 	return validation.ValidateStruct(&l,
 		validation.Field(&l.Name, validation.Required.Error("姓名不能为空")),