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

Side by Side Diff: appengine/chromium_build_stats/default/ninja_log.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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package chromiumbuildstats 5 package chromiumbuildstats
6 6
7 // ninja_log.go provides /ninja_log endpoints. 7 // ninja_log.go provides /ninja_log endpoints.
8 8
9 import ( 9 import (
10 "bufio" 10 "bufio"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 } 158 }
159 159
160 func ninjalogForm(w http.ResponseWriter, req *http.Request) { 160 func ninjalogForm(w http.ResponseWriter, req *http.Request) {
161 if req.Method == "POST" { 161 if req.Method == "POST" {
162 ninjalogUpload(w, req) 162 ninjalogUpload(w, req)
163 return 163 return
164 } 164 }
165 ctx := appengine.NewContext(req) 165 ctx := appengine.NewContext(req)
166 u := user.Current(ctx) 166 u := user.Current(ctx)
167 » login, err := user.LoginURL(ctx, "/ninja_log/") 167 » authPage(w, req, http.StatusOK, formTmpl, u, "/ninja_log/")
168 » if err != nil {
169 » » http.Error(w, err.Error(), http.StatusInternalServerError)
170 » » return
171 » }
172 » logout, err := user.LogoutURL(ctx, "/ninja_log/")
173 » if err != nil {
174 » » http.Error(w, err.Error(), http.StatusInternalServerError)
175 » » return
176 » }
177 » w.Header().Set("Content-Type", "text/html")
178 » w.WriteHeader(http.StatusOK)
179 » data := struct {
180 » » User *user.User
181 » » Login string
182 » » Logout string
183 » }{
184 » » User: u,
185 » » Login: login,
186 » » Logout: logout,
187 » }
188 » err = formTmpl.Execute(w, data)
189 » if err != nil {
190 » » ctx.Errorf("formTmpl: %v", err)
191 » }
192
193 } 168 }
194 169
195 func ninjalogUpload(w http.ResponseWriter, req *http.Request) { 170 func ninjalogUpload(w http.ResponseWriter, req *http.Request) {
196 ctx := appengine.NewContext(req) 171 ctx := appengine.NewContext(req)
197 u := user.Current(ctx) 172 u := user.Current(ctx)
198 if u == nil { 173 if u == nil {
199 http.Error(w, "unauthorized", http.StatusUnauthorized) 174 http.Error(w, "unauthorized", http.StatusUnauthorized)
200 return 175 return
201 } 176 }
202 // TODO(ukai): allow only @google.com and @chromium.org? 177 // TODO(ukai): allow only @google.com and @chromium.org?
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 traces := ninjalog.ToTraces(flow, 1) 301 traces := ninjalog.ToTraces(flow, 1)
327 b, err := traceViewerTmpl.HTML(logPath, traces) 302 b, err := traceViewerTmpl.HTML(logPath, traces)
328 if err != nil { 303 if err != nil {
329 return err 304 return err
330 } 305 }
331 w.Header().Set("Content-Type", "text/html; charset=utf-8") 306 w.Header().Set("Content-Type", "text/html; charset=utf-8")
332 w.WriteHeader(http.StatusOK) 307 w.WriteHeader(http.StatusOK)
333 _, err = w.Write(b) 308 _, err = w.Write(b)
334 return err 309 return err
335 } 310 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698