-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from MasoniteFramework/develop
Next Major
- Loading branch information
Showing
46 changed files
with
632 additions
and
622 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
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 |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
.env | ||
*__pycache__ | ||
venv | ||
.env.* | ||
.env.* | ||
.vscode | ||
.pytest_cache |
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
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
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,8 +1,22 @@ | ||
''' Welcome The User To Masonite ''' | ||
"""Welcome The User To Masonite.""" | ||
|
||
from masonite.view import View | ||
from masonite.request import Request | ||
|
||
|
||
class WelcomeController: | ||
''' Controller For Welcoming The User ''' | ||
"""Controller For Welcoming The User.""" | ||
|
||
def show(self, view: View, request: Request): | ||
"""Show the welcome page. | ||
Arguments: | ||
view {masonite.view.View} -- The Masonite view class. | ||
Application {config.application} -- The application config module. | ||
def show(self, Application): | ||
''' Show Welcome Template ''' | ||
return view('welcome', {'app': Application}) | ||
Returns: | ||
masonite.view.View -- The Masonite view class. | ||
""" | ||
return view.render('welcome', { | ||
'app': request.app().make('Application') | ||
}) |
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,17 +1,24 @@ | ||
''' Authentication Middleware ''' | ||
"""Authentication Middleware.""" | ||
|
||
from masonite.request import Request | ||
|
||
|
||
class AuthenticationMiddleware: | ||
''' Middleware To Check If The User Is Logged In ''' | ||
"""Middleware To Check If The User Is Logged In.""" | ||
|
||
def __init__(self, request: Request): | ||
"""Inject Any Dependencies From The Service Container. | ||
def __init__(self, Request): | ||
''' Inject Any Dependencies From The Service Container ''' | ||
self.request = Request | ||
Arguments: | ||
Request {masonite.request.Request} -- The Masonite request object | ||
""" | ||
self.request = request | ||
|
||
def before(self): | ||
''' Run This Middleware Before The Route Executes ''' | ||
"""Run This Middleware Before The Route Executes.""" | ||
if not self.request.user(): | ||
self.request.redirect_to('login') | ||
|
||
def after(self): | ||
''' Run This Middleware After The Route Executes ''' | ||
"""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 |
---|---|---|
@@ -1,48 +1,11 @@ | ||
''' CSRF Middleware ''' | ||
from masonite.exceptions import InvalidCSRFToken | ||
"""CSRF Middleware.""" | ||
|
||
from masonite.middleware import CsrfMiddleware as Middleware | ||
|
||
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='__token' value='{0}' />".format(token) | ||
}) | ||
|
||
def after(self): | ||
pass | ||
class CsrfMiddleware(Middleware): | ||
"""Verify CSRF Token Middleware.""" | ||
|
||
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('__token') | ||
if not self.csrf.verify_csrf_token(token): | ||
raise InvalidCSRFToken("Invalid CSRF token.") | ||
else: | ||
token = self.csrf.generate_csrf_token() | ||
|
||
return token | ||
exempt = [] | ||
every_request = False | ||
token_length = 30 |
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,22 +1,33 @@ | ||
''' Load User Middleware''' | ||
from masonite.facades.Auth import Auth | ||
"""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 ''' | ||
"""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 __init__(self, request: Request): | ||
"""Inject Any Dependencies From The Service Container. | ||
Arguments: | ||
Request {masonite.request.Request} -- The Masonite request object. | ||
""" | ||
self.request = request | ||
|
||
def before(self): | ||
''' Run This Middleware Before The Route Executes ''' | ||
self.load_user(self.request) | ||
"""Run This Middleware Before The Route Executes.""" | ||
self.load_user() | ||
return self.request | ||
|
||
def after(self): | ||
''' Run This Middleware After The Route Executes ''' | ||
"""Run This Middleware After The Route Executes.""" | ||
pass | ||
|
||
def load_user(self, request): | ||
''' Load user into the request ''' | ||
request.set_user(Auth(request).user()) | ||
def load_user(self): | ||
"""Load user into the request. | ||
Arguments: | ||
request {masonite.request.Request} -- The Masonite request object. | ||
""" | ||
self.request.set_user(Auth(self.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Verify Email Middleware.""" | ||
|
||
from masonite.request import Request | ||
|
||
|
||
class VerifyEmailMiddleware: | ||
"""Middleware To Check If The User Has Verified Their Email.""" | ||
|
||
def __init__(self, request: Request): | ||
"""Inject Any Dependencies From The Service Container. | ||
Arguments: | ||
Request {masonite.request.Request} -- The Masonite request object | ||
""" | ||
self.request = request | ||
|
||
def before(self): | ||
"""Run This Middleware Before The Route Executes.""" | ||
user = self.request.user() | ||
|
||
if user and user.verified_at is None: | ||
self.request.redirect('/email/verify') | ||
|
||
def after(self): | ||
"""Run This Middleware After The Route Executes.""" | ||
pass |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.