modweb/auth.go

28 lines
592 B
Go
Raw Normal View History

2020-11-11 22:48:11 +00:00
package modweb
import "github.com/gofiber/fiber/v2/middleware/session"
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() string
RegisterURL() string
}
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
}