From 47aa3c8a4534aa3bb491c69ec6a08fcccada0b3a Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 8 May 2018 23:00:27 +1000 Subject: [PATCH 1/3] Login / Logout views Information found here - https://simpleisbetterthancomplex.com/tutorial/2016/06/27/how-to-use-djangos-built-in-login-system.html --- InvenTree/InvenTree/urls.py | 11 ++++++----- InvenTree/part/templates/part/category.html | 2 +- InvenTree/templates/registration/login.html | 10 ++++++++++ InvenTree/templates/registration/logout.html | 7 +++++++ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 InvenTree/templates/registration/login.html create mode 100644 InvenTree/templates/registration/logout.html diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 8c1d319531..1c0cc7cefe 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -1,5 +1,6 @@ from django.conf.urls import url, include from django.contrib import admin +from django.contrib.auth import views as auth_views from company.urls import company_urls @@ -34,9 +35,6 @@ apipatterns = [ ] urlpatterns = [ - - url(r'^api-doc/', include_docs_urls(title='InvenTree API')), - url(r'^part/', include(part_urls)), url(r'^supplier-part/', include(supplier_part_urls)), @@ -46,11 +44,14 @@ urlpatterns = [ url(r'^build/', include(build_urls)), - url(r'^admin/', admin.site.urls), - url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')), + url(r'^login/', auth_views.login, name='login'), + url(r'^logout/', auth_views.logout, name='logout'), + url(r'^admin/', admin.site.urls), + url(r'^api/', include(apipatterns)), + url(r'^api-doc/', include_docs_urls(title='InvenTree API')), ] # Static file access diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index 5b172f1b5e..84c86390c7 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -50,7 +50,7 @@ {% endblock %} {% block js_load %} {{ block.super }} - + {% endblock %} {% block js_ready %} {{ block.super }} diff --git a/InvenTree/templates/registration/login.html b/InvenTree/templates/registration/login.html new file mode 100644 index 0000000000..bb56433e74 --- /dev/null +++ b/InvenTree/templates/registration/login.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block content %} +

Login

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/registration/logout.html b/InvenTree/templates/registration/logout.html new file mode 100644 index 0000000000..ef4fcec632 --- /dev/null +++ b/InvenTree/templates/registration/logout.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} + +{% block content %} +

Logout

+

You have been logged out

+

Click here to log in

+{% endblock %} \ No newline at end of file From 3cf45f5ed3abaf56d1a1f86771a4ea2b624f8ed0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 8 May 2018 23:09:52 +1000 Subject: [PATCH 2/3] Added Login and Logout buttons to NavBar --- InvenTree/InvenTree/urls.py | 2 +- InvenTree/templates/navbar.html | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 1c0cc7cefe..ca4afc4e55 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -47,7 +47,7 @@ urlpatterns = [ url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')), url(r'^login/', auth_views.login, name='login'), - url(r'^logout/', auth_views.logout, name='logout'), + url(r'^logout/', auth_views.logout, {'template_name': 'registration/logout.html'}, name='logout'), url(r'^admin/', admin.site.urls), url(r'^api/', include(apipatterns)), diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index 449eb20533..5f6c1f750b 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -11,5 +11,17 @@
  • Build
  • Companies
  • + \ No newline at end of file From 84efaba9209cd6e927b1c5653cca9cf89118d4a7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 8 May 2018 23:14:07 +1000 Subject: [PATCH 3/3] Add link to admin page - Only if user is admin! --- InvenTree/InvenTree/urls.py | 2 +- InvenTree/templates/navbar.html | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index ca4afc4e55..07fbf9bca8 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -48,7 +48,7 @@ urlpatterns = [ url(r'^login/', auth_views.login, name='login'), url(r'^logout/', auth_views.logout, {'template_name': 'registration/logout.html'}, name='logout'), - url(r'^admin/', admin.site.urls), + url(r'^admin/', admin.site.urls, name='inventree-admin'), url(r'^api/', include(apipatterns)), url(r'^api-doc/', include_docs_urls(title='InvenTree API')), diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index 5f6c1f750b..830166ad2e 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -16,6 +16,9 @@