You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package Handler
import (
"dsSdsf/Utils/RedisUtil"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
func LoginHandler ( ) gin . HandlerFunc {
return func ( c * gin . Context ) {
requestUri := c . Request . RequestURI
if strings . Index ( requestUri , "/sdsf/login/test1" ) >= 0 {
//放行~
c . Next ( )
return
}
//是否需要登录, 默认为true需要登录
needLoginFlag := true
//获取cookie中的token
cookieToken , _ := c . Request . Cookie ( "token" )
if cookieToken != nil {
_ , error := RedisUtil . GET ( cookieToken . Value )
if error == nil {
needLoginFlag = false
}
}
if needLoginFlag {
c . Redirect ( http . StatusMovedPermanently , "/sdsf/login/test1?redirect_uri=" + requestUri )
} else {
//将redis中的token有效期重置
RedisUtil . EXPIRE ( cookieToken . Value , 1800 )
c . Next ( )
return
}
}
}