提交 089aeb42 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

增加了用户权限设置

上级 e56101c3
......@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
uuid "github.com/satori/go.uuid"
"main/controller/servers"
"main/middleware"
"main/model/dbModel"
......@@ -175,3 +176,27 @@ func GetUserList(c *gin.Context) {
})
}
}
type SetUserAuth struct {
UUID uuid.UUID `json:"uuid"`
AuthorityId string `json:"authorityId"`
}
// @Tags User
// @Summary 设置用户权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.SetUserAuth true "设置用户权限"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/setUserAuthority [post]
func SetUserAuthority(c *gin.Context) {
var sua SetUserAuth
_ = c.BindJSON(&sua)
err := new(dbModel.User).SetUserAuthority(sua.UUID, sua.AuthorityId)
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("修改失败,%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "修改成功", gin.H{})
}
}
......@@ -11,7 +11,7 @@
Target Server Version : 50644
File Encoding : 65001
Date: 09/10/2019 18:28:48
Date: 09/10/2019 23:08:15
*/
SET NAMES utf8mb4;
......@@ -30,7 +30,7 @@ CREATE TABLE `api_authorities` (
`api_id` int(10) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_api_authorities_deleted_at`(`deleted_at`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 185 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 212 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of api_authorities
......@@ -44,31 +44,34 @@ INSERT INTO `api_authorities` VALUES (77, '2019-09-30 15:34:19', '2019-09-30 15:
INSERT INTO `api_authorities` VALUES (78, '2019-09-30 15:34:19', '2019-09-30 15:34:19', NULL, 9528, 17);
INSERT INTO `api_authorities` VALUES (79, '2019-09-30 15:34:19', '2019-09-30 15:34:19', NULL, 9528, 23);
INSERT INTO `api_authorities` VALUES (80, '2019-09-30 15:34:19', '2019-09-30 15:34:19', NULL, 9528, 24);
INSERT INTO `api_authorities` VALUES (159, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 1);
INSERT INTO `api_authorities` VALUES (160, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 2);
INSERT INTO `api_authorities` VALUES (161, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 3);
INSERT INTO `api_authorities` VALUES (162, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 4);
INSERT INTO `api_authorities` VALUES (163, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 5);
INSERT INTO `api_authorities` VALUES (164, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 6);
INSERT INTO `api_authorities` VALUES (165, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 7);
INSERT INTO `api_authorities` VALUES (166, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 8);
INSERT INTO `api_authorities` VALUES (167, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 9);
INSERT INTO `api_authorities` VALUES (168, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 10);
INSERT INTO `api_authorities` VALUES (169, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 28);
INSERT INTO `api_authorities` VALUES (170, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 11);
INSERT INTO `api_authorities` VALUES (171, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 12);
INSERT INTO `api_authorities` VALUES (172, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 13);
INSERT INTO `api_authorities` VALUES (173, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 14);
INSERT INTO `api_authorities` VALUES (174, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 15);
INSERT INTO `api_authorities` VALUES (175, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 16);
INSERT INTO `api_authorities` VALUES (176, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 17);
INSERT INTO `api_authorities` VALUES (177, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 18);
INSERT INTO `api_authorities` VALUES (178, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 19);
INSERT INTO `api_authorities` VALUES (179, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 20);
INSERT INTO `api_authorities` VALUES (180, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 21);
INSERT INTO `api_authorities` VALUES (181, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 22);
INSERT INTO `api_authorities` VALUES (182, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 23);
INSERT INTO `api_authorities` VALUES (183, '2019-10-09 15:15:27', '2019-10-09 15:15:27', NULL, 888, 24);
INSERT INTO `api_authorities` VALUES (184, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 1);
INSERT INTO `api_authorities` VALUES (185, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 2);
INSERT INTO `api_authorities` VALUES (186, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 3);
INSERT INTO `api_authorities` VALUES (187, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 4);
INSERT INTO `api_authorities` VALUES (188, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 5);
INSERT INTO `api_authorities` VALUES (189, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 6);
INSERT INTO `api_authorities` VALUES (190, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 7);
INSERT INTO `api_authorities` VALUES (191, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 8);
INSERT INTO `api_authorities` VALUES (192, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 9);
INSERT INTO `api_authorities` VALUES (193, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 10);
INSERT INTO `api_authorities` VALUES (194, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 11);
INSERT INTO `api_authorities` VALUES (195, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 12);
INSERT INTO `api_authorities` VALUES (196, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 13);
INSERT INTO `api_authorities` VALUES (197, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 14);
INSERT INTO `api_authorities` VALUES (198, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 15);
INSERT INTO `api_authorities` VALUES (199, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 16);
INSERT INTO `api_authorities` VALUES (200, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 17);
INSERT INTO `api_authorities` VALUES (201, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 18);
INSERT INTO `api_authorities` VALUES (202, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 19);
INSERT INTO `api_authorities` VALUES (203, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 20);
INSERT INTO `api_authorities` VALUES (204, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 21);
INSERT INTO `api_authorities` VALUES (205, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 22);
INSERT INTO `api_authorities` VALUES (206, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 23);
INSERT INTO `api_authorities` VALUES (207, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 24);
INSERT INTO `api_authorities` VALUES (208, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 28);
INSERT INTO `api_authorities` VALUES (209, '2019-10-09 23:01:52', '2019-10-09 23:01:52', NULL, 888, 29);
INSERT INTO `api_authorities` VALUES (210, '2019-10-09 23:04:56', '2019-10-09 23:04:56', NULL, 999, 1);
INSERT INTO `api_authorities` VALUES (211, '2019-10-09 23:04:56', '2019-10-09 23:04:56', NULL, 999, 2);
-- ----------------------------
-- Table structure for apis
......@@ -85,7 +88,7 @@ CREATE TABLE `apis` (
`group` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_apis_deleted_at`(`deleted_at`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 29 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 30 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of apis
......@@ -116,6 +119,7 @@ INSERT INTO `apis` VALUES (23, '2019-09-30 15:29:19', '2019-09-30 15:29:19', NUL
INSERT INTO `apis` VALUES (24, '2019-09-30 15:29:33', '2019-09-30 15:29:33', NULL, NULL, '/user/uploadHeaderImg', '上传头像', 'user');
INSERT INTO `apis` VALUES (25, '2019-09-30 15:30:00', '2019-09-30 15:30:00', '2019-10-09 15:26:37', NULL, '/user/getInfoList', '分页获取用户列表', 'user');
INSERT INTO `apis` VALUES (28, '2019-10-09 15:15:17', '2019-10-09 15:17:07', NULL, NULL, '/user/getUserList', '获取用户列表', 'user');
INSERT INTO `apis` VALUES (29, '2019-10-09 23:01:40', '2019-10-09 23:01:40', NULL, NULL, '/user/setUserAuthority', '修改用户角色', 'user');
-- ----------------------------
-- Table structure for authorities
......@@ -131,7 +135,7 @@ CREATE TABLE `authorities` (
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `authority_id`(`authority_id`) USING BTREE,
INDEX `idx_authorities_deleted_at`(`deleted_at`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 13 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of authorities
......@@ -142,6 +146,7 @@ INSERT INTO `authorities` VALUES (3, '2019-09-18 22:20:28', '2019-09-18 22:20:28
INSERT INTO `authorities` VALUES (6, '2019-09-18 22:23:33', '2019-09-18 22:23:33', NULL, 9528, '测试角色');
INSERT INTO `authorities` VALUES (7, '2019-09-18 22:24:39', '2019-09-18 22:24:39', '2019-09-18 22:25:19', 9529, '测试角色');
INSERT INTO `authorities` VALUES (8, '2019-09-18 22:25:13', '2019-09-18 22:25:13', '2019-09-18 22:25:17', 9522, '测试角色');
INSERT INTO `authorities` VALUES (12, '2019-10-09 23:04:18', '2019-10-09 23:04:18', NULL, 999, '封禁');
-- ----------------------------
-- Table structure for base_menus
......@@ -208,7 +213,7 @@ CREATE TABLE `menus` (
`nick_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_menus_deleted_at`(`deleted_at`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 231 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 233 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of menus
......@@ -225,6 +230,8 @@ INSERT INTO `menus` VALUES (227, '2019-09-19 22:11:53', '2019-09-19 22:11:53', N
INSERT INTO `menus` VALUES (228, '2019-09-19 22:13:18', '2019-09-19 22:13:18', NULL, 0, 888, 'menu', 'menu', 0, 'view/superAdmin/menu/menu.vue', '菜单管理', 's-order', 3, '5', '菜单管理');
INSERT INTO `menus` VALUES (229, '2019-09-19 22:13:36', '2019-09-19 22:13:36', NULL, 0, 888, 'api', 'api', 0, 'view/superAdmin/api/api.vue', 'api管理', 's-platform', 3, '6', 'api管理');
INSERT INTO `menus` VALUES (230, '2019-10-09 15:12:29', '2019-10-09 15:14:44', NULL, 0, 888, 'user', 'user', 0, 'view/superAdmin/user/user.vue', '用户管理', 'coordinate', 3, '17', '用户管理');
INSERT INTO `menus` VALUES (231, '2019-09-19 22:05:18', '2019-09-19 22:05:18', NULL, 0, 999, 'dashbord', 'dashbord', 0, 'view/dashbord/index.vue', '仪表盘', 'setting', 0, '1', '仪表盘');
INSERT INTO `menus` VALUES (232, '2019-09-19 22:06:17', '2019-09-30 15:44:50', NULL, 0, 999, 'test', 'test', 0, 'view/test/index.vue', '测试菜单', 'info', 0, '2', '测试菜单');
-- ----------------------------
-- Table structure for users
......@@ -256,6 +263,6 @@ INSERT INTO `users` VALUES (11, '2019-09-13 17:27:29', '2019-09-13 17:27:29', NU
INSERT INTO `users` VALUES (12, '2019-09-13 17:28:56', '2019-09-13 17:28:56', NULL, 0x65373939636563362D346337662D343338632D383634372D376435633333393734353165, NULL, NULL, 'QMPlusUser', 'http://www.henrongyi.top/avatar/lufu.jpg', 888, NULL, 'a30317465', '3ec063004a6f31642261936a379fde3d');
INSERT INTO `users` VALUES (13, '2019-09-13 17:29:26', '2019-09-13 17:29:26', NULL, 0x65653764353932322D323333312D343162632D393363322D613665366461306465343230, NULL, NULL, 'QMPlusUser', 'http://www.henrongyi.top/avatar/lufu.jpg', 888, NULL, 'a30317465', '3ec063004a6f31642261936a379fde3d');
INSERT INTO `users` VALUES (14, '2019-09-13 17:29:28', '2019-09-13 17:29:28', NULL, 0x35623464333461322D343266352D343763352D613932642D613637616536643461643334, NULL, NULL, 'QMPlusUser', 'http://www.henrongyi.top/avatar/lufu.jpg', 888, NULL, 'a30317465', '3ec063004a6f31642261936a379fde3d');
INSERT INTO `users` VALUES (15, '2019-09-13 17:31:16', '2019-09-13 17:31:16', NULL, 0x34306437393436612D363732382D346536662D396434302D313432356566653831363032, NULL, NULL, 'QMPlusUser', 'http://www.henrongyi.top/avatar/lufu.jpg', 888, NULL, 'a303146523', 'e10adc3949ba59abbe56e057f20f883e');
INSERT INTO `users` VALUES (15, '2019-09-13 17:31:16', '2019-10-09 23:04:28', NULL, 0x34306437393436612D363732382D346536662D396434302D313432356566653831363032, NULL, NULL, 'QMPlusUser', 'http://www.henrongyi.top/avatar/lufu.jpg', 999, NULL, 'a303146523', 'e10adc3949ba59abbe56e057f20f883e');
SET FOREIGN_KEY_CHECKS = 1;
......@@ -23,7 +23,9 @@ func JWTAuth() gin.HandlerFunc {
// 我们这里jwt鉴权取头部信息 x-token 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localSstorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录
token := c.Request.Header.Get("x-token")
if token == "" {
servers.ReportFormat(c, false, "未登录或非法访问", gin.H{})
servers.ReportFormat(c, false, "未登录或非法访问", gin.H{
"reload": true,
})
c.Abort()
return
}
......@@ -38,7 +40,9 @@ func JWTAuth() gin.HandlerFunc {
c.Abort()
return
}
servers.ReportFormat(c, false, err.Error(), gin.H{})
servers.ReportFormat(c, false, err.Error(), gin.H{
"reload": true,
})
c.Abort()
return
}
......
......@@ -54,9 +54,9 @@ func (u *User) ChangePassword(newPassword string) (err error, userInter *User) {
}
//用户更新接口
func (u *User) UpdataUser() (err error, userInter *User) {
err = qmsql.DEFAULTDB.Create(u).Error
return err, u
func (u *User) SetUserAuthority(uuid uuid.UUID, AuthorityId string) (err error) {
err = qmsql.DEFAULTDB.Where("uuid = ?", uuid).First(&User{}).Update("authority_id", AuthorityId).Error
return err
}
//用户登录
......
......@@ -9,8 +9,9 @@ import (
func InitUserRouter(Router *gin.Engine) {
UserRouter := Router.Group("user").Use(middleware.JWTAuth())
{
UserRouter.POST("changePassword", api.ChangePassword) // 修改密码
UserRouter.POST("uploadHeaderImg", api.UploadHeaderImg) //上传头像
UserRouter.POST("getUserList", api.GetUserList) // 分页获取用户列表
UserRouter.POST("changePassword", api.ChangePassword) // 修改密码
UserRouter.POST("uploadHeaderImg", api.UploadHeaderImg) //上传头像
UserRouter.POST("getUserList", api.GetUserList) // 分页获取用户列表
UserRouter.POST("setUserAuthority", api.SetUserAuthority) //设置用户权限
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册