2021-09-20 05:06:26 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2022-01-17 06:02:13 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/db"
|
|
|
|
"github.com/gin-gonic/gin"
|
2021-09-20 05:06:26 +00:00
|
|
|
)
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
// StringSliceContains checks if a string slice contains a particular string
|
2021-10-19 07:27:59 +00:00
|
|
|
func StringSliceContains(s []string, e string) bool {
|
2021-10-13 16:41:41 +00:00
|
|
|
for _, a := range s {
|
|
|
|
if a == e {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-01-17 06:02:13 +00:00
|
|
|
|
|
|
|
// SaveSessionInDB saves sessions generated for a given user with meta information
|
|
|
|
// Not store token here as that could be security breach
|
|
|
|
func SaveSessionInDB(userId string, c *gin.Context) {
|
|
|
|
sessionData := db.Session{
|
|
|
|
UserID: userId,
|
|
|
|
UserAgent: GetUserAgent(c.Request),
|
|
|
|
IP: GetIP(c.Request),
|
|
|
|
}
|
|
|
|
|
|
|
|
db.Mgr.AddSession(sessionData)
|
|
|
|
}
|