获取当前登录管理员信息

pull/30/head
taoshihan1991 4 years ago
parent d4ed409963
commit 0cd10f2211

@ -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
) 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

@ -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,
},
})
}

@ -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,
})
}

@ -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)
//邮箱列表

@ -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
}

@ -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
}
Loading…
Cancel
Save