Skip to content

Commit

Permalink
fixed auth command pointing to wrong snippet location
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed May 1, 2018
1 parent acec94c commit af0b464
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 5 deletions.
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
include masonite/snippets/exceptions/css/*
include masonite/snippets/*
include masonite/snippets/*
include masonite/snippets/auth/controllers/*
include masonite/snippets/auth/templates/auth/*
8 changes: 4 additions & 4 deletions masonite/commands/AuthCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def handle(self):
f.write(']\n')

# move controllers
shutil.copyfile(module_path+"/../masonite_snippets/auth/controllers/LoginController.py",
shutil.copyfile(module_path+"/../snippets/auth/controllers/LoginController.py",
os.getcwd()+"/app/http/controllers/LoginController.py")
shutil.copyfile(module_path+"/../masonite_snippets/auth/controllers/RegisterController.py",
shutil.copyfile(module_path+"/../snippets/auth/controllers/RegisterController.py",
os.getcwd()+"/app/http/controllers/RegisterController.py")
shutil.copyfile(module_path+"/../masonite_snippets/auth/controllers/HomeController.py",
shutil.copyfile(module_path+"/../snippets/auth/controllers/HomeController.py",
os.getcwd()+"/app/http/controllers/HomeController.py")

# move templates
shutil.copytree(module_path + "/../masonite_snippets/auth/templates/auth",
shutil.copytree(module_path + "/../snippets/auth/templates/auth",
os.getcwd()+"/resources/templates/auth")

self.info('Project Scaffolded. You now have 4 new controllers, 5 new templates and 6 new routes')
13 changes: 13 additions & 0 deletions masonite/snippets/auth/controllers/HomeController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
''' A Module Description '''
from masonite.facades.Auth import Auth

class HomeController(object):
''' Home Dashboard Controller '''

def __init__(self):
pass

def show(self, Request, Application):
if not Auth(Request).user():
Request.redirect('/login')
return view('auth/home', {'app': Application, 'Auth': Auth(Request)})
23 changes: 23 additions & 0 deletions masonite/snippets/auth/controllers/LoginController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
''' A Module Description '''
from masonite.facades.Auth import Auth

class LoginController(object):
''' Login Form Controller '''

def __init__(self):
pass

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

def store(self, Request):
if Auth(Request).login(Request.input('username'), Request.input('password')):
Request.redirect('/home')
else:
Request.redirect('/login')
return 'check terminal'

def logout(self, Request):
Auth(Request).logout()
return Request.redirect('/login')
35 changes: 35 additions & 0 deletions masonite/snippets/auth/controllers/RegisterController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
''' A Module Description '''
from masonite.facades.Auth import Auth
from config import auth
import bcrypt


class RegisterController(object):
''' Class Docstring Description '''

def __init__(self):
pass

def show(self, Request, Application):
''' Show the registration page '''
return view('auth/register', {'app': Application, 'Auth': Auth(Request)})

def store(self, Request):
''' Register a new user '''
# register the user
password = bcrypt.hashpw(
bytes(Request.input('password'), 'utf-8'), bcrypt.gensalt()
)

auth.AUTH['model'].create(
name=Request.input('name'),
password=password,
email=Request.input('email'),
)

# login the user
# redirect to the homepage
if Auth(Request).login(Request.input(auth.AUTH['model'].__auth__), Request.input('password')):
return Request.redirect('/home')

return Request.redirect('/register')
46 changes: 46 additions & 0 deletions masonite/snippets/auth/templates/auth/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{ app.name }}</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
</head>

<body>

<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/home">{{ app.NAME }}</a>
</div>
<ul class="nav navbar-nav navbar-right">

{% if Auth.user() %}
<li>
<a href="/logout">Logout</a>
</li>
{% else %}
<li>
<a href="/login">Login</a>
</li>
<li>
<a href="/register">Register</a>
</li>
{% endif %}
</ul>
</div>
</nav>



<div class="row">
{% block content %}{% endblock %}
</div>

</body>

</html>
14 changes: 14 additions & 0 deletions masonite/snippets/auth/templates/auth/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends 'auth/base.html' %}

{% block content %}
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="panel-body">
This is a dashboard. Hello {{ Auth.user().name }}
</div>
</div>
</div>
</div>
{% endblock %}
30 changes: 30 additions & 0 deletions masonite/snippets/auth/templates/auth/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends 'auth/base.html' %}

{% block content %}
<div class="row">
<div class="col-xs-4 col-xs-offset-4">
<div class="panel panel-default">
<div class="panel-heading">Login</div>
<div class="panel-body">
<form action="/login" method="POST">
{{ csrf_field|safe }}

<div class="form-group">
<label for="">Username</label>
<input type="text" name="username" class="form-control">
</div>

<div class="form-group">
<label for="">Password</label>
<input type="password" name="password" class="form-control">
</div>

<div class="form-group text-center">
<button type="submit" class="btn btn-success">Login</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
Empty file.
33 changes: 33 additions & 0 deletions masonite/snippets/auth/templates/auth/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends 'auth/base.html' %}

{% block content %}
<div class="col-xs-4 col-xs-offset-4">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-body">
<form action="/register" method="POST">
{{ csrf_field|safe }}

<div class="form-group">
<label for="">Username</label>
<input type="text" name="name" class="form-control">
</div>

<div class="form-group">
<label for="">Email</label>
<input type="email" name="email" class="form-control">
</div>

<div class="form-group">
<label for="">Password</label>
<input type="password" name="password" class="form-control">
</div>

<div class="form-group text-center">
<button type="submit" class="btn btn-success">Register</button>
</div>
</form>
</div>
</div>
</div>
{% endblock %}

0 comments on commit af0b464

Please sign in to comment.