Skip to content

Commit

Permalink
Merge pull request #100 from MasoniteFramework/develop
Browse files Browse the repository at this point in the history
Next Major
  • Loading branch information
josephmancuso authored Dec 1, 2018
2 parents 59848d6 + b082a42 commit 7237695
Show file tree
Hide file tree
Showing 46 changed files with 632 additions and 622 deletions.
26 changes: 23 additions & 3 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME=Masonite
APP_NAME=Masonite 2.1
APP_ENV=local
APP_DEBUG=True
KEY=your-secret-key
Expand All @@ -14,18 +14,38 @@ MAIL_PASSWORD=
MAILGUN_SECRET=
MAILGUN_DOMAIN=

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

STRIPE_PUBLISHABLE=
STRIPE_CLIENT=
STRIPE_SECRET=

STORAGE_DRIVER=disk

S3_CLIENT=
S3_SECRET=
S3_BUCKET=
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=
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.env
*__pycache__
venv
.env.*
.env.*
.vscode
.pytest_cache
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ python:
- "3.4"
- "3.5"
- "3.6"
matrix:
include:
- python: 3.7
dist: xenial
sudo: true
install:
- pip install masonite-cli
- craft install
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Joseph Mancuso
Copyright (c) 2017-present Joseph Mancuso

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
44 changes: 41 additions & 3 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<img src="https://travis-ci.org/MasoniteFramework/masonite.svg?branch=master">
<img src="https://img.shields.io/badge/python-3.4+-blue.svg" alt="Python Version"> <img src="http://pepy.tech/badge/masonite?1" alt="License"> <img src="https://img.shields.io/github/license/MasoniteFramework/masonite.svg" alt="License">
<img src="https://coveralls.io/repos/github/MasoniteFramework/core/badge.svg?branch=master#" alt="License">
<a href="https://gitter.im/masonite-framework/Lobby"><img src="https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg" alt="gitter"></a>

</p>

Expand All @@ -30,7 +29,14 @@ Masonite works hard to be fast and easy from install to deployment so developers

Masonite strives to have extremely comprehensive documentation. All documentation can be [Found Here](https://masoniteframework.gitbooks.io/docs/content/) and would be wise to go through the tutorials there. If you find any discrepencies or anything that doesn't make sense, be sure to comment directly on the documentation to start a discussion!

Also be sure to join the [Slack channel](https://masoniteframework.gitbooks.io/docs/content/)!
Also be sure to join the [Slack channel](http://slack.masoniteproject.com/)!


## Requirements

- Python 3.4 +
- OpenSSL (latest version)
- Pip

## Linux

Expand All @@ -46,6 +52,38 @@ Instead of `python-dev` you may need to specify your Python version
$ sudo apt-get install python3.6-dev libssl-dev
```

## Windows

With windows you will need to have the latest OpenSSL version. Install OpenSSL [32-bit](http://slproweb.com/download/Win32OpenSSL-1_1_0h.exe) or [64-bit](http://slproweb.com/download/Win64OpenSSL-1_1_0h.exe)

## Mac

If you do not have the latest version of OpenSSL you will encounter some installation issues with creating new applications since we need to download a zip of the application via GitHub.

With Mac you can install OpenSSL through `brew`.

```
brew install openssl
```

Python 3.6 does not come preinstalled with certificates so you may need to install certificates with this command:

```
/Applications/Python\ 3.6/Install\ Certificates.command
```

You should now be good to install new Masonite application of Mac :)

### Python 3.7

If you are using [Python 3.7](https://www.python.org/downloads/windows/), add it to your PATH Environment variable.

Open Windows PowerShell and run: `pip install masonite-cli`

Add `C:\Users\%USERNAME%\.AppData\Programs\Python\Python37\Scripts\` to PATH Environment variable.

Note: PATH variables depend on your installation folder

## Installation:

```
Expand Down Expand Up @@ -205,7 +243,7 @@ Inside the `HelloWorldController` we can make our `show` method like this:

```python
def show(self):
''' Show Hello World Template '''
""" Show Hello World Template """
return view('helloworld')
```

Expand Down
6 changes: 4 additions & 2 deletions app/User.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
''' User Model '''
"""User Model."""

from config.database import Model


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

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

Expand Down
24 changes: 19 additions & 5 deletions app/http/controllers/WelcomeController.py
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')
})
21 changes: 14 additions & 7 deletions app/http/middleware/AuthenticationMiddleware.py
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
51 changes: 7 additions & 44 deletions app/http/middleware/CsrfMiddleware.py
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
35 changes: 23 additions & 12 deletions app/http/middleware/LoadUserMiddleware.py
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())
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
Empty file added app/providers/.gitignore
Empty file.
15 changes: 0 additions & 15 deletions app/providers/MiddlewareProvider.py

This file was deleted.

15 changes: 0 additions & 15 deletions app/providers/UserModelProvider.py

This file was deleted.

Loading

0 comments on commit 7237695

Please sign in to comment.