2020-11-11 22:48:11 +00:00
|
|
|
package modweb
|
|
|
|
|
2021-01-03 02:57:41 +00:00
|
|
|
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
|
2021-01-03 02:57:41 +00:00
|
|
|
LoginURL() template.URL
|
|
|
|
RegisterURL() template.URL
|
2020-11-16 20:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
ID string
|
|
|
|
DisplayName string
|
|
|
|
AccessLevel int64
|
|
|
|
}
|
|
|
|
|
2020-11-17 16:46:36 +00:00
|
|
|
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
|
|
|
|
2020-11-17 16:46:36 +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
|
|
|
}
|