Browse Source

编写授权

master
超级管理员 3 years ago
parent
commit
03c0cd27e5
  1. 2
      api/base/loginVerify/login.go
  2. 42
      api/version1/empower/system_license.go
  3. 21
      api/version1/empower/type.go
  4. 2
      api/version1/entry.go
  5. 2
      apirouter/entry.go
  6. 20
      apirouter/v1/empowerrouter/authorize.go
  7. 4
      apirouter/v1/empowerrouter/type.go
  8. 14
      identification/interceptor/identity.go
  9. 4
      initialization/route/initRoute.go
  10. 2
      models/modelssystempermission/empower.go
  11. 2
      overall/publicmethod/formatOutput.go
  12. 2
      overall/publicmethod/technique.go

2
api/base/loginVerify/login.go

@ -150,6 +150,8 @@ func (a *ApiMethod) ScanCodeLogin(c *gin.Context) {
myCont["planformaldate"] = userCont.Planformaldate //预计转正日期
myCont["political_outlook"] = userCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
redisClient.HashMsetAdd(redisMyContKey, myCont)
fmt.Printf("redisMyContKey------Login----->%v\n", redisMyContKey)
publicmethod.Result(0, saveData, c)
}

42
api/version1/empower/system_license.go

@ -0,0 +1,42 @@
package empower
import (
"key_performance_indicators/models/modelssystempermission"
"key_performance_indicators/overall/publicmethod"
"strings"
"github.com/gin-gonic/gin"
)
// 系统授权
func (a *ApiMethod) ObtainAuthorization(c *gin.Context) {
var receivedValue getSystemEmpower
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.System == "" {
publicmethod.Result(1, err, c, "未知系统!不可授权!")
return
}
//获取登录人信息
context, err := publicmethod.LoginMyCont(c)
if err != nil {
publicmethod.Result(1, err, c, "未知身份!不可授权!")
return
}
var systemPermission modelssystempermission.Empower
err = systemPermission.GetCont(map[string]interface{}{"`state`": 1, "`ordid`": context.AdminOrg, "`post_id`": context.Position, "`system`": receivedValue.System}, "`point_id`")
if err != nil {
publicmethod.Result(1, err, c, "没有可使用的授权信息!")
return
}
// var pointId []string
pointId := strings.Split(systemPermission.PointId, ",")
if len(pointId) < 1 {
publicmethod.Result(1, err, c, "没有可使用的授23权信息!")
return
}
publicmethod.Result(0, pointId, c)
}

21
api/version1/empower/type.go

@ -0,0 +1,21 @@
package empower
import (
"key_performance_indicators/overall/publicmethod"
"github.com/gin-gonic/gin"
)
type ApiMethod struct{}
// 系统授权配置
func (a *ApiMethod) Index(c *gin.Context) {
outputCont := publicmethod.MapOut[string]()
outputCont["index"] = "系统授权配置"
publicmethod.Result(0, outputCont, c)
}
// 获取系统权限参数
type getSystemEmpower struct {
System string `json:"system"`
}

2
api/version1/entry.go

@ -4,6 +4,7 @@ import (
"key_performance_indicators/api/version1/bookimg"
"key_performance_indicators/api/version1/departmentseting/departmentpc"
"key_performance_indicators/api/version1/departmentseting/departmentweb"
"key_performance_indicators/api/version1/empower"
"key_performance_indicators/api/version1/honoraryArchives"
"key_performance_indicators/api/version1/jurisdiction/jurisdictionpc"
"key_performance_indicators/api/version1/postseting/postpc"
@ -18,6 +19,7 @@ type ApiEntry struct {
DeparmentWebApi departmentweb.ApiMethod //部门web端
BookImg bookimg.ApiMethod //图文信息管理
JurisdictionpcApi jurisdictionpc.ApiMethod //权限模块PC端
EmpowerApi empower.ApiMethod //系统授权
}
var AppApiEntry = new(ApiEntry)

2
apirouter/entry.go

@ -5,6 +5,7 @@ import (
"key_performance_indicators/apirouter/empower"
"key_performance_indicators/apirouter/v1/bookimg"
"key_performance_indicators/apirouter/v1/departmentseting"
"key_performance_indicators/apirouter/v1/empowerrouter"
honorsRoute "key_performance_indicators/apirouter/v1/honorsRoute"
"key_performance_indicators/apirouter/v1/postseting"
"key_performance_indicators/apirouter/v1/systempower"
@ -22,6 +23,7 @@ type RouterGroup struct {
DepartmentRouter departmentseting.ApiRouter
BookImg bookimg.ApiRouter
SystemPowerRouter systempower.ApiRouter
Empowerouter empowerrouter.ApiRouter
}
var RouterGroupEntry = new(RouterGroup)

20
apirouter/v1/empowerrouter/authorize.go

@ -0,0 +1,20 @@
package empowerrouter
import (
"key_performance_indicators/api/version1"
"github.com/gin-gonic/gin"
)
// 系统授权
func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) {
apiRouter := router.Group("system_authorizing")
var methodBinding = version1.AppApiEntry.EmpowerApi
{
apiRouter.GET("", methodBinding.Index) //入口
apiRouter.POST("", methodBinding.Index) //入口
apiRouter.POST("obtain_authorization", methodBinding.ObtainAuthorization) //系统授权
}
}

4
apirouter/v1/empowerrouter/type.go

@ -0,0 +1,4 @@
package empowerrouter
//系统授权
type ApiRouter struct{}

14
identification/interceptor/identity.go

@ -3,6 +3,7 @@ package interceptor
import (
"fmt"
"key_performance_indicators/middleware/grocerystore"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelssystempermission"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
@ -37,13 +38,17 @@ func AuthenticateUser() gin.HandlerFunc {
c.Abort()
return
}
myCont, myErr := publicmethod.GetUserRedisCont(userRedisToken["usernumber"])
// myCont, myErr := publicmethod.GetUserRedisCont(userRedisToken["usernumber"])
var myCont modelshr.ManCont
myErr := myCont.GetCont(map[string]interface{}{"`number`": userRedisToken["usernumber"]})
if myErr != nil {
response.FailWithDetailed(gin.H{"reload": false, "code": 303, "data": myErr}, "登录超时!请重新登录", c)
c.Abort()
return
}
// fmt.Printf("myCont---------------->%v\n", myCont)
// myContJson, _ := json.Marshal(myCont)
// fmt.Printf("myCont---------------->%v\n", string(myContJson))
c.Set(overall.MyContJwt, myCont)
writeRedisData := publicmethod.MapOut[string]()
for i, v := range userRedisToken {
@ -102,6 +107,11 @@ func AuthenticateUser() gin.HandlerFunc {
myContRedis["planformaldate"] = myCont.Planformaldate //预计转正日期
myContRedis["political_outlook"] = myCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, myCont.Number)
// fmt.Printf("redisMyContKey------------>%v\n", redisMyContKey)
// myContRedisJson, _ := json.Marshal(myContRedis)
// fmt.Printf("myContRedisJson------------>%v\n", string(myContRedisJson))
redisClient.HashMsetAdd(redisMyContKey, myContRedis)
c.Next()
}

4
initialization/route/initRoute.go

@ -68,6 +68,10 @@ func InitialRouter() *gin.Engine {
// 图文信息
bookimgRouterApi := apirouter.RouterGroupEntry.BookImg
bookimgRouterApi.RouterGroup(VerifyIdentity)
//系统授权
systemAuthorizingApi := apirouter.RouterGroupEntry.Empowerouter
systemAuthorizingApi.RouterGroup(VerifyIdentity) //系统授权
}
//验证身份接口 无需鉴权Url(主要web端使用)
VerifyIdentityWeb := router.Group("")

2
models/modelssystempermission/empower.go

@ -16,7 +16,7 @@ type Empower struct {
}
func (Empower *Empower) TableName() string {
return "Empower"
return "empower"
}
// 编辑内容

2
overall/publicmethod/formatOutput.go

@ -53,11 +53,13 @@ func ResultList(code, page, pageSize int, total, count int64, data interface{},
// 登录信息转换
func LoginMyCont(c *gin.Context) (myCont modelshr.ManCont, err error) {
context, exi := c.Get(overall.MyContJwt)
if exi != true {
err = errors.New("对不起!你没有该功能的操作权限!1")
return
}
jsonCont, jsonErr := json.Marshal(context)
// fmt.Printf("LoginMyCont--------->%v\n", string(jsonCont))
if jsonErr != nil {
err = jsonErr
return

2
overall/publicmethod/technique.go

@ -403,6 +403,7 @@ func GetUserRedisCont(number string) (manCont modelshr.ManCont, err error) {
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, number)
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
useMap, isTrue := redisClient.HashGetAll(redisMyContKey)
// fmt.Printf("redisMyContKey------pubils------>%v\n", redisMyContKey)
if isTrue == false {
err.Error()
return
@ -417,6 +418,7 @@ func GetUserRedisCont(number string) (manCont modelshr.ManCont, err error) {
// 获取人员Redis信息返回指针
func GetUserRedisContPointer(number string) (manCont modelshr.ManCont, err error) {
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, number)
fmt.Printf("redisMyContKey------pubils------>%v\n", redisMyContKey)
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
useMap, isTrue := redisClient.HashGetAll(redisMyContKey)
if isTrue == false {

Loading…
Cancel
Save