99
1010 "github.com/go-zoo/bone"
1111 "github.com/nerdynz/datastore"
12- flow "github.com/nerdynz/flow"
12+ "github.com/nerdynz/flow"
1313 "github.com/nerdynz/security"
1414 "github.com/nerdynz/view"
1515 "github.com/unrolled/render"
@@ -22,10 +22,10 @@ type CustomRouter struct {
2222 Renderer * render.Render
2323 Key security.Key
2424 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 )
2626}
2727
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 )
2929
3030func New (renderer * render.Render , s * datastore.Datastore , key security.Key ) * CustomRouter {
3131 customRouter := & CustomRouter {}
@@ -39,7 +39,7 @@ func New(renderer *render.Render, s *datastore.Datastore, key security.Key) *Cus
3939 return customRouter
4040}
4141
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 {
4343 customRouter := New (renderer , s , key )
4444 customRouter .AuthHandler = authFn
4545 return customRouter
@@ -112,10 +112,10 @@ func (customRouter *CustomRouter) handler(reqType string, fn CustomHandlerFunc,
112112// }, authMethod)
113113// }
114114
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 ) {
116116 // 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
119119 root := strings .ToLower (req .Host )
120120 if ! strings .HasSuffix (root , "/" ) {
121121 root += "/"
@@ -127,7 +127,7 @@ func authenticate(w http.ResponseWriter, req *http.Request, ctx *flow.Context, s
127127 // logrus.Info("root", canonical)
128128 if canonical != root {
129129 redirectURL := "http://"
130- if ctx .Settings .GetBool ("IS_HTTPS" ) {
130+ if store .Settings .GetBool ("IS_HTTPS" ) {
131131 redirectURL = "https://"
132132 }
133133 redirectURL += strings .TrimRight (canonical , "/" )
@@ -150,35 +150,35 @@ func authenticate(w http.ResponseWriter, req *http.Request, ctx *flow.Context, s
150150 }
151151
152152 if authMethod == security .NoAuth {
153- fn (w , req , ctx , store )
153+ fn (w , req , flw , store )
154154 return
155155 }
156156
157157 // if we are at this point then we want a login
158- loggedInUser , _ , err := ctx .Padlock .LoggedInUser ()
158+ loggedInUser , _ , err := flw .Padlock .LoggedInUser ()
159159 if err != nil {
160160 if err .Error () == "redis: nil" {
161161 // ignore it, its expired from cache
162- ctx .ErrorJSON (http .StatusForbidden , "Login Expired" , err )
162+ flw .ErrorJSON (http .StatusForbidden , "Login Expired" , err )
163163 } else {
164- ctx .ErrorJSON (http .StatusForbidden , "Auth Failure" , err )
164+ flw .ErrorJSON (http .StatusForbidden , "Auth Failure" , err )
165165 }
166166 return
167167 }
168168
169169 if loggedInUser != nil {
170- fn (w , req , ctx , store )
170+ fn (w , req , flw , store )
171171 return
172172 }
173173
174174 // if we have reached this point then the user doesn't have access
175175 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 )
177177 return
178178
179179 }
180180 if authMethod == security .Redirect {
181- ctx .Redirect ("/Login" , http .StatusSeeOther )
181+ flw .Redirect ("/Login" , http .StatusSeeOther )
182182 }
183183}
184184
0 commit comments