登录用户路由信息
This commit is contained in:
@@ -2,9 +2,15 @@ package security
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"ems.agt/features/security/service"
|
||||
"ems.agt/lib/core/account"
|
||||
"ems.agt/lib/core/conf"
|
||||
"ems.agt/lib/core/utils/ctx"
|
||||
"ems.agt/lib/core/vo/result"
|
||||
"ems.agt/lib/dborm"
|
||||
"ems.agt/lib/global"
|
||||
"ems.agt/lib/log"
|
||||
@@ -19,6 +25,10 @@ var (
|
||||
|
||||
CustomUriOauthToken = config.UriPrefix + "/securityManagement/{apiVersion}/{elementTypeValue}/token"
|
||||
CustomUriOauthHandshake = config.UriPrefix + "/securityManagement/{apiVersion}/{elementTypeValue}/handshake"
|
||||
|
||||
// 登录用户路由信息
|
||||
UriRouters = config.DefaultUriPrefix + "/securityManagement/{apiVersion}/getRouters"
|
||||
CustomUriRouters = config.UriPrefix + "/securityManagement/{apiVersion}/getRouters"
|
||||
)
|
||||
|
||||
func LoginFromOMC(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -102,7 +112,13 @@ func LoginFromOMC(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
services.ResponseStatusOK200Login(w, token, user)
|
||||
// 缓存用户信息
|
||||
account.CacheLoginUser(user)
|
||||
// 角色权限集合,管理员拥有所有权限
|
||||
userId := fmt.Sprint(user.Id)
|
||||
isAdmin := conf.IsAdmin(userId)
|
||||
roles, perms := service.NewServiceAccount.RoleAndMenuPerms(userId, isAdmin)
|
||||
services.ResponseStatusOK200LoginWhitRP(w, token, user, roles, perms)
|
||||
}
|
||||
|
||||
func LogoutFromOMC(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -136,12 +152,14 @@ func LogoutFromOMC(w http.ResponseWriter, r *http.Request) {
|
||||
// return
|
||||
// }
|
||||
|
||||
_, err = dborm.XormLogoutUpdateSession(token)
|
||||
se, err := dborm.XormLogoutUpdateSession(token)
|
||||
if err != nil {
|
||||
log.Error("Uri is invalid")
|
||||
services.ResponseNotFound404UriNotExist(w, r)
|
||||
return
|
||||
}
|
||||
// 清除缓存用户信息
|
||||
account.ClearLoginUser(se.AccountId)
|
||||
services.ResponseStatusOK200Null(w)
|
||||
return
|
||||
}
|
||||
@@ -181,3 +199,13 @@ func HandshakeFromOMC(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseStatusOK200Null(w)
|
||||
return
|
||||
}
|
||||
|
||||
// 登录用户路由信息
|
||||
func Routers(w http.ResponseWriter, r *http.Request) {
|
||||
userID := ctx.LoginUserToUserID(r)
|
||||
|
||||
// 前端路由,管理员拥有所有
|
||||
isAdmin := conf.IsAdmin(userID)
|
||||
buildMenus := service.NewServiceAccount.RouteMenus(userID, isAdmin)
|
||||
ctx.JSON(w, 200, result.OkData(buildMenus))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user