-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.go
59 lines (53 loc) · 1.22 KB
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"fmt"
"google.golang.org/appengine/datastore"
"google.golang.org/appengine/log"
"google.golang.org/appengine/user"
"os"
"strings"
)
type appuser struct {
Email string
IsAdmin bool
//multi-conference support?
}
func userauthenticated(c context.Context) bool {
u := user.Current(c)
return u != nil
}
func userauthorized(c context.Context, email string) (bool, error) {
if v := os.Getenv("BOOTSTRAP_USER"); v != "" && v == email {
return true, nil
}
lc := strings.ToLower(email)
q := datastore.NewQuery("SVDPUser").Filter("Email=", lc)
cnt, err := q.Count(c)
log.Debugf(c, "count for user %v = %v", lc, cnt)
if err != nil {
return false, err
}
if cnt > 0 {
return true, nil
}
return false, nil
}
func useradmin(c context.Context, email string) (bool, error) {
if v := os.Getenv("BOOTSTRAP_USER"); v != "" && v == email {
// bootstrap user is admin by definition
return true, nil
}
u := []appuser{}
q := datastore.NewQuery("SVDPUser").Filter("Email=", email)
_, err := q.GetAll(c, &u)
log.Debugf(c, "user %v", u)
if err != nil {
return false, err
}
if len(u) == 0 {
return false, fmt.Errorf("no user with email %v found",
email)
}
return u[0].IsAdmin, nil
}