/
user.go
40 lines (33 loc) · 915 Bytes
/
user.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
package isumm
import (
"html/template"
"net/http"
"os"
"appengine"
"appengine/user"
)
func IsUserAllowed(u *user.User) bool {
if os.Getenv("RUN_WITH_DEVAPPSERVER") == "1" {
_, ok := AllowedTestUsers[u.Email]
return ok
}
_, ok := AllowedUsers[u.Email]
return ok
}
var notAllowedTemplate = template.Must(template.ParseFiles("static/not_allowed.template.html"))
type notAllowedParams struct {
User string
LogoutURL string
}
func InvalidUserPage(c appengine.Context, w http.ResponseWriter, r *http.Request, u *user.User) {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusForbidden)
logoutUrl, err := LogoutURL(c, r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := notAllowedTemplate.Execute(w, notAllowedParams{u.String(), logoutUrl}); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}