diff --git a/MANIFEST.in b/MANIFEST.in index b7bd30fcb..5c910c935 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,4 @@ include masonite/snippets/exceptions/css/* -include masonite/snippets/* \ No newline at end of file +include masonite/snippets/* +include masonite/snippets/auth/controllers/* +include masonite/snippets/auth/templates/auth/* \ No newline at end of file diff --git a/masonite/commands/AuthCommand.py b/masonite/commands/AuthCommand.py index 7438f45f3..0e75011a8 100644 --- a/masonite/commands/AuthCommand.py +++ b/masonite/commands/AuthCommand.py @@ -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') diff --git a/masonite/snippets/auth/controllers/HomeController.py b/masonite/snippets/auth/controllers/HomeController.py new file mode 100644 index 000000000..c9a50b71c --- /dev/null +++ b/masonite/snippets/auth/controllers/HomeController.py @@ -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)}) diff --git a/masonite/snippets/auth/controllers/LoginController.py b/masonite/snippets/auth/controllers/LoginController.py new file mode 100644 index 000000000..91554d339 --- /dev/null +++ b/masonite/snippets/auth/controllers/LoginController.py @@ -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') diff --git a/masonite/snippets/auth/controllers/RegisterController.py b/masonite/snippets/auth/controllers/RegisterController.py new file mode 100644 index 000000000..bd574ef33 --- /dev/null +++ b/masonite/snippets/auth/controllers/RegisterController.py @@ -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') diff --git a/masonite/snippets/auth/templates/auth/base.html b/masonite/snippets/auth/templates/auth/base.html new file mode 100644 index 000000000..8045619d7 --- /dev/null +++ b/masonite/snippets/auth/templates/auth/base.html @@ -0,0 +1,46 @@ + + + + + + + + {{ app.name }} + + + + + + + + + +
+ {% block content %}{% endblock %} +
+ + + + \ No newline at end of file diff --git a/masonite/snippets/auth/templates/auth/home.html b/masonite/snippets/auth/templates/auth/home.html new file mode 100644 index 000000000..1ce89218b --- /dev/null +++ b/masonite/snippets/auth/templates/auth/home.html @@ -0,0 +1,14 @@ +{% extends 'auth/base.html' %} + +{% block content %} +
+
+
+
Dashboard
+
+ This is a dashboard. Hello {{ Auth.user().name }} +
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/masonite/snippets/auth/templates/auth/login.html b/masonite/snippets/auth/templates/auth/login.html new file mode 100644 index 000000000..dc593ef73 --- /dev/null +++ b/masonite/snippets/auth/templates/auth/login.html @@ -0,0 +1,30 @@ +{% extends 'auth/base.html' %} + +{% block content %} +
+
+
+
Login
+
+
+ {{ csrf_field|safe }} + +
+ + +
+ +
+ + +
+ +
+ +
+
+
+
+
+
+{% endblock %} diff --git a/masonite/snippets/auth/templates/auth/nav.html b/masonite/snippets/auth/templates/auth/nav.html new file mode 100644 index 000000000..e69de29bb diff --git a/masonite/snippets/auth/templates/auth/register.html b/masonite/snippets/auth/templates/auth/register.html new file mode 100644 index 000000000..1b9b4e971 --- /dev/null +++ b/masonite/snippets/auth/templates/auth/register.html @@ -0,0 +1,33 @@ +{% extends 'auth/base.html' %} + +{% block content %} +
+
+
Register
+
+
+ {{ csrf_field|safe }} + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file