From 0cd10f221174a6bf70334e8fd8f0afe4caa48618 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Mon, 20 Jul 2020 19:24:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=AE=A1=E7=90=86=E5=91=98=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/go-fly.sql | 9 ++++++++- controller/main.go | 8 ++++++++ controller/role.go | 15 +++++++++++++++ main.go | 3 +++ models/roles.go | 10 ++++++++++ models/users.go | 6 ++++++ 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 controller/role.go create mode 100644 models/roles.go diff --git a/config/go-fly.sql b/config/go-fly.sql index 1534e60..f5be5b4 100644 --- a/config/go-fly.sql +++ b/config/go-fly.sql @@ -56,4 +56,11 @@ CREATE TABLE `user_role` ( `user_id` int(11) NOT NULL DEFAULT '0', `role_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8 + +DROP TABLE IF EXISTS `role`; +CREATE TABLE `role` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL DEFAULT '', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 diff --git a/controller/main.go b/controller/main.go index 3f07b91..c84cbc9 100644 --- a/controller/main.go +++ b/controller/main.go @@ -2,6 +2,7 @@ package controller import ( "github.com/gin-gonic/gin" + "github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/tmpl" "github.com/taoshihan1991/imaptool/tools" "net/http" @@ -18,8 +19,15 @@ func ActionMain(w http.ResponseWriter, r *http.Request) { render.Display("main", render) } func MainCheckAuth(c *gin.Context) { + id,_:=c.Get("kefu_id") + userinfo:=models.FindUserRole("user.avator,user.name,user.id, role.name role_name",id) c.JSON(200, gin.H{ "code": 200, "msg": "验证成功", + "result":gin.H{ + "avator":userinfo.Avator, + "name":userinfo.Name, + "role_name":userinfo.RoleName, + }, }) } diff --git a/controller/role.go b/controller/role.go new file mode 100644 index 0000000..b161530 --- /dev/null +++ b/controller/role.go @@ -0,0 +1,15 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "github.com/taoshihan1991/imaptool/models" +) + +func GetRoleList(c *gin.Context){ + roles:=models.FindRoles() + c.JSON(200, gin.H{ + "code": 200, + "msg": "获取成功", + "result":roles, + }) +} diff --git a/main.go b/main.go index d36dca6..194b704 100644 --- a/main.go +++ b/main.go @@ -56,6 +56,9 @@ func main() { engine.GET("/setting", tmpl.PageSetting) //设置mysql engine.GET("/setting_mysql", tmpl.PageSettingMysql) + //角色列表 + engine.GET("/roles", controller.GetRoleList) + //网页部署 engine.GET("/setting_deploy", tmpl.PageSettingDeploy) //邮箱列表 diff --git a/models/roles.go b/models/roles.go new file mode 100644 index 0000000..7d7654c --- /dev/null +++ b/models/roles.go @@ -0,0 +1,10 @@ +package models +type Role struct{ + Id string `json:"role_id"` + Name string `json:"role_name"` +} +func FindRoles()[]Role{ + var roles []Role + DB.Order("id desc").Find(&roles) + return roles +} \ No newline at end of file diff --git a/models/users.go b/models/users.go index 07cf753..1c6ab73 100644 --- a/models/users.go +++ b/models/users.go @@ -9,6 +9,7 @@ type User struct { Password string `json:"password"` Nickname string `json:"nickname"` Avator string `json:"avator"` + RoleName string `json:"role_name"` } func CreateUser(name string,password string,avator string,nickname string){ user:=&User{ @@ -47,4 +48,9 @@ func FindUsers()[]User{ var users []User DB.Order("id desc").Find(&users) return users +} +func FindUserRole(query interface{},id interface{})User{ + var user User + DB.Select(query).Where("user.id = ?", id).Joins("join user_role on user.id=user_role.user_id").Joins("join role on user_role.role_id=role.id").First(&user) + return user } \ No newline at end of file