38 lines
596 B
Go
38 lines
596 B
Go
|
package auth
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"git.tek.govt.hu/dowerx/szoe-pontok/database/auth"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
func LoggedIn(c *gin.Context) {
|
||
|
token, err := c.Cookie("token")
|
||
|
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusUnauthorized, gin.H{
|
||
|
"status": http.StatusUnauthorized,
|
||
|
"error": "missing token",
|
||
|
})
|
||
|
c.Abort()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
neptun, err := auth.LoggedIn(token)
|
||
|
if err != nil {
|
||
|
c.JSON(http.StatusUnauthorized, gin.H{
|
||
|
"status": http.StatusUnauthorized,
|
||
|
"error": "not logged in",
|
||
|
})
|
||
|
c.Abort()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.Set("neptun", neptun)
|
||
|
}
|
||
|
|
||
|
func IsAdmin(c *gin.Context) {
|
||
|
|
||
|
}
|