2020-12-07 21:41:45 -07:00
|
|
|
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 {
|
2020-10-05 23:25:36 -06:00
|
|
|
db *Database
|
2020-09-29 22:03:34 -06:00
|
|
|
pendingRequests map[string]*LoginRequest
|
2020-09-29 20:12:54 -06:00
|
|
|
mutex *sync.Mutex
|
2020-09-28 22:46:35 -06:00
|
|
|
}
|
|
|
|
|
|
2020-09-29 22:03:34 -06:00
|
|
|
type LoginRequest struct {
|
2020-10-02 17:09:14 -06:00
|
|
|
Email string
|
2020-09-29 22:03:34 -06:00
|
|
|
}
|
|
|
|
|
|
2020-10-05 23:25:36 -06:00
|
|
|
func NewAuth(db *Database) *Auth {
|
2020-09-28 22:46:35 -06:00
|
|
|
|
2020-09-29 22:03:34 -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
|
|
|
|
2020-10-05 23:25:36 -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
|
|
|
}
|