Created
December 15, 2014 10:24
-
-
Save Ovinatter/e9af689be9c0218a6709 to your computer and use it in GitHub Desktop.
GAE/GOで認証
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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