Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5419)

Unified Diff: appengine/chromium_build_stats/default/auth.go

Issue 2125513002: chromium_build_stats: redirect login url if not logged in. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/chromium_build_stats/default/auth.go
diff --git a/appengine/chromium_build_stats/default/auth.go b/appengine/chromium_build_stats/default/auth.go
new file mode 100644
index 0000000000000000000000000000000000000000..d1e71c5fdf461df48c908fe9f03f1b45da787a8b
--- /dev/null
+++ b/appengine/chromium_build_stats/default/auth.go
@@ -0,0 +1,38 @@
+package chromiumbuildstats
+
+import (
+ "html/template"
+ "net/http"
+
+ "appengine"
+ "appengine/user"
+)
+
+func authPage(w http.ResponseWriter, req *http.Request, status int, tmpl *template.Template, u *user.User, reqpath string) {
+ ctx := appengine.NewContext(req)
+ login, err := user.LoginURL(ctx, reqpath)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ logout, err := user.LogoutURL(ctx, reqpath)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ w.Header().Set("Content-Type", "text/html")
+ w.WriteHeader(status)
+ data := struct {
+ User *user.User
+ Login string
+ Logout string
+ }{
+ User: u,
+ Login: login,
+ Logout: logout,
+ }
+ err = tmpl.Execute(w, data)
+ if err != nil {
+ ctx.Errorf("tmpl: %v", err)
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698