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

Side by Side Diff: appengine/cmd/milo/settings/settings.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd Created 4 years, 6 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
« no previous file with comments | « appengine/cmd/milo/frontend/milo.go ('k') | appengine/cmd/milo/settings/themes.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package settings 5 package settings
6 6
7 import ( 7 import (
8 "encoding/base64" 8 "encoding/base64"
9 "encoding/json" 9 "encoding/json"
10 "fmt" 10 "fmt"
11 "net/http" 11 "net/http"
12 12
13 "github.com/julienschmidt/httprouter"
14 "github.com/luci/gae/service/datastore" 13 "github.com/luci/gae/service/datastore"
15 "github.com/luci/luci-go/appengine/cmd/milo/model" 14 "github.com/luci/luci-go/appengine/cmd/milo/model"
16 "github.com/luci/luci-go/appengine/cmd/milo/resp" 15 "github.com/luci/luci-go/appengine/cmd/milo/resp"
17 "github.com/luci/luci-go/server/auth" 16 "github.com/luci/luci-go/server/auth"
18 "github.com/luci/luci-go/server/auth/identity" 17 "github.com/luci/luci-go/server/auth/identity"
19 "github.com/luci/luci-go/server/auth/xsrf" 18 "github.com/luci/luci-go/server/auth/xsrf"
19 "github.com/luci/luci-go/server/router"
20 "golang.org/x/net/context" 20 "golang.org/x/net/context"
21 ) 21 )
22 22
23 type updateReq struct { 23 type updateReq struct {
24 Theme string 24 Theme string
25 } 25 }
26 26
27 // GetTheme returns the chosen theme based on the current user. 27 // GetTheme returns the chosen theme based on the current user.
28 func GetTheme(c context.Context, r *http.Request) Theme { 28 func GetTheme(c context.Context, r *http.Request) Theme {
29 cfg := getUserSettings(c) 29 cfg := getUserSettings(c)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 err = json.Unmarshal([]byte(s), &config) 69 err = json.Unmarshal([]byte(s), &config)
70 if err != nil { 70 if err != nil {
71 panic(err) 71 panic(err)
72 } 72 }
73 return &config 73 return &config
74 } 74 }
75 75
76 // ChangeSettings is invoked in a POST request to settings and changes either 76 // ChangeSettings is invoked in a POST request to settings and changes either
77 // the user settings in the datastore, or the cookies if user is anon. 77 // the user settings in the datastore, or the cookies if user is anon.
78 func ChangeSettings(c context.Context, h http.ResponseWriter, r *http.Request, p httprouter.Params) { 78 func ChangeSettings(ctx *router.Context) {
79 » c, h, r := ctx.Context, ctx.Writer, ctx.Request
80
79 // First, check XSRF token. 81 // First, check XSRF token.
80 err := xsrf.Check(c, r.FormValue("xsrf_token")) 82 err := xsrf.Check(c, r.FormValue("xsrf_token"))
81 if err != nil { 83 if err != nil {
82 h.WriteHeader(http.StatusUnauthorized) 84 h.WriteHeader(http.StatusUnauthorized)
83 h.Write([]byte("Failed XSRF check.")) 85 h.Write([]byte("Failed XSRF check."))
84 return 86 return
85 } 87 }
86 88
87 u := &updateReq{ 89 u := &updateReq{
88 Theme: r.FormValue("theme"), 90 Theme: r.FormValue("theme"),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 143
142 result := &resp.Settings{} 144 result := &resp.Settings{}
143 result.ActionURL = r.URL.String() 145 result.ActionURL = r.URL.String()
144 result.Theme = &resp.Choices{ 146 result.Theme = &resp.Choices{
145 Choices: GetAllThemes(), 147 Choices: GetAllThemes(),
146 Selected: userSettings.Theme, 148 Selected: userSettings.Theme,
147 } 149 }
148 150
149 return result, nil 151 return result, nil
150 } 152 }
OLDNEW
« no previous file with comments | « appengine/cmd/milo/frontend/milo.go ('k') | appengine/cmd/milo/settings/themes.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698