修改权限部分实现
This commit is contained in:
parent
6d7e6c26fc
commit
ed2b936bf2
20
dao/user.go
20
dao/user.go
|
|
@ -14,15 +14,19 @@ type User struct {
|
||||||
Password string `gorm:"column:password"`
|
Password string `gorm:"column:password"`
|
||||||
Gender string `gorm:"column:gender"`
|
Gender string `gorm:"column:gender"`
|
||||||
Role string `gorm:"column:role"`
|
Role string `gorm:"column:role"`
|
||||||
Redis bool `gorm:"column:redis"`
|
Redis int `gorm:"column:redis"`
|
||||||
Run bool `gorm:"column:run"`
|
Run int `gorm:"column:run"`
|
||||||
Upload bool `gorm:"column:upload"`
|
Upload int `gorm:"column:upload"`
|
||||||
VideoFunc bool `gorm:"column:video_func"` //视频功能
|
VideoFunc int `gorm:"column:video_func"` //视频功能
|
||||||
DeviceFunc bool `gorm:"column:device_func"` //设备功能
|
DeviceFunc int `gorm:"column:device_func"` //设备功能
|
||||||
CIDFunc bool `gorm:"column:cid_func"` //持续集成功能
|
CIDFunc int `gorm:"column:cid_func"` //持续集成功能, 0为无效, -1为false, 1为true
|
||||||
Avatar string `gorm:"column:avatar"`
|
Avatar string `gorm:"column:avatar"`
|
||||||
CreateTime string `gorm:"column:create_time"`
|
PasswordNeedSecondAuth int `gorm:"column:password_need_second_auth" json:"password_need_second_auth"`
|
||||||
UpdateTime string `gorm:"column:update_time"`
|
ThirdPartyNeedSecondAuth int `gorm:"column:third_party_need_second_auth" json:"third_party_need_second_auth"`
|
||||||
|
CodeNeedSecondAuth int `gorm:"column:code_need_second_auth" json:"code_need_second_auth"`
|
||||||
|
AISecondAuth int `json:"ai_second_auth" column:"ai_second_auth"`
|
||||||
|
LoginAddressInfo string `gorm:"column:login_address_info" json:"login_address_info,omitempty"`
|
||||||
|
LoginDeviceInfo string `gorm:"column:login_device_info" json:"login_device_info,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUser(name, password, email, gender string, age int) uint {
|
func CreateUser(name, password, email, gender string, age int) uint {
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ func RunCID(c *gin.Context) {
|
||||||
//获取权限
|
//获取权限
|
||||||
//user := dao.FindUserByUserID(authID)
|
//user := dao.FindUserByUserID(authID)
|
||||||
user := service.GetUserByIDFromUserCenter(authID)
|
user := service.GetUserByIDFromUserCenter(authID)
|
||||||
if user.Run == false {
|
if user.Run > 0 {
|
||||||
c.JSON(200, gin.H{"error": "no run Permissions", "code": proto.NoRunPermissions, "message": "no run Permissions"})
|
c.JSON(200, gin.H{"error": "no run Permissions", "code": proto.NoRunPermissions, "message": "no run Permissions"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +230,7 @@ func CIDCallback(c *gin.Context) {
|
||||||
|
|
||||||
//user := dao.FindUserByUserID(res.Auth_id)
|
//user := dao.FindUserByUserID(res.Auth_id)
|
||||||
user := service.GetUserByIDFromUserCenter(res.Auth_id)
|
user := service.GetUserByIDFromUserCenter(res.Auth_id)
|
||||||
if user.Run == false {
|
if user.Run > 0 {
|
||||||
resp.Code, resp.Message = proto.NoRunPermissions, "the user has no run Permissions"
|
resp.Code, resp.Message = proto.NoRunPermissions, "the user has no run Permissions"
|
||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ func UploadFileV2(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
user := dao.FindUserByUserID(id1)
|
user := dao.FindUserByUserID(id1)
|
||||||
if user.Upload == false {
|
if user.Upload > 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "no upload Permissions", "code": proto.NoUploadPermissions, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "no upload Permissions", "code": proto.NoUploadPermissions, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ func UploadFile(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
user := dao.FindUserByUserID(id1)
|
user := dao.FindUserByUserID(id1)
|
||||||
if user.Upload == false {
|
if user.Upload > 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "no upload Permissions", "code": proto.NoUploadPermissions, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "no upload Permissions", "code": proto.NoUploadPermissions, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -351,7 +351,7 @@ func SetRedis(c *gin.Context) {
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
id1 := int(id.(float64))
|
id1 := int(id.(float64))
|
||||||
user := dao.FindUserByUserID(id1)
|
user := dao.FindUserByUserID(id1)
|
||||||
if user.Redis == false {
|
if user.Redis > 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "no redis Permissions", "code": proto.NoRedisPermissions, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "no redis Permissions", "code": proto.NoRedisPermissions, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -379,7 +379,7 @@ func GetRedis(c *gin.Context) {
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
id1 := int(id.(float64))
|
id1 := int(id.(float64))
|
||||||
user := dao.FindUserByUserID(id1)
|
user := dao.FindUserByUserID(id1)
|
||||||
if user.Redis == false {
|
if user.Redis > 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "no redis Permissions", "code": proto.NoRedisPermissions, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "no redis Permissions", "code": proto.NoRedisPermissions, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
main.go
6
main.go
|
|
@ -392,13 +392,13 @@ func UserFuncIntercept(id int, url string) bool {
|
||||||
//如果用户有权限,则不拦截
|
//如果用户有权限,则不拦截
|
||||||
for k, v := range proto.Per_menu_map {
|
for k, v := range proto.Per_menu_map {
|
||||||
if strings.Contains(url, k) {
|
if strings.Contains(url, k) {
|
||||||
if v == 1 && user.VideoFunc == false {
|
if v == 1 && user.VideoFunc > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if v == 2 && user.DeviceFunc == false {
|
if v == 2 && user.DeviceFunc > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if v == 3 && user.CIDFunc == false {
|
if v == 3 && user.CIDFunc > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue