-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
LoadUserMiddleware.py
35 lines (26 loc) · 1017 Bytes
/
LoadUserMiddleware.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Load User Middleware."""
from masonite.auth import Auth
from masonite.request import Request
class LoadUserMiddleware:
"""Middleware class which loads the current user into the request."""
def __init__(self, request: Request, auth: Auth):
"""Inject Any Dependencies From The Service Container.
Arguments:
request {masonite.request.Request} -- The Masonite request object.
auth {masonite.auth.Auth} -- The Masonite authentication object.
"""
self.request = request
self.auth = auth
def before(self):
"""Run This Middleware Before The Route Executes."""
self.load_user()
return self.request
def after(self):
"""Run This Middleware After The Route Executes."""
pass
def load_user(self):
"""Load user into the request.
Arguments:
request {masonite.request.Request} -- The Masonite request object.
"""
self.request.set_user(self.auth.user())