-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
''' Load User Middleware''' | ||
|
||
|
||
class AddAttributeMiddleware: | ||
''' Middleware class which loads the current user into the request ''' | ||
|
||
def __init__(self, Request): | ||
''' Inject Any Dependencies From The Service Container ''' | ||
self.request = Request | ||
|
||
def before(self): | ||
''' Run This Middleware Before The Route Executes ''' | ||
self.request.attribute = True | ||
|
||
def after(self): | ||
''' Run This Middleware After The Route Executes ''' | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
''' Load User Middleware''' | ||
|
||
|
||
class MiddlewareTest: | ||
''' Middleware class which loads the current user into the request ''' | ||
|
||
def __init__(self, Request): | ||
''' Inject Any Dependencies From The Service Container ''' | ||
self.request = Request | ||
|
||
def before(self): | ||
''' Run This Middleware Before The Route Executes ''' | ||
self.request.path = 'test/middleware/before/ran' | ||
|
||
def after(self): | ||
''' Run This Middleware After The Route Executes ''' | ||
pass | ||
|
||
def load_user(self, request): | ||
''' Load user into the request ''' | ||
request.set_user(Auth(request).user()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
ROUTE_MIDDLEWARE = {} | ||
ROUTE_MIDDLEWARE = { | ||
'test': 'app.http.middleware.MiddlewareTest.MiddlewareTest', | ||
'middleware.test': [ | ||
'app.http.middleware.MiddlewareTest.MiddlewareTest', | ||
'app.http.middleware.AddAttributeMiddleware.AddAttributeMiddleware' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters