Ver código fonte

添加修改密码接口

huangyh 6 anos atrás
pai
commit
ca230261f1

+ 13 - 0
controllers/gen/SystemController_gen.go

@@ -255,6 +255,19 @@ func (c *SystemController) UpdateUser(ctx *gin.Context) {
 	partial.System_UpdateUser(&entitys.CtrlContext{c.apiengine, ctx, db, c.apiengine.PlatformOrmEngine})
 }
 
+// UpdatePassword
+// @Title UpdatePassword
+// @Description 修改用户密码
+// @Param	    $sys_user  false  "用户ID"
+// @Success 200 {object} sysReturn
+// @Failure 403 :id is empty
+// @router /update_password  [post,get]
+func (c *SystemController) UpdatePassword(ctx *gin.Context) {
+	//
+	db := c.apiengine.BusinessOrmEngine[ctx.GetString("domain")]
+	partial.System_UpdatePassword(&entitys.CtrlContext{c.apiengine, ctx, db, c.apiengine.PlatformOrmEngine})
+}
+
 // GetUser
 // @Title GetUser
 // @Description 更加用户ID获取用户信息

+ 31 - 0
controllers/partial/SystemController.go

@@ -362,6 +362,37 @@ func System_UpdateUser(c *entitys.CtrlContext) {
 	}
 }
 
+// _UpdatePassword
+// @Title _UpdatePassword
+// @Description 修改用户密码
+// @Param	    string  false  "用户ID"
+// @Param	password    string  false  "密码"
+// @Success 200 {object} Account
+// @Failure 403 :id is empty
+func System_UpdatePassword(c *entitys.CtrlContext) {
+	var user sysmodel.SysUser
+	err := c.Ctx.BindJSON(&user)
+
+	tk, _ := c.Ctx.Get("token")
+	operator := tk.(*entitys.Token)
+
+	if err != nil {
+		c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
+		return
+	}
+
+	user.Password = sysutils.HashPassword(user.Password, "")
+
+	paramMap := map[string]interface{}{"id": user.Id, "password": user.Password, "last_update_time": time.Now().UnixNano(), "last_update_by": operator.UserId}
+	_, err = c.PlatformDbEngine.SqlMapClient("update_user_password", &paramMap).Execute()
+
+	if err == nil {
+		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
+	} else {
+		c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
+	}
+}
+
 // _GetUser
 // @Title _GetUser
 // @Description 更加用户ID获取用户信息

+ 6 - 0
routers/system_gen.go

@@ -76,6 +76,9 @@ func registerSystemRouter(e *engine.ApiEngine) {
 	v1.GET("/update_user", ctrler.UpdateUser)
 	v1.POST("/update_user", ctrler.UpdateUser)
 
+	v1.GET("/update_password", ctrler.UpdatePassword)
+	v1.POST("/update_password", ctrler.UpdatePassword)
+
 	v1.GET("/get_user", ctrler.GetUser)
 	//v1.POST("/get_user",ctrler.GetUser)
 
@@ -163,6 +166,9 @@ func registerSystemRouter(e *engine.ApiEngine) {
 	v1.GET("/update_role", ctrler.UpdateRole)
 	v1.POST("/update_role", ctrler.UpdateRole)
 
+	v1.GET("/get_user_roles", ctrler.GetUserRoles)
+	v1.POST("/get_user_roles", ctrler.GetUserRoles)
+
 	v1.GET("/find_role_menu", ctrler.FindRoleMenu)
 	v1.POST("/find_role_menu", ctrler.FindRoleMenu)
 

+ 5 - 0
sqlconfig/light-apiengine-develop/sys_user.xml

@@ -4,4 +4,9 @@
         `name` = ?name,`mobile` = ?mobile,`email` = ?email,`org_id` = ?org_id,`last_update_by` = ?last_update_by,`last_update_time` = ?last_update_time,`temp_id` = ?temp_id,`temp_value` = ?temp_value
         where id = ?id
     </sql>
+    <sql id="update_user_password">
+        update sys_user set
+        `password` = ?password,`last_update_by` = ?last_update_by,`last_update_time` = ?last_update_time
+        where id = ?id
+    </sql>
 </sqlMap>