Skip to content

Instantly share code, notes, and snippets.

@Ovinatter
Created December 15, 2014 10:24
Show Gist options
  • Save Ovinatter/e9af689be9c0218a6709 to your computer and use it in GitHub Desktop.
Save Ovinatter/e9af689be9c0218a6709 to your computer and use it in GitHub Desktop.
GAE/GOで認証
func Handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
u := user.Current(c)
//ログインのチェック
if u == nil {
url, err := user.LoginURL(c, r.URL.String())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Location", url)
w.WriteHeader(http.StatusFound)
return
}
//管理者チェツク
if !user.IsAdmin(c){
c.Infof("管理者ではない %v", u.Email)
fmt.Fprintf(w, "管理者じゃない, %v", "")
return
}
id := u.ID
fmt.Fprintf(w, "ログイン完了した, %v!", id)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment