1package aetest 2 3import ( 4 "hash/crc32" 5 "net/http" 6 "strconv" 7 8 "google.golang.org/appengine/user" 9) 10 11// Login causes the provided Request to act as though issued by the given user. 12func Login(u *user.User, req *http.Request) { 13 req.Header.Set("X-AppEngine-User-Email", u.Email) 14 id := u.ID 15 if id == "" { 16 id = strconv.Itoa(int(crc32.Checksum([]byte(u.Email), crc32.IEEETable))) 17 } 18 req.Header.Set("X-AppEngine-User-Id", id) 19 req.Header.Set("X-AppEngine-User-Federated-Identity", u.Email) 20 req.Header.Set("X-AppEngine-User-Federated-Provider", u.FederatedProvider) 21 if u.Admin { 22 req.Header.Set("X-AppEngine-User-Is-Admin", "1") 23 } else { 24 req.Header.Set("X-AppEngine-User-Is-Admin", "0") 25 } 26} 27 28// Logout causes the provided Request to act as though issued by a logged-out 29// user. 30func Logout(req *http.Request) { 31 req.Header.Del("X-AppEngine-User-Email") 32 req.Header.Del("X-AppEngine-User-Id") 33 req.Header.Del("X-AppEngine-User-Is-Admin") 34 req.Header.Del("X-AppEngine-User-Federated-Identity") 35 req.Header.Del("X-AppEngine-User-Federated-Provider") 36} 37