Skip to content

Commit ee89a4c

Browse files
Merge pull request #83 from MasoniteFramework/develop
Masonite 1.4
2 parents e9889fc + 384dda5 commit ee89a4c

12 files changed

+139
-17
lines changed
+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
''' Welcome The User To Masonite '''
22

3-
from masonite.request import Request
4-
5-
class WelcomeController(object):
3+
class WelcomeController:
64
''' Controller For Welcoming The User '''
75

8-
def show(self, Application, request: Request):
6+
def show(self, Application):
97
''' Show Welcome Template '''
108
return view('welcome', {'app': Application})

app/http/middleware/AuthenticationMiddleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
''' Authentication Middleware '''
22

3-
class AuthenticationMiddleware(object):
3+
class AuthenticationMiddleware:
44
''' Middleware To Check If The User Is Logged In '''
55

66
def __init__(self, Request):

app/http/middleware/CsrfMiddleware.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
''' CSRF Middleware '''
2+
3+
from masonite.exceptions import InvalidCSRFToken
4+
5+
6+
class CsrfMiddleware:
7+
''' Verify CSRF Token Middleware '''
8+
9+
exempt = []
10+
11+
def __init__(self, Request, Csrf, ViewClass):
12+
self.request = Request
13+
self.csrf = Csrf
14+
self.view = ViewClass
15+
16+
def before(self):
17+
token = self.__verify_csrf_token()
18+
19+
self.view.share({
20+
'csrf_field': "<input type='hidden' name='csrf_token' value='{0}' />".format(token)
21+
})
22+
23+
def after(self):
24+
pass
25+
26+
def __in_exempt(self):
27+
"""
28+
Determine if the request has a URI that should pass
29+
through CSRF verification.
30+
"""
31+
32+
if self.request.path in self.exempt:
33+
return True
34+
else:
35+
return False
36+
37+
def __verify_csrf_token(self):
38+
"""
39+
Verify si csrf token in post is valid.
40+
"""
41+
42+
if self.request.is_post() and not self.__in_exempt():
43+
token = self.request.input('csrf_token')
44+
if not self.csrf.verify_csrf_token(token):
45+
raise InvalidCSRFToken("Invalid CSRF token.")
46+
else:
47+
token = self.csrf.generate_csrf_token()
48+
49+
return token

app/http/middleware/LoadUserMiddleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
''' Load User Middleware'''
22
from masonite.facades.Auth import Auth
33

4-
class LoadUserMiddleware(object):
4+
class LoadUserMiddleware:
55
''' Middleware class which loads the current user into the request '''
66

77
def __init__(self, Request):

bootstrap/cache/.gitignore

Whitespace-only changes.

config/application.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
|
1414
'''
1515

16-
NAME = 'Masonite 1.3'
16+
NAME = 'Masonite 1.4'
1717

1818
'''
1919
|--------------------------------------------------------------------------
@@ -79,6 +79,9 @@
7979
'masonite.providers.ViewProvider.ViewProvider',
8080
'masonite.providers.HelpersProvider.HelpersProvider',
8181
'masonite.providers.QueueProvider.QueueProvider',
82+
'masonite.providers.BroadcastProvider.BroadcastProvider',
83+
'masonite.providers.CacheProvider.CacheProvider',
84+
'masonite.providers.CsrfProvider.CsrfProvider',
8285

8386
# Third Party Providers
8487

config/broadcast.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
''' Broadcast Settings '''
2+
3+
import os
4+
5+
'''
6+
|--------------------------------------------------------------------------
7+
| Broadcast Driver
8+
|--------------------------------------------------------------------------
9+
|
10+
| Realtime support is critical for any modern web application. Broadcast
11+
| drivers allow you to push data from your server to all your clients
12+
| to show data updates to your clients in real time without having
13+
| to constantly refresh the page or send constant ajax requests
14+
|
15+
| Supported: 'pusher', 'ably'
16+
|
17+
'''
18+
19+
DRIVER = os.getenv('BROADCAST_DRIVER', 'pusher')
20+
21+
'''
22+
|--------------------------------------------------------------------------
23+
| Broadcast Drivers
24+
|--------------------------------------------------------------------------
25+
|
26+
| Below is a dictionary of all your driver configurations. Each key in the
27+
| dictionary should be the name of a driver.
28+
|
29+
'''
30+
31+
DRIVERS = {
32+
'pusher': {
33+
'app_id': os.getenv('PUSHER_APP_ID', '29382xx..'),
34+
'client': os.getenv('PUSHER_CLIENT', 'shS8dxx..'),
35+
'secret': os.getenv('PUSHER_SECRET', 'HDGdjss..'),
36+
},
37+
'ably': {
38+
'secret': os.getenv('ABLY_SECRET', 'api:key')
39+
}
40+
}

config/cache.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
''' Cache Settings '''
2+
3+
'''
4+
|--------------------------------------------------------------------------
5+
| Cache Driver
6+
|--------------------------------------------------------------------------
7+
|
8+
| Caching is a great way to gain an instant speed boost to your application.
9+
| Very often templates will not change and you can utilize caching to the
10+
| best by caching your templates forever, monthly or every few seconds
11+
|
12+
| Supported: 'disk'
13+
|
14+
'''
15+
16+
DRIVER = 'disk'
17+
18+
'''
19+
|--------------------------------------------------------------------------
20+
| Cache Drivers
21+
|--------------------------------------------------------------------------
22+
|
23+
| Place all your caching coniguration as a dictionary here. The keys here
24+
| should correspond to the driver types supported above.
25+
|
26+
'''
27+
28+
DRIVERS = {
29+
'disk': {
30+
'location': 'bootstrap/cache'
31+
}
32+
}

config/database.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
|
2929
'''
3030

31-
databases = {
32-
'mysql': {
31+
DATABASES = {
32+
'default': {
3333
'driver': os.environ.get('DB_DRIVER'),
3434
'host': os.environ.get('DB_HOST'),
3535
'database': os.environ.get('DB_DATABASE'),
@@ -39,5 +39,5 @@
3939
}
4040
}
4141

42-
db = DatabaseManager(databases)
43-
Model.set_connection_resolver(db)
42+
DB = DatabaseManager(DATABASES)
43+
Model.set_connection_resolver(DB)

config/middleware.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
'''
1313

1414
HTTP_MIDDLEWARE = [
15-
# 'app.http.middleware.LoadUserMiddleware.LoadUserMiddleware'
15+
'app.http.middleware.LoadUserMiddleware.LoadUserMiddleware',
16+
'app.http.middleware.CsrfMiddleware.CsrfMiddleware',
1617
]
1718

1819
'''

requirements.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ waitress==1.1.0
22
Jinja2==2.10
33
python-dotenv==0.7.1
44
passlib==1.7.1
5-
python-slugify==1.2.4
65
whitenoise==3.3.1
76
bcrypt==3.1.4
87
pytest==3.3.1
98
orator==0.9.7
10-
masonite>=1.3,<=1.3.99
9+
masonite>=1.4,<=1.4.99
1110
cryptography==2.1.4
12-
mysqlclient==1.3.12
13-
psycopg2==2.7.3.2
11+
PyMySQL==0.8.0
12+
psycopg2==2.7.3.2

routes/web.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
from masonite.routes import Get, Post
33

44
ROUTES = [
5-
Get().route('/', 'WelcomeController@show').name('home'),
5+
Get().route('/', 'WelcomeController@show').name('welcome'),
66
]

0 commit comments

Comments
 (0)