Files
boringproxy/auth.go
Anders Pitman 5cd911f310 Automatically create admin user on first start
Also changed order that extractToken looks for tokens. Used to
be cookies then headers then query. Now in reverse, to make it
easier to override, ie for replacing cookies during login.
2020-10-13 09:48:03 -06:00

34 lines
489 B
Go

package main
import (
"sync"
)
type Auth struct {
db *Database
pendingRequests map[string]*LoginRequest
mutex *sync.Mutex
}
type LoginRequest struct {
Email string
}
func NewAuth(db *Database) *Auth {
pendingRequests := make(map[string]*LoginRequest)
mutex := &sync.Mutex{}
return &Auth{db, pendingRequests, mutex}
}
func (a *Auth) Authorized(token string) bool {
_, exists := a.db.GetTokenData(token)
if exists {
return true
}
return false
}