2016-08-22 15:17:13 -07:00
|
|
|
package chipmunk
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
2017-01-20 14:22:01 -08:00
|
|
|
var authEmails []string = []string{"derekmcquay@gmail.com", "colleenmmcquay@gmail.com"}
|
2016-08-22 15:17:13 -07:00
|
|
|
|
|
|
|
type user struct {
|
|
|
|
Info userInfo `json:"info"`
|
|
|
|
admin bool `json:"admin"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type userInfo struct {
|
|
|
|
Sub string `json:"sub"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
GivenName string `json:"given_name"`
|
|
|
|
FamilyName string `json:"family_name"`
|
|
|
|
Profile string `json:"profile"`
|
|
|
|
Picture string `json:"picture"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
EmailVerified bool `json:"email_verified"`
|
|
|
|
}
|
|
|
|
|
2016-08-23 09:44:08 -07:00
|
|
|
//authorizedEmail checks whether the email coming in is in the preapproved list
|
2016-08-22 15:17:13 -07:00
|
|
|
func authorizedEmail(e string) bool {
|
|
|
|
b := false
|
|
|
|
for _, i := range authEmails {
|
|
|
|
if i == e {
|
|
|
|
b = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2016-08-22 21:00:39 -07:00
|
|
|
// getUser returns index of user with given email, otherwise it returns an
|
|
|
|
// error that it could not find that user
|
|
|
|
func getUser(e string) (int, error) {
|
|
|
|
for i, u := range users {
|
|
|
|
if e == u.Info.Email {
|
|
|
|
return i, nil
|
2016-08-22 15:17:13 -07:00
|
|
|
}
|
|
|
|
}
|
2016-08-22 21:00:39 -07:00
|
|
|
return 0, fmt.Errorf("could not find user")
|
2016-08-22 15:17:13 -07:00
|
|
|
}
|
|
|
|
|
2016-08-23 09:44:08 -07:00
|
|
|
//addUser adds user to slice of users
|
2016-08-22 15:17:13 -07:00
|
|
|
func addUser(u userInfo) {
|
2016-08-22 21:08:06 -07:00
|
|
|
_, err := getUser(u.Email)
|
|
|
|
if err != nil {
|
|
|
|
users = append(
|
|
|
|
users,
|
|
|
|
user{
|
|
|
|
Info: u,
|
|
|
|
admin: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2016-08-22 15:17:13 -07:00
|
|
|
}
|