| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |