Config: Add public flag to disable auth #16

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer
2019-11-11 21:10:41 +01:00
parent 56c97ec057
commit a14b74dfa6
15 changed files with 78 additions and 23 deletions

View File

@@ -55,3 +55,17 @@ func DeleteSession(router *gin.RouterGroup, conf *config.Config) {
c.JSON(http.StatusOK, gin.H{"status": "ok", "token": token})
})
}
// Returns true, if user doesn't have a valid session token
func Unauthorized(c *gin.Context, conf *config.Config) bool {
if conf.Public() {
return false
}
token := c.GetHeader("X-Session-Token")
gc := conf.Cache()
_, found := gc.Get(token)
return found
}