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