Skip to content

Commit

Permalink
Merge pull request #83 from MasoniteFramework/develop
Browse files Browse the repository at this point in the history
Masonite 1.4
  • Loading branch information
josephmancuso committed Mar 8, 2018
2 parents e9889fc + 384dda5 commit ee89a4c
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 17 deletions.
6 changes: 2 additions & 4 deletions app/http/controllers/WelcomeController.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
''' Welcome The User To Masonite '''

from masonite.request import Request

class WelcomeController(object):
class WelcomeController:
''' Controller For Welcoming The User '''

def show(self, Application, request: Request):
def show(self, Application):
''' Show Welcome Template '''
return view('welcome', {'app': Application})
2 changes: 1 addition & 1 deletion app/http/middleware/AuthenticationMiddleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
''' Authentication Middleware '''

class AuthenticationMiddleware(object):
class AuthenticationMiddleware:
''' Middleware To Check If The User Is Logged In '''

def __init__(self, Request):
Expand Down
49 changes: 49 additions & 0 deletions app/http/middleware/CsrfMiddleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
''' CSRF Middleware '''

from masonite.exceptions import InvalidCSRFToken


class CsrfMiddleware:
''' Verify CSRF Token Middleware '''

exempt = []

def __init__(self, Request, Csrf, ViewClass):
self.request = Request
self.csrf = Csrf
self.view = ViewClass

def before(self):
token = self.__verify_csrf_token()

self.view.share({
'csrf_field': "<input type='hidden' name='csrf_token' value='{0}' />".format(token)
})

def after(self):
pass

def __in_exempt(self):
"""
Determine if the request has a URI that should pass
through CSRF verification.
"""

if self.request.path in self.exempt:
return True
else:
return False

def __verify_csrf_token(self):
"""
Verify si csrf token in post is valid.
"""

if self.request.is_post() and not self.__in_exempt():
token = self.request.input('csrf_token')
if not self.csrf.verify_csrf_token(token):
raise InvalidCSRFToken("Invalid CSRF token.")
else:
token = self.csrf.generate_csrf_token()

return token
2 changes: 1 addition & 1 deletion app/http/middleware/LoadUserMiddleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
''' Load User Middleware'''
from masonite.facades.Auth import Auth

class LoadUserMiddleware(object):
class LoadUserMiddleware:
''' Middleware class which loads the current user into the request '''

def __init__(self, Request):
Expand Down
Empty file added bootstrap/cache/.gitignore
Empty file.
5 changes: 4 additions & 1 deletion config/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
|
'''

NAME = 'Masonite 1.3'
NAME = 'Masonite 1.4'

'''
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -79,6 +79,9 @@
'masonite.providers.ViewProvider.ViewProvider',
'masonite.providers.HelpersProvider.HelpersProvider',
'masonite.providers.QueueProvider.QueueProvider',
'masonite.providers.BroadcastProvider.BroadcastProvider',
'masonite.providers.CacheProvider.CacheProvider',
'masonite.providers.CsrfProvider.CsrfProvider',

# Third Party Providers

Expand Down
40 changes: 40 additions & 0 deletions config/broadcast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
''' Broadcast Settings '''

import os

'''
|--------------------------------------------------------------------------
| Broadcast Driver
|--------------------------------------------------------------------------
|
| Realtime support is critical for any modern web application. Broadcast
| drivers allow you to push data from your server to all your clients
| to show data updates to your clients in real time without having
| to constantly refresh the page or send constant ajax requests
|
| Supported: 'pusher', 'ably'
|
'''

DRIVER = os.getenv('BROADCAST_DRIVER', 'pusher')

'''
|--------------------------------------------------------------------------
| Broadcast Drivers
|--------------------------------------------------------------------------
|
| Below is a dictionary of all your driver configurations. Each key in the
| dictionary should be the name of a driver.
|
'''

DRIVERS = {
'pusher': {
'app_id': os.getenv('PUSHER_APP_ID', '29382xx..'),
'client': os.getenv('PUSHER_CLIENT', 'shS8dxx..'),
'secret': os.getenv('PUSHER_SECRET', 'HDGdjss..'),
},
'ably': {
'secret': os.getenv('ABLY_SECRET', 'api:key')
}
}
32 changes: 32 additions & 0 deletions config/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
''' Cache Settings '''

'''
|--------------------------------------------------------------------------
| Cache Driver
|--------------------------------------------------------------------------
|
| Caching is a great way to gain an instant speed boost to your application.
| Very often templates will not change and you can utilize caching to the
| best by caching your templates forever, monthly or every few seconds
|
| Supported: 'disk'
|
'''

DRIVER = 'disk'

'''
|--------------------------------------------------------------------------
| Cache Drivers
|--------------------------------------------------------------------------
|
| Place all your caching coniguration as a dictionary here. The keys here
| should correspond to the driver types supported above.
|
'''

DRIVERS = {
'disk': {
'location': 'bootstrap/cache'
}
}
8 changes: 4 additions & 4 deletions config/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
|
'''

databases = {
'mysql': {
DATABASES = {
'default': {
'driver': os.environ.get('DB_DRIVER'),
'host': os.environ.get('DB_HOST'),
'database': os.environ.get('DB_DATABASE'),
Expand All @@ -39,5 +39,5 @@
}
}

db = DatabaseManager(databases)
Model.set_connection_resolver(db)
DB = DatabaseManager(DATABASES)
Model.set_connection_resolver(DB)
3 changes: 2 additions & 1 deletion config/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
'''

HTTP_MIDDLEWARE = [
# 'app.http.middleware.LoadUserMiddleware.LoadUserMiddleware'
'app.http.middleware.LoadUserMiddleware.LoadUserMiddleware',
'app.http.middleware.CsrfMiddleware.CsrfMiddleware',
]

'''
Expand Down
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ waitress==1.1.0
Jinja2==2.10
python-dotenv==0.7.1
passlib==1.7.1
python-slugify==1.2.4
whitenoise==3.3.1
bcrypt==3.1.4
pytest==3.3.1
orator==0.9.7
masonite>=1.3,<=1.3.99
masonite>=1.4,<=1.4.99
cryptography==2.1.4
mysqlclient==1.3.12
psycopg2==2.7.3.2
PyMySQL==0.8.0
psycopg2==2.7.3.2
2 changes: 1 addition & 1 deletion routes/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from masonite.routes import Get, Post

ROUTES = [
Get().route('/', 'WelcomeController@show').name('home'),
Get().route('/', 'WelcomeController@show').name('welcome'),
]

0 comments on commit ee89a4c

Please sign in to comment.