feat(login):基本完成用户登录,待测。

This commit is contained in:
徐涛
2022-08-12 06:32:25 +08:00
parent 8f4e0320fd
commit 1c5bcf033b
8 changed files with 265 additions and 0 deletions

23
router/security.go Normal file
View File

@@ -0,0 +1,23 @@
package router
import (
"electricity_bill_calc/cache"
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
func AuthenticatedSession(c *gin.Context) {
auth := c.Request.Header.Get("Authorization")
if len(auth) > 0 {
token := strings.Fields(auth)[1]
session, err := cache.RetreiveSession(token)
if err != nil {
c.AbortWithStatus(http.StatusForbidden)
}
c.Set("session", session)
}
c.Next()
}