forked from free-lancers/electricity_bill_calc_service
		
	feat(login):基本完成用户登录,待测。
This commit is contained in:
		
							
								
								
									
										23
									
								
								router/security.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								router/security.go
									
									
									
									
									
										Normal 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() | ||||
| } | ||||
		Reference in New Issue
	
	Block a user