9
9
10
10
"github.com/go-zoo/bone"
11
11
"github.com/nerdynz/datastore"
12
- flow "github.com/nerdynz/flow"
12
+ "github.com/nerdynz/flow"
13
13
"github.com/nerdynz/security"
14
14
"github.com/nerdynz/view"
15
15
"github.com/unrolled/render"
@@ -22,10 +22,10 @@ type CustomRouter struct {
22
22
Renderer * render.Render
23
23
Key security.Key
24
24
Store * datastore.Datastore
25
- AuthHandler func (w http.ResponseWriter , req * http.Request , ctx * flow.Context , store * datastore.Datastore , fn CustomHandlerFunc , authMethod string )
25
+ AuthHandler func (w http.ResponseWriter , req * http.Request , flw * flow.Flow , store * datastore.Datastore , fn CustomHandlerFunc , authMethod string )
26
26
}
27
27
28
- type CustomHandlerFunc func (w http.ResponseWriter , req * http.Request , ctx * flow.Context , store * datastore.Datastore )
28
+ type CustomHandlerFunc func (w http.ResponseWriter , req * http.Request , flw * flow.Flow , store * datastore.Datastore )
29
29
30
30
func New (renderer * render.Render , s * datastore.Datastore , key security.Key ) * CustomRouter {
31
31
customRouter := & CustomRouter {}
@@ -39,7 +39,7 @@ func New(renderer *render.Render, s *datastore.Datastore, key security.Key) *Cus
39
39
return customRouter
40
40
}
41
41
42
- func CustomAuth (renderer * render.Render , s * datastore.Datastore , key security.Key , authFn func (w http.ResponseWriter , req * http.Request , ctx * flow.Context , store * datastore.Datastore , fn CustomHandlerFunc , authMethod string )) * CustomRouter {
42
+ func CustomAuth (renderer * render.Render , s * datastore.Datastore , key security.Key , authFn func (w http.ResponseWriter , req * http.Request , flw * flow.Flow , store * datastore.Datastore , fn CustomHandlerFunc , authMethod string )) * CustomRouter {
43
43
customRouter := New (renderer , s , key )
44
44
customRouter .AuthHandler = authFn
45
45
return customRouter
@@ -112,10 +112,10 @@ func (customRouter *CustomRouter) handler(reqType string, fn CustomHandlerFunc,
112
112
// }, authMethod)
113
113
// }
114
114
115
- func authenticate (w http.ResponseWriter , req * http.Request , ctx * flow.Context , store * datastore.Datastore , fn CustomHandlerFunc , authMethod string ) {
115
+ func authenticate (w http.ResponseWriter , req * http.Request , flw * flow.Flow , store * datastore.Datastore , fn CustomHandlerFunc , authMethod string ) {
116
116
// canonical host
117
- canonical := ctx .Settings .Get ("CANNONICAL_URL" )
118
- if canonical != "" && ctx .Settings .IsProduction () { // set in ENV
117
+ canonical := store .Settings .Get ("CANNONICAL_URL" )
118
+ if canonical != "" && store .Settings .IsProduction () { // set in ENV
119
119
root := strings .ToLower (req .Host )
120
120
if ! strings .HasSuffix (root , "/" ) {
121
121
root += "/"
@@ -127,7 +127,7 @@ func authenticate(w http.ResponseWriter, req *http.Request, ctx *flow.Context, s
127
127
// logrus.Info("root", canonical)
128
128
if canonical != root {
129
129
redirectURL := "http://"
130
- if ctx .Settings .GetBool ("IS_HTTPS" ) {
130
+ if store .Settings .GetBool ("IS_HTTPS" ) {
131
131
redirectURL = "https://"
132
132
}
133
133
redirectURL += strings .TrimRight (canonical , "/" )
@@ -150,35 +150,35 @@ func authenticate(w http.ResponseWriter, req *http.Request, ctx *flow.Context, s
150
150
}
151
151
152
152
if authMethod == security .NoAuth {
153
- fn (w , req , ctx , store )
153
+ fn (w , req , flw , store )
154
154
return
155
155
}
156
156
157
157
// if we are at this point then we want a login
158
- loggedInUser , _ , err := ctx .Padlock .LoggedInUser ()
158
+ loggedInUser , _ , err := flw .Padlock .LoggedInUser ()
159
159
if err != nil {
160
160
if err .Error () == "redis: nil" {
161
161
// ignore it, its expired from cache
162
- ctx .ErrorJSON (http .StatusForbidden , "Login Expired" , err )
162
+ flw .ErrorJSON (http .StatusForbidden , "Login Expired" , err )
163
163
} else {
164
- ctx .ErrorJSON (http .StatusForbidden , "Auth Failure" , err )
164
+ flw .ErrorJSON (http .StatusForbidden , "Auth Failure" , err )
165
165
}
166
166
return
167
167
}
168
168
169
169
if loggedInUser != nil {
170
- fn (w , req , ctx , store )
170
+ fn (w , req , flw , store )
171
171
return
172
172
}
173
173
174
174
// if we have reached this point then the user doesn't have access
175
175
if authMethod == security .Disallow {
176
- ctx .ErrorJSON (http .StatusForbidden , "You're not currently logged in" , err )
176
+ flw .ErrorJSON (http .StatusForbidden , "You're not currently logged in" , err )
177
177
return
178
178
179
179
}
180
180
if authMethod == security .Redirect {
181
- ctx .Redirect ("/Login" , http .StatusSeeOther )
181
+ flw .Redirect ("/Login" , http .StatusSeeOther )
182
182
}
183
183
}
184
184
0 commit comments