Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added 2.1 to 2.2 changes #2

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -9,7 +9,7 @@ class HomeController:
def __init__(self, request: Request):
self.request = request

def show(self):
if not Auth(self.request).user():
def show(self, auth: Auth):
if not auth.user():
self.request.redirect('/login')
return view('auth/home', {'app': application, 'Auth': Auth(self.request)})
return view('auth/home', {'app': application, 'Auth': auth})
@@ -7,7 +7,8 @@
from masonite.helpers import password as bcrypt_password

from app.User import User
from app.validators.RegisterValidator import RegisterValidator
# from app.validators.RegisterValidator import RegisterValidator
from masonite.validation import Validator


class LoginController:
@@ -16,27 +17,32 @@ class LoginController:
def __init__(self, request: Request):
self.request = request

def show(self):
def show(self, auth: Auth):
''' Show the login page '''
return view('auth/login', {'app': application, 'Auth': Auth(self.request)})
return view('auth/login', {'app': application, 'Auth': auth})

def store(self):
validate = RegisterValidator(self.request).login()
if not validate.check():
self.request.session.flash('validation', validate.errors())
return self.request.redirect_to('login')
def store(self, auth: Auth, validator: Validator):
errors = self.request.validate(
validator.required(['username', 'password']),
validator.length(['username', 'password'], min=1, max=35),
validator.is_in('username', User.all().pluck('email').map(lambda item: item.lower()), messages = {
'username': 'Username or password is incorrect'
})
)

if errors:
return self.request.redirect_to('login').with_errors(errors)

self.check_old_encryption(self.request)

if Auth(self.request).login(self.request.input('username'), self.request.input('password')):
if auth.login(self.request.input('username'), self.request.input('password')):
return self.request.redirect_to('discover')
else:
self.request.session.flash('danger', 'Invalid username or password')
return self.request.redirect_to('login')
return 'check terminal'

def logout(self):
Auth(self.request).logout()
def logout(self, auth: Auth):
auth.logout()
return self.request.redirect('/login')

def check_old_encryption(self, request):
@@ -8,9 +8,11 @@
from masonite.helpers import password as bcrypt_password

from app.notifications import WelcomeNotification
from app.validators import RegisterValidator
# from app.validators import RegisterValidator
from config import auth
from app.jobs import WelcomeEmailJob
from masonite.validation import Validator
from app.User import User


class RegisterController:
@@ -19,33 +21,41 @@ class RegisterController:
def __init__(self, request: Request):
self.request = request

def show(self):
def show(self, auth: Auth):
""" Show the registration page """
return view('auth/register', {'app': application, 'Auth': Auth(self.request), 'json': json})
return view('auth/register', {'app': application, 'Auth': auth, 'json': json})

def store(self, queue: Queue):
def store(self, auth: Auth, request: Request, queue: Queue, validator: Validator):
""" Register a new user """

validate = RegisterValidator(self.request).register()
if validate.check():
validate.check_exists()
errors = request.validate(
validator.required(['username', 'email', 'password']),
validator.length('username', min=3, max=20),
validator.length('email', min=3),
validator.isnt(
validator.is_in('email', User.all().pluck('email'), messages = {
'email': 'That email already exists'
}),
)
)

print(errors)

if not validate.check():
self.request.session.flash('validation', json.dumps(validate.errors()))
return self.request.redirect_to('register')
if errors:
return self.request.redirect_to('register').with_errors(errors)

# register the user
password = bcrypt_password(self.request.input('password'))

auth.AUTH['model'].create(
name=self.request.input('username'),
password=password,
email=self.request.input('email'),
)
auth.register({
'name': self.request.input('username'),
'password': self.request.input('password'),
'email': self.request.input('email'),
})

# login the user
# redirect to the homepage
if Auth(self.request).login(self.request.input(auth.AUTH['model'].__auth__), self.request.input('password')):
if auth.login(self.request.input('email'), self.request.input('password')):
queue.push(WelcomeEmailJob, args=[self.request.input('email')])
return self.request.redirect('/home')

@@ -23,7 +23,6 @@ def discover(self) -> View.render:
Returns:
View.render
"""

if self.request.input('search'):
leagues = League.order_by('id', 'desc').get().filter(lambda league: self.request.input(
'search').lower() in league.name.lower())
@@ -2,12 +2,13 @@
from masonite.auth import Auth
from masonite.request import Request

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

def __init__(self, request: Request):
def __init__(self, request: Request, auth: Auth):
''' Inject Any Dependencies From The Service Container '''
self.request = request
self.auth = auth

def before(self):
''' Run This Middleware Before The Route Executes '''
@@ -20,4 +21,4 @@ def after(self):

def load_user(self, request):
''' Load user into the request '''
request.set_user(Auth(request).user())
request.set_user(self.auth.user())

This file was deleted.

This file was deleted.

@@ -29,14 +29,30 @@
'''

DATABASES = {
'default': {
'driver': env('DB_DRIVER'),
'default': env('DB_CONNECTION'),
'sqlite': {
'driver': 'sqlite',
'database': env('DB_DATABASE'),
'log_queries': env('DB_LOG'),
},
'mysql': {
'driver': 'mysql',
'host': env('DB_HOST'),
'database': env('DB_DATABASE'),
'port': env('DB_PORT'),
'user': env('DB_USERNAME'),
'password': env('DB_PASSWORD'),
'log_queries': env('DB_LOG'),
},
'postgres': {
'driver': 'postgres',
'host': env('DB_HOST'),
'database': env('DB_DATABASE'),
'port': env('DB_PORT'),
'user': env('DB_USERNAME'),
'password': env('DB_PASSWORD'),
'prefix': ''
}
'log_queries': env('DB_LOG'),
},
}

DB = DatabaseManager(DATABASES)
@@ -13,6 +13,7 @@
from app.providers import (MiddlewareProvider, SentryServiceProvider,
UserModelProvider)
from events.providers import EventProvider
from masonite.validation.providers import ValidationProvider

"""
|--------------------------------------------------------------------------
@@ -47,7 +48,8 @@
BroadcastProvider,
CacheProvider,
CsrfProvider,

ValidationProvider,

# Third Party Providers
BillingProvider,
SentryServiceProvider,
@@ -8,7 +8,7 @@ def up(self):
Run the migrations.
"""
with self.schema.table('schedules') as table:
table.date('scheduled_for')
table.date('scheduled_for').nullable()

def down(self):
"""
@@ -8,8 +8,7 @@ def up(self):
Run the migrations.
"""
with self.schema.table('discord') as table:
table.string('channel_id')
table.string('token')
table.string('token').nullable()

def down(self):
"""
@@ -9,6 +9,15 @@
<div class="panel-body">
{% include 'helpers/validation.html' %}
{% include 'helpers/messages.html' %}
{% if session().has('errors') %}
<div class="alert alert-danger">
{% for _, messages in session().get('errors').items() %}
{% for error in messages %}
{{ error }}<br>
{% endfor %}
{% endfor %}
</div>
{% endif %}
<form action="/login" method="POST">
{{ csrf_field|safe }}

@@ -6,6 +6,15 @@
<div class="panel-heading">Register</div>
<div class="panel-body">
{% include 'helpers/validation.html' %}
{% if session().has('errors') %}
<div class="alert alert-danger">
{% for _, messages in session().get('errors').items() %}
{% for error in messages %}
{{ error }}<br>
{% endfor %}
{% endfor %}
</div>
{% endif %}
<form action="/register" method="POST">
{{ csrf_field|safe }}

@@ -1,13 +1,13 @@
''' Web Routes '''
from masonite.routes import Get, RouteGroup
from masonite.helpers.routes import get, post
from masonite.routes import Get as get, Post as post
# from dashboard.routes import management_routes

ROUTES = [

RouteGroup([
get('/discover', 'WelcomeController@discover').name('discover'),
get('/', 'WelcomeController@show').name('home'),
get('/discover', 'WelcomeController@discover').name('discover'),
]),

# League Routes
@@ -92,12 +92,12 @@

# Slack
get('/integration/slack/@id', 'AppIntegrationsController@slack_send'),
Get().domain('*').route('/oauth/slack', 'AppIntegrationsController@slack_return'),
get().domain('*').route('/oauth/slack', 'AppIntegrationsController@slack_return'),

# Discord
get('/integration/discord/@id', 'AppIntegrationsController@discord_send'),
Get().domain('*').route('/oauth/discord', 'AppIntegrationsController@discord_return'),
Get().domain('*').route('/slacktest', 'WelcomeController@slack').name('create-league'),
get().domain('*').route('/oauth/discord', 'AppIntegrationsController@discord_return'),
get().domain('*').route('/slacktest', 'WelcomeController@slack').name('create-league'),

# Testing
post('/stripe/webhook', '/billing.controllers.WebhookController@handle').domain('684b1285'),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.