boringproxy/auth.go

34 lines
496 B
Go
Raw Normal View History

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