modweb/auth.go

31 lines
626 B
Go
Raw Normal View History

2020-11-11 22:48:11 +00:00
package modweb
import (
"github.com/gofiber/fiber/v2/middleware/session"
"html/template"
)
2020-11-16 20:19:37 +00:00
2020-11-11 22:48:11 +00:00
type AuthHandler interface {
2020-11-16 20:19:37 +00:00
Module
LoginURL() template.URL
RegisterURL() template.URL
2020-11-16 20:19:37 +00:00
}
type User struct {
ID string
DisplayName string
AccessLevel int64
}
func (u User) Save(sess *session.Session) {
sess.Set("user:id", u.ID)
sess.Set("user:displayName", u.DisplayName)
sess.Set("user:accessLevel", u.AccessLevel)
2020-11-16 20:19:37 +00:00
}
2020-11-11 22:48:11 +00:00
func (u *User) Load(sess *session.Session) {
u.ID = sess.Get("user:id").(string)
u.DisplayName = sess.Get("user:displayName").(string)
u.AccessLevel = sess.Get("user:accessLevel").(int64)
2020-11-11 22:48:11 +00:00
}