DEVELOPMENT ENVIRONMENT

~liljamo/tixe

ref: c57a862c4977378256899f12648f72534ee68a32 tixe/middlewares/auth.go -rw-r--r-- 457 bytes
c57a862cJonni Liljamo wip: internal users 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package middlewares

import (
	"net/http"

	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
)

func IsAuthenticated(c *gin.Context) {
	if sessions.Default(c).Get("profile") == nil {
		c.Redirect(http.StatusSeeOther, "/login")
	} else {
		c.Next()
	}
}

func CanLogin(c *gin.Context) {
	if sessions.Default(c).Get("profile") != nil {
		// Don't allow the login page if logged in
		c.Redirect(http.StatusSeeOther, "/")
	} else {
		c.Next()
	}
}