Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-cutter into 2.3
  • Loading branch information
josephmancuso committed Jan 24, 2020
2 parents f8e34e6 + ae7256f commit 2f77f36
Show file tree
Hide file tree
Showing 28 changed files with 191 additions and 121 deletions.
3 changes: 2 additions & 1 deletion .env-example
Expand Up @@ -2,9 +2,10 @@ APP_NAME=Masonite 2.3
APP_ENV=local
APP_DEBUG=True
AUTH_GUARD=web
APP_URL=http://localhost:8000
KEY=your-secret-key

MAIL_DRIVER=smtp
MAIL_DRIVER=terminal
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
MAIL_HOST=
Expand Down
2 changes: 2 additions & 0 deletions .env.testing
@@ -0,0 +1,2 @@
DB_CONNECTION=sqlite
DB_LOG=True
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ venv
.pytest_cache
node_modules
package-lock.json
!.env.testing
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -5,9 +5,8 @@ python:
- "3.6"
matrix:
include:
- python: 3.7
- python: "3.7"
dist: xenial
sudo: true
install:
- pip install masonite-cli
- craft install
Expand Down
68 changes: 33 additions & 35 deletions README.md
Expand Up @@ -11,6 +11,9 @@

</p>

**NOTE: This repository is the general shell of the framework. This repository is responsible for managing the installation of all new applications. All core framework related code has been abstracted out into it's own PYPI package which can be found [in this GitHub Repo](https://github.com/masoniteframework/core).**


## About Masonite

The modern and developer centric Python web framework that strives for an actual batteries included developer tool with a lot of out of the box functionality with an extremely extendable architecture. Masonite is perfect for beginner developers getting into their first web applications as well as experienced devs that need to utilize the full potential of Masonite to get their applications done.
Expand All @@ -29,6 +32,8 @@ 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://docs.masoniteproject.com/v/v2.1/) 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!

If you are a visual learner you can find tutorials here: [MasoniteCasts](https://casts.masonite.dev)

Also be sure to join the [Slack channel](http://slack.masoniteproject.com/)!


Expand All @@ -54,7 +59,7 @@ $ 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)
With windows you will need to have the latest OpenSSL version. Install [OpenSSL 32-bit or 64-bit](https://slproweb.com/products/Win32OpenSSL.html).

## Mac

Expand Down Expand Up @@ -133,33 +138,34 @@ Getting started is very easy. Below is how you can get a simple Hello World appl

## Installation

You can easily create new applications with `craft`. To create a new application run:

$ craft new project_name

****
The best way to install Masonite is by starting in a virtual environment first. This will avoid any issues with filesystem permissions.

<p align="center">
* * * *
</p>
```
python3 -m venv venv
```

NOTE: If you do not have the craft command, you can run `pip install masonite-cli` which will install `craft` command line tool.
Then activate the virtual environment:

<p align="center">
* * * *
</p>
```
WINDOWS: $ ./venv/Scripts/activate
MAC: $ source venv/bin/activate
```

****

This command will create a new directory called `project_name` with our new Masonite project.
You can easily create new applications with `craft`. To create a new application run:

You can now cd into this directory by doing:
```
$ pip install masonite-cli
$ craft new project .
```

$ cd project_name
The `.` will tell craft to create the project in the current directory instead of a new directory.

Now we just need to add the pip dependencies. You can run `pip3 install -r "requirements.txt"` or you can run the `craft` command:
```
$ craft install
```

$ craft install
This will install all of Masonites dependencies as well as create a new `.env` file consisting of all of your environment variables.

****

Expand All @@ -176,11 +182,11 @@ NOTE: Python craft commands are essentially wrappers around common mundane tasks
****


This will install all the required dependencies to run this framework. Now we can run the `craft` command:
Now we can run the `craft` command:

$ craft serve

This will run the server at `localhost:8000`. Navigating to that URL should show the Masonite welcome message.
This will run the server at `localhost:8000` and be in an auto-reloading state. When you change files, your server will restart. Navigating to that URL should show the Masonite welcome message.

If that port is blocked you can specify a port by running:

Expand All @@ -189,27 +195,21 @@ If that port is blocked you can specify a port by running:
Or specify a host by running:

$ craft serve --host 192.168.1.283

The server can also be auto reloaded by passing in a `-r` flag (short for `--reload`)

$ craft serve -r

This will reload the server when Masonite detects file changes. This is very similiar to Django.

## Hello World

All web routes are in `routes/web.py`. In this file is already the route to the welcome controller. To start your hello world example just add something like:

```python
Get().route('/hello/world', 'HelloWorldController@show'),
Get('/hello/world', 'HelloWorldController@show'),
```

our routes constant file should now look something like:

```python
ROUTES = [
Get().route('/', 'WelcomeController@show'),
Get().route('/hello/world', 'HelloWorldController@show'),
Get('/', 'WelcomeController@show'),
Get('/hello/world', 'HelloWorldController@show'),
]
```

Expand All @@ -235,16 +235,14 @@ In order to make the `HelloWorldController` we can use a `craft` command:

$ craft controller HelloWorld

This will scaffold the controller for you and put it in `app/http/controllers/HelloWorldController.py`

We will have a `show()` method by default which is the typical method we will use to "show" our views and content.
This will scaffold the controller for you and put it in `app/http/controllers/HelloWorldController.py`. This new file will have all the imports for us.

Inside the `HelloWorldController` we can make our `show` method like this:

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

As you see above, we are returning a `helloworld` template but we do not have that yet. All templates are in `resources/templates`. We can simply make a file called `helloworld.html` or run the `craft` command:
Expand Down
5 changes: 3 additions & 2 deletions app/http/controllers/WelcomeController.py
Expand Up @@ -2,17 +2,18 @@

from masonite.view import View
from masonite.request import Request
from masonite.controllers import Controller


class WelcomeController:
class WelcomeController(Controller):
"""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.
request {masonite.request.Request} -- The Masonite request class.
Returns:
masonite.view.View -- The Masonite view class.
Expand Down
2 changes: 1 addition & 1 deletion app/http/middleware/AuthenticationMiddleware.py
Expand Up @@ -10,7 +10,7 @@ def __init__(self, request: Request):
"""Inject Any Dependencies From The Service Container.
Arguments:
Request {masonite.request.Request} -- The Masonite request object
request {masonite.request.Request} -- The Masonite request class.
"""
self.request = request

Expand Down
9 changes: 8 additions & 1 deletion app/http/middleware/CsrfMiddleware.py
Expand Up @@ -6,6 +6,13 @@
class CsrfMiddleware(Middleware):
"""Verify CSRF Token Middleware."""

exempt = []
"""Which routes should be exempt from CSRF protection."""
exempt = [
#
]

"""Whether or not the CSRF token should be changed on every request."""
every_request = False

"""The length of the token to generate."""
token_length = 30
3 changes: 2 additions & 1 deletion app/http/middleware/LoadUserMiddleware.py
Expand Up @@ -11,7 +11,8 @@ def __init__(self, request: Request, auth: Auth):
"""Inject Any Dependencies From The Service Container.
Arguments:
Request {masonite.request.Request} -- The Masonite request object.
request {masonite.request.Request} -- The Masonite request object.
auth {masonite.auth.Auth} -- The Masonite authentication object.
"""
self.request = request
self.auth = auth
Expand Down
2 changes: 1 addition & 1 deletion app/http/middleware/VerifyEmailMiddleware.py
Expand Up @@ -10,7 +10,7 @@ def __init__(self, request: Request):
"""Inject Any Dependencies From The Service Container.
Arguments:
Request {masonite.request.Request} -- The Masonite request object
request {masonite.request.Request} -- The Masonite request class.
"""
self.request = request

Expand Down
2 changes: 1 addition & 1 deletion config/application.py
Expand Up @@ -33,7 +33,7 @@
Sets the root URL of the application. This is primarily used for testing
"""

URL = 'http://localhost:8000'
URL = env('APP_URL', 'http://localhost:8000')

"""Base Directory
Sets the root path of your project
Expand Down
11 changes: 11 additions & 0 deletions config/auth.py
Expand Up @@ -33,3 +33,14 @@
},
}
}

DRIVERS = {
'cookie': {},
'jwt': {
"""Whether or not to reauthenticate with the database when the token expires."""
'reauthentication': True,

"""How long the token should live for before being refreshed."""
'lifetime': '5 minutes'
}
}
5 changes: 3 additions & 2 deletions config/database.py
@@ -1,6 +1,7 @@
import logging
"""Database Settings."""

import logging

from masonite import env
from masonite.environment import LoadEnvironment
from orator import DatabaseManager, Model
Expand Down Expand Up @@ -53,7 +54,7 @@


logger = logging.getLogger('orator.connection.queries')
logger.setLevel(logging.DEBUG )
logger.setLevel(logging.DEBUG)

formatter = logging.Formatter(
'It took %(elapsed_time)sms to execute the query %(query)s'
Expand Down
15 changes: 15 additions & 0 deletions config/factories.py
@@ -0,0 +1,15 @@
from orator.orm import Factory
from app.User import User

factory = Factory()


def users_factory(faker):
return {
'name': faker.name(),
'email': faker.email(),
'password': '$2b$12$WMgb5Re1NqUr.uSRfQmPQeeGWudk/8/aNbVMpD1dR.Et83vfL8WAu', # == 'secret'
}


factory.register(User, users_factory)
2 changes: 1 addition & 1 deletion config/middleware.py
Expand Up @@ -22,7 +22,7 @@
]

"""Route Middleware
Specify a dictionary of middleware to be used on a per route basis here. The key will
Specify a dictionary of middleware to be used on a per route basis here. The key will
be the alias to use on routes and the value can be any middleware class or a list
of middleware (middleware stacks).
"""
Expand Down
2 changes: 2 additions & 0 deletions config/providers.py
Expand Up @@ -6,6 +6,7 @@
SessionProvider, StatusCodeProvider,
UploadProvider, ViewProvider,
WhitenoiseProvider)
from masonite.validation.providers.ValidationProvider import ValidationProvider

from masonite.logging.providers import LoggingProvider
from masonite.validation.providers import ValidationProvider
Expand Down Expand Up @@ -35,6 +36,7 @@
BroadcastProvider,
CsrfProvider,
HelpersProvider,
ValidationProvider,

# Third Party Providers
LoggingProvider,
Expand Down
3 changes: 3 additions & 0 deletions config/queue.py
Expand Up @@ -16,6 +16,9 @@
"""

DRIVERS = {
'async': {
'mode': 'threading'
},
'amqp': {
'username': env('QUEUE_USERNAME', 'guest'),
'vhost': env('QUEUE_VHOST', ''),
Expand Down
1 change: 1 addition & 0 deletions craft 100644 → 100755
@@ -1,3 +1,4 @@
#!/usr/bin/env python
"""Craft Command.
This module is really used for backup only if the masonite CLI cannot import this for you.
Expand Down
15 changes: 3 additions & 12 deletions databases/seeds/user_table_seeder.py
@@ -1,16 +1,16 @@
"""User Table Seeder.
You can run this seeder in order to generate users.
You can run this seeder in order to generate users.
- Each time it is ran it will generate 50 random users.
- All users have the password of 'secret'.
- You can run the seeder by running: craft seed:run.
"""

from orator.orm import Factory
from orator.seeds import Seeder

from app.User import User
from config.factories import factory


class UserTableSeeder(Seeder):
Expand All @@ -19,13 +19,4 @@ def run(self):
"""
Run the database seeds.
"""
self.factory.register(User, self.users_factory)

self.factory(User, 50).create()

def users_factory(self, faker):
return {
'name': faker.name(),
'email': faker.email(),
'password': '$2b$12$WMgb5Re1NqUr.uSRfQmPQeeGWudk/8/aNbVMpD1dR.Et83vfL8WAu', # == 'secret'
}
factory(User, 50).create()
2 changes: 1 addition & 1 deletion resources/__init__.py
@@ -1,5 +1,5 @@
"""Resources directory.
This directory is responsible for storing any resource based files such as
This directory is responsible for storing any resource based files such as
templates and SASS files
"""

0 comments on commit 2f77f36

Please sign in to comment.