mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 09:15:33 +00:00
Registration form for new users
This commit is contained in:
26
middleware/accesstoken.go
Normal file
26
middleware/accesstoken.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func HasToken() func(*core.RequestEvent) error {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
token := req.AccessToken()
|
||||
if token == nil {
|
||||
return e.Error(401, "Unauthorized", nil)
|
||||
}
|
||||
|
||||
if token.IsExpired() {
|
||||
return e.Error(403, "Forbidden", nil)
|
||||
}
|
||||
|
||||
if token.URL != e.Request.URL.Path {
|
||||
return e.Error(403, "Forbidden", nil)
|
||||
}
|
||||
|
||||
return e.Next()
|
||||
}
|
||||
}
|
||||
22
middleware/admin.go
Normal file
22
middleware/admin.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func IsAdmin() func(*core.RequestEvent) error {
|
||||
return func(e *core.RequestEvent) error {
|
||||
req := templating.NewRequest(e)
|
||||
user := req.User()
|
||||
if user == nil {
|
||||
return e.Error(401, "Unauthorized", nil)
|
||||
}
|
||||
|
||||
if user.Role != "Admin" {
|
||||
return e.Error(403, "Forbidden", nil)
|
||||
}
|
||||
|
||||
return e.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user