Files
boringproxy/auth.go

34 lines
496 B
Go
Raw Normal View History

package boringproxy
2020-09-28 22:46:35 -06:00
import (
2020-09-29 20:12:54 -06:00
"sync"
2020-09-28 22:46:35 -06:00
)
type Auth struct {
db *Database
pendingRequests map[string]*LoginRequest
2020-09-29 20:12:54 -06:00
mutex *sync.Mutex
2020-09-28 22:46:35 -06:00
}
type LoginRequest struct {
2020-10-02 17:09:14 -06:00
Email string
}
func NewAuth(db *Database) *Auth {
2020-09-28 22:46:35 -06:00
pendingRequests := make(map[string]*LoginRequest)
2020-09-29 20:12:54 -06:00
mutex := &sync.Mutex{}
2020-09-28 22:46:35 -06:00
return &Auth{db, pendingRequests, mutex}
2020-09-28 22:46:35 -06:00
}
func (a *Auth) Authorized(token string) bool {
2020-10-11 14:27:32 -06:00
_, exists := a.db.GetTokenData(token)
2020-09-28 22:46:35 -06:00
2020-09-29 20:12:54 -06:00
if exists {
return true
}
2020-09-28 22:46:35 -06:00
2020-09-29 20:12:54 -06:00
return false
2020-09-28 22:46:35 -06:00
}