diff --git a/CalibreWebCompanion/CalibreWebCompanion/settings.py b/CalibreWebCompanion/CalibreWebCompanion/settings.py index 40a5ea8..5e06eef 100644 --- a/CalibreWebCompanion/CalibreWebCompanion/settings.py +++ b/CalibreWebCompanion/CalibreWebCompanion/settings.py @@ -15,6 +15,19 @@ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) CALIBRE_DIR = os.path.abspath("C:\\Users\\MassiveAtoms\\Documents\\Calibre Library") +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.0/howto/static-files/ + +STATICFILES_DIRS = [ + os.path.abspath(CALIBRE_DIR), + # '/static/', +] + +STATIC_URL = '/static/' + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ @@ -22,11 +35,20 @@ CALIBRE_DIR = os.path.abspath("C:\\Users\\MassiveAtoms\\Documents\\Calibre Libra # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'u(8^+rb%rz5hsx4v^^y(ul7g(4n7a8!db@s*9(m5cs*2_ppy8+' -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True ALLOWED_HOSTS = [] +#### Don't change things beyond this + + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + + + + + +LOGIN_REDIRECT_URL = '/books' # Application definition @@ -127,12 +149,3 @@ USE_L10N = True USE_TZ = True -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.0/howto/static-files/ - -STATICFILES_DIRS = [ - os.path.abspath(CALIBRE_DIR), - # '/static/', -] - -STATIC_URL = '/static/' diff --git a/CalibreWebCompanion/CalibreWebCompanion/urls.py b/CalibreWebCompanion/CalibreWebCompanion/urls.py index 64829d1..813db69 100644 --- a/CalibreWebCompanion/CalibreWebCompanion/urls.py +++ b/CalibreWebCompanion/CalibreWebCompanion/urls.py @@ -21,7 +21,8 @@ from django.views.generic import RedirectView urlpatterns = [ path('admin/', admin.site.urls), - path('library/', include('library.urls')), - path('', RedirectView.as_view(url='library/', permanent=True)), + path('accounts/', include('django.contrib.auth.urls')), + path('', include('library.urls')), + path('', RedirectView.as_view(url='books/', permanent=True)), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \ No newline at end of file diff --git a/CalibreWebCompanion/db.sqlite3 b/CalibreWebCompanion/db.sqlite3 index b92ca61..a609fcd 100644 Binary files a/CalibreWebCompanion/db.sqlite3 and b/CalibreWebCompanion/db.sqlite3 differ diff --git a/CalibreWebCompanion/library/static/css/styles.css b/CalibreWebCompanion/library/static/css/styles.css index 2a56dc8..2d8332c 100644 --- a/CalibreWebCompanion/library/static/css/styles.css +++ b/CalibreWebCompanion/library/static/css/styles.css @@ -1,78 +1,112 @@ - /* Fixed sidenav, full height */ - .sidenav { - height: 100%; - width: 200px; - position: fixed; - z-index: 1; - top: 0; - left: 0; - background-color: #111; - overflow-x: hidden; - padding-top: 20px; - } - - /* Style the sidenav links and the dropdown button */ - .sidenav a, .dropdown-btn { - padding: 6px 8px 6px 16px; - text-decoration: none; - font-size: 20px; - color: #818181; - display: block; - border: none; - background: none; - width:100%; - text-align: left; - cursor: pointer; - outline: none; - } - - /* On mouse-over */ - .sidenav a:hover, .dropdown-btn:hover { - color: #f1f1f1; - } - - /* Main content */ - .main { - margin-left: 200px; /* Same as the width of the sidenav */ - font-size: 20px; /* Increased text to enable scrolling */ - padding: 0px 10px; - } - - /* Add an active class to the active dropdown button */ - .active { - background-color: green; - color: white; - } - - /* Dropdown container (hidden by default). Optional: add a lighter background color and some left padding to change the design of the dropdown content */ - .dropdown-container { - display: none; - background-color: #262626; - padding-left: 8px; - } - - /* Optional: Style the caret down icon */ - .fa-caret-down { - float: right; - padding-right: 8px; - } +/* sidenav */ - table { - border-spacing: 0; - width: 100%; - border: 1px solid #ddd; - } - - th { - cursor: pointer; - } - - th, td { - text-align: left; - padding: 16px; - } - - tr:nth-child(even) { - background-color: #f2f2f2 - } \ No newline at end of file +/* Fixed sidenav, full height */ +.sidenav { + height: 100%; + width: 200px; + position: fixed; + z-index: 1; + top: 0; + left: 0; + background-color: #111; + overflow-x: hidden; + padding-top: 20px; +} + +/* Style the sidenav links and the dropdown button */ +.sidenav a, +.dropdown-btn { + padding: 6px 8px 6px 16px; + text-decoration: none; + font-size: 20px; + color: #818181; + display: block; + border: none; + background: none; + width: 100%; + text-align: left; + cursor: pointer; + outline: none; +} + +/* On mouse-over */ +.sidenav a:hover, +.dropdown-btn:hover { + color: #f1f1f1; +} + +/* Main content */ +.main { + margin-left: 200px; + /* Same as the width of the sidenav */ + font-size: 20px; + /* Increased text to enable scrolling */ + padding: 0px 10px; +} + +/* Add an active class to the active dropdown button */ +.active { + background-color: green; + color: white; +} + +/* Dropdown container (hidden by default). Optional: add a lighter background color and some left padding to change the design of the dropdown content */ +.dropdown-container { + display: none; + background-color: #262626; + padding-left: 8px; +} + +/* Optional: Style the caret down icon */ +.fa-caret-down { + float: right; + padding-right: 8px; +} + + +ul.topnav { + list-style-type: none; + margin: 0; + padding: 0; + overflow: hidden; + background-color: #333; +} + +.topnav li { + float: right; +} + +.topnav li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +.topnav li a:hover { + background-color: #111; +} + + +/* Table */ +table { + border-spacing: 0; + width: 100%; + border: 1px solid #ddd; +} + +th { + cursor: pointer; +} + +th, +td { + text-align: left; + padding: 16px; +} + +tr:nth-child(even) { + background-color: #f2f2f2 +} \ No newline at end of file diff --git a/CalibreWebCompanion/library/templates/base.html b/CalibreWebCompanion/library/templates/base.html index a1bc9ab..9199e18 100644 --- a/CalibreWebCompanion/library/templates/base.html +++ b/CalibreWebCompanion/library/templates/base.html @@ -13,6 +13,20 @@ + {% block topnav%} + + {% endblock %} + + {% if user.is_authenticated %}
@@ -138,6 +152,18 @@ } } + + {% else %} +

You don't have permission to view this.

+
  • Login
  • + or +
  • Sign up
  • + {% endif %} + + + + + \ No newline at end of file diff --git a/CalibreWebCompanion/library/templates/ifelselogin.html b/CalibreWebCompanion/library/templates/ifelselogin.html new file mode 100644 index 0000000..5188599 --- /dev/null +++ b/CalibreWebCompanion/library/templates/ifelselogin.html @@ -0,0 +1,6 @@ + {% if user.is_authenticated %} + + {% else %} +

    You don't have permission to view this.

    +
  • Login
  • + {% endif %} \ No newline at end of file diff --git a/CalibreWebCompanion/library/templates/registration/index.html b/CalibreWebCompanion/library/templates/registration/index.html new file mode 100644 index 0000000..ef19bfe --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/index.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} +{% block content %} + +

    Welcome {{user}}

    + +{% endblock %} \ No newline at end of file diff --git a/CalibreWebCompanion/library/templates/registration/logged_out.html b/CalibreWebCompanion/library/templates/registration/logged_out.html new file mode 100644 index 0000000..c0697a4 --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/logged_out.html @@ -0,0 +1,7 @@ +{% extends "stripped_base.html" %} + + {% block content %} +

    Logged out!

    + Click here to login again. +{% endblock %} + diff --git a/CalibreWebCompanion/library/templates/registration/login.html b/CalibreWebCompanion/library/templates/registration/login.html new file mode 100644 index 0000000..ac16faf --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/login.html @@ -0,0 +1,39 @@ +{% extends "stripped_base.html" %} + +{% block content %} + + {% if form.errors %} +

    Your username and password didn't match. Please try again.

    + {% endif %} + + {% if next %} + {% if user.is_authenticated %} +

    Your account doesn't have access to this page. To proceed, + please login with an account that has access.

    + {% else %} +

    Please login to see this page.

    + {% endif %} + {% endif %} + +
    + {% csrf_token %} + + + + + + + + + +
    {{ form.username.label_tag }}{{ form.username }}
    {{ form.password.label_tag }}{{ form.password }}
    + + +
    + + {# Assumes you setup the password_reset view in your URLconf #} +

    Lost password?

    + + + +{% endblock %} diff --git a/CalibreWebCompanion/library/templates/registration/password_reset_complete.html b/CalibreWebCompanion/library/templates/registration/password_reset_complete.html new file mode 100644 index 0000000..29c2099 --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/password_reset_complete.html @@ -0,0 +1,7 @@ +{% extends "stripped_base.html" %} +{% block content %} +

    The password has been changed!

    +

    log in again?

    +{% endblock %} + + diff --git a/CalibreWebCompanion/library/templates/registration/password_reset_confirm.html b/CalibreWebCompanion/library/templates/registration/password_reset_confirm.html new file mode 100644 index 0000000..c5eff65 --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/password_reset_confirm.html @@ -0,0 +1,28 @@ +{% extends "stripped_base.html" %} +{% block content %} + {% if validlink %} +

    Please enter (and confirm) your new password.

    +
    + {% csrf_token %} + + + + + + + + + + + + + +
    {{ form.new_password1.errors }} + {{ form.new_password1 }}
    {{ form.new_password2.errors }} + {{ form.new_password2 }}
    +
    + {% else %} +

    Password reset failed

    +

    The password reset link was invalid, possibly because it has already been used. Please request a new password reset.

    + {% endif %} +{% endblock %} diff --git a/CalibreWebCompanion/library/templates/registration/password_reset_done.html b/CalibreWebCompanion/library/templates/registration/password_reset_done.html new file mode 100644 index 0000000..ca093eb --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/password_reset_done.html @@ -0,0 +1,4 @@ +{% extends "stripped_base.html" %} +{% block content %} +

    We've emailed you instructions for setting your password. If they haven't arrived in a few minutes, check your spam folder.

    +{% endblock %} diff --git a/CalibreWebCompanion/library/templates/registration/password_reset_email.html b/CalibreWebCompanion/library/templates/registration/password_reset_email.html new file mode 100644 index 0000000..61fba5c --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/password_reset_email.html @@ -0,0 +1,2 @@ +Someone asked for password reset for email {{ email }}. Follow the link below: +{{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} \ No newline at end of file diff --git a/CalibreWebCompanion/library/templates/registration/password_reset_form.html b/CalibreWebCompanion/library/templates/registration/password_reset_form.html new file mode 100644 index 0000000..fafceb0 --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/password_reset_form.html @@ -0,0 +1,11 @@ +{% extends "stripped_base.html" %} +{% block content %} +
    + {% csrf_token %} + {% if form.email.errors %} + {{ form.email.errors }} + {% endif %} +

    {{ form.email }}

    + +
    +{% endblock %} diff --git a/CalibreWebCompanion/library/templates/registration/sign_up.html b/CalibreWebCompanion/library/templates/registration/sign_up.html new file mode 100644 index 0000000..d46cece --- /dev/null +++ b/CalibreWebCompanion/library/templates/registration/sign_up.html @@ -0,0 +1,13 @@ +{% extends "stripped_base.html" %} + +{% block content %} + +
    + {% csrf_token %} {{form.as_p}}
    + + + +{% endblock %} + + + diff --git a/CalibreWebCompanion/library/templates/stripped_base.html b/CalibreWebCompanion/library/templates/stripped_base.html new file mode 100644 index 0000000..80468ed --- /dev/null +++ b/CalibreWebCompanion/library/templates/stripped_base.html @@ -0,0 +1,41 @@ + + + + + {% block title %}Local Library{% endblock %} + + + + + {% load static %} + + + + + {% block topnav%} +
      + + {% if user.is_authenticated %} +
    • {{ user.get_username }}
    • +
    • Logout
    • + {% else %} +
    • Sign up
    • +
    • Login
    • + {% endif %} +
    + {% endblock %} + + + +
    +
    + +
    {% block content %}{% endblock %}
    +
    +
    + + + + + \ No newline at end of file diff --git a/CalibreWebCompanion/library/urls.py b/CalibreWebCompanion/library/urls.py index 188880e..6a5e2a1 100644 --- a/CalibreWebCompanion/library/urls.py +++ b/CalibreWebCompanion/library/urls.py @@ -19,5 +19,7 @@ urlpatterns = [ path('results/', views.ResultsView.as_view(), name='results'), path('search/', views.SearchView.as_view(), name='search'), + path('accounts/sign_up/',views.sign_up,name="sign-up") + ] \ No newline at end of file diff --git a/CalibreWebCompanion/library/views.py b/CalibreWebCompanion/library/views.py index c785d89..f6a174a 100644 --- a/CalibreWebCompanion/library/views.py +++ b/CalibreWebCompanion/library/views.py @@ -5,8 +5,28 @@ from django.http import HttpResponseRedirect from .forms import SearchForm from django.db import models from django.db.models import Q +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User +from django.contrib.auth import login +from django.contrib.auth.decorators import login_required +@login_required +def index(request): + return render(request,'accounts/index.html') + + +def sign_up(request): + context = {} + form = UserCreationForm(request.POST or None) + if request.method == "POST": + if form.is_valid(): + user = form.save() + login(request,user) + return render(request,'registration/index.html') + context['form']=form + return render(request,'registration/sign_up.html',context) + class SearchView(generic.TemplateView): template_name = 'search.html'