Skip to content

Commit

Permalink
Merge 8df4046 into 38e99d7
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavmule committed Jan 9, 2019
2 parents 38e99d7 + 8df4046 commit 9937e08
Show file tree
Hide file tree
Showing 33 changed files with 466 additions and 480 deletions.
42 changes: 40 additions & 2 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
APP_NAME=Masonite 2.1
APP_ENV=local
APP_DEBUG=True
KEY=your-secret-key

MAIL_DRIVER=smtp
MAIL_FROM_ADDRESS=sandboxXX.mailgun.org
MAIL_FROM_NAME=Masonite
Expand All @@ -9,8 +14,41 @@ MAIL_PASSWORD=
MAILGUN_SECRET=key-xx
MAILGUN_DOMAIN=xx.mailgun.org

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=masonite
DB_USERNAME=root
DB_PASSWORD=root
DB_LOG=True

STRIPE_CLIENT=
STRIPE_SECRET=

STORAGE_DRIVER=disk

S3_CLIENT=
S3_SECRET=
S3_BUCKET=

RACKSPACE_USERNAME=
RACKSPACE_SECRET=
RACKSPACE_CONTAINER=
RACKSPACE_REGION=

AZURE_NAME=
AZURE_SECRET=
AZURE_CONNECTION=
AZURE_CONTAINER=

QUEUE_DRIVER=async
QUEUE_USERNAME=
QUEUE_VHOST=
QUEUE_PASSWORD=
QUEUE_HOST=
QUEUE_PORT=
QUEUE_CHANNEL=

PUSHER_APP_ID=
PUSHER_CLIENT=
PUSHER_SECRET=

ABLY_SECRET=
5 changes: 2 additions & 3 deletions app/User.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
""" User Model """
"""User Model."""

from config.database import Model


class User(Model):
"""User Model
"""
"""User Model."""

__fillable__ = ['name', 'email', 'password']

Expand Down
12 changes: 6 additions & 6 deletions app/http/controllers/WelcomeController.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
""" 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):
"""Shows the welcome page.
"""Show the welcome page.
Arguments:
view {masonite.view.View} -- The Masonite view class.
Expand All @@ -18,5 +17,6 @@ def show(self, view: View, request: Request):
Returns:
masonite.view.View -- The Masonite view class.
"""

return view.render('welcome', {'app': request.app().make('Application')})
return view.render('welcome', {
'app': request.app().make('Application')
})
16 changes: 5 additions & 11 deletions app/http/middleware/AuthenticationMiddleware.py
Original file line number Diff line number Diff line change
@@ -1,30 +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
"""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
"""

"""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
6 changes: 4 additions & 2 deletions app/http/middleware/CsrfMiddleware.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
""" CSRF Middleware """
"""CSRF Middleware."""

from masonite.middleware import CsrfMiddleware as Middleware


class CsrfMiddleware(Middleware):
""" Verify CSRF Token Middleware """
"""Verify CSRF Token Middleware."""

exempt = []
every_request = False
token_length = 30
19 changes: 6 additions & 13 deletions app/http/middleware/LoadUserMiddleware.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
""" Load User Middleware """
"""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: Request):
"""Inject Any Dependencies From The Service Container
"""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
"""

"""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):
"""Load user into the request
"""Load user into the request.
Arguments:
request {masonite.request.Request} -- The Masonite request object.
"""

self.request.set_user(Auth(self.request).user())
26 changes: 26 additions & 0 deletions app/http/middleware/VerifyEmailMiddleware.py
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
67 changes: 21 additions & 46 deletions bootstrap/start.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
""" Start of Application. This function is the gunicorn server """
"""Start of Application. This function is the gunicorn server."""

from masonite.environment import LoadEnvironment

"""
|--------------------------------------------------------------------------
| Load Environment Variables
|--------------------------------------------------------------------------
|
| Take environment variables from the .env file and load them in.
|
"""Load Environment Variables
Take environment variables from the .env file and load them in.
"""

LoadEnvironment()


def app(environ, start_response):
"""The WSGI Application Server
"""The WSGI Application Server.
Arguments:
environ {dict} -- The WSGI environ dictionary
Expand All @@ -24,29 +19,18 @@ def app(environ, start_response):
Returns:
WSGI Response
"""

from wsgi import container

"""
|--------------------------------------------------------------------------
| Add Environ To Service Container
|--------------------------------------------------------------------------
|
| Add the environ to the service container. The environ is generated by the
| the WSGI server above and used by a service provider to manipulate the
| incoming requests
|
"""Add Environ To Service Container
Add the environ to the service container. The environ is generated by the
the WSGI server above and used by a service provider to manipulate the
incoming requests
"""

container.bind('Environ', environ)

"""
|--------------------------------------------------------------------------
| Execute All Service Providers That Require The WSGI Server
|--------------------------------------------------------------------------
|
| Run all service provider boot methods if the wsgi attribute is true.
|
"""Execute All Service Providers That Require The WSGI Server
Run all service provider boot methods if the wsgi attribute is true.
"""

try:
Expand All @@ -55,28 +39,19 @@ def app(environ, start_response):
except Exception as e:
container.make('ExceptionHandler').load_exception(e)

"""We Are Ready For Launch
If we have a solid response and not redirecting then we need to return
a 200 status code along with the data. If we don't, then we'll have
to return a 302 redirection to where ever the user would like go
to next.
"""
|--------------------------------------------------------------------------
| We Are Ready For Launch
|--------------------------------------------------------------------------
|
| If we have a solid response and not redirecting then we need to return
| a 200 status code along with the data. If we don't, then we'll have
| to return a 302 redirection to where ever the user would like go
| to next.
|
"""

start_response(container.make('Request').get_status_code(), container.make('Request').get_and_reset_headers())

"""
|--------------------------------------------------------------------------
| Final Step
|--------------------------------------------------------------------------
|
| This will take the data variable from the Service Container and return
| it to the WSGI server.
|
start_response(container.make('Request').get_status_code(),
container.make('Request').get_and_reset_headers())

"""Final Step
This will take the data variable from the Service Container and return
it to the WSGI server.
"""

return iter([bytes(container.make('Response'), 'utf-8')])
Loading

0 comments on commit 9937e08

Please sign in to comment.