mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-08-21 10:43:49 +02:00
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
![]() |
package server
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func (s *Server) ensureWebEnabled(next handleFunc) handleFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request, v *visitor) error {
|
||
|
if !s.config.EnableWeb {
|
||
|
return errHTTPNotFound
|
||
|
}
|
||
|
return next(w, r, v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *Server) ensureUserManager(next handleFunc) handleFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request, v *visitor) error {
|
||
|
if s.userManager == nil {
|
||
|
return errHTTPNotFound
|
||
|
}
|
||
|
return next(w, r, v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *Server) ensureUser(next handleFunc) handleFunc {
|
||
|
return s.ensureUserManager(func(w http.ResponseWriter, r *http.Request, v *visitor) error {
|
||
|
if v.user == nil {
|
||
|
return errHTTPUnauthorized
|
||
|
}
|
||
|
return next(w, r, v)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func (s *Server) ensurePaymentsEnabled(next handleFunc) handleFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request, v *visitor) error {
|
||
|
if !s.config.EnablePayments {
|
||
|
return errHTTPNotFound
|
||
|
}
|
||
|
return next(w, r, v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *Server) ensureStripeCustomer(next handleFunc) handleFunc {
|
||
|
return s.ensureUser(func(w http.ResponseWriter, r *http.Request, v *visitor) error {
|
||
|
if v.user.Billing.StripeCustomerID == "" {
|
||
|
return errHTTPBadRequestNotAPaidUser
|
||
|
}
|
||
|
return next(w, r, v)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func (s *Server) withAccountSync(next handleFunc) handleFunc {
|
||
|
return func(w http.ResponseWriter, r *http.Request, v *visitor) error {
|
||
|
if v.user == nil {
|
||
|
return next(w, r, v)
|
||
|
}
|
||
|
err := next(w, r, v)
|
||
|
if err == nil {
|
||
|
s.publishSyncEventAsync(v)
|
||
|
}
|
||
|
return err
|
||
|
}
|
||
|
}
|