feat:完善项目

This commit is contained in:
henry
2021-11-08 15:52:46 +08:00
parent 1502076841
commit 1cc95fb5ca
16 changed files with 154 additions and 64 deletions

View File

@ -3,13 +3,9 @@ package router
import (
"ArmedPolice/app/service"
"ArmedPolice/config"
cache2 "ArmedPolice/serve/cache"
"ArmedPolice/utils"
"fmt"
"net/http"
"time"
"github.com/gin-gonic/gin"
"net/http"
)
// SkipperURL 跳过验证
@ -40,34 +36,10 @@ func NeedLogin(skipperURL ...SkipperURL) gin.HandlerFunc {
c.Abort()
return
}
tokenInfo := utils.JWTDecrypt(token)
session, err := service.NewAuthToken(token).Auth()
if tokenInfo == nil || len(tokenInfo) <= 0 {
c.JSON(http.StatusUnauthorized, gin.H{"message": "Token无效"})
c.Abort()
return
}
expTimestamp := utils.StringToInt64(fmt.Sprintf("%v", tokenInfo["exp"]))
expTime := time.Unix(expTimestamp, 0)
ok := expTime.After(time.Now())
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"message": "Token过期"})
c.Abort()
return
}
cache, _ := cache2.Cache.HGet(config.RedisKeyForAccount, fmt.Sprintf("%v", tokenInfo[config.TokenForUID]))
if cache == "" {
c.JSON(http.StatusUnauthorized, gin.H{"message": "用户未登录或已退出"})
c.Abort()
return
}
session := new(service.Session)
_ = session.UnmarshalBinary([]byte(cache))
if !config.SettingInfo.MultipleLogin && session.Token != token {
c.JSON(http.StatusUnauthorized, gin.H{"message": "登录失效,已在其他地方登录!"})
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"message": err.Error()})
c.Abort()
return
}

View File

@ -46,8 +46,9 @@ func (this *Router) registerAPI() {
// Websocket socket接口管理
{
_api := new(api.Websocket)
v1.GET("/ws", _api.Ws)
v1.GET("/pong", _api.Pong)
this.handler.GET("/ws", _api.Ws)
this.handler.GET("/pong", _api.Pong)
this.handler.GET("/publish", _api.Publish)
}
// Captcha 验证码接口管理
v1.GET("/captcha", new(api.Captcha).Captcha)
@ -68,6 +69,8 @@ func (this *Router) registerAPI() {
configV1.POST("/edit", _api.Edit)
configV1.GET("/area", _api.Area)
configV1.POST("/breakdown", _api.Breakdown)
configV1.POST("/breakdown/add", _api.BreakdownAdd)
configV1.POST("/breakdown/edit", _api.BreakdownEdit)
}
// Tenant 租户单位管理
tenantV1 := v1.Group("/tenant")