From a72f39863a25840b6ed1cd1281778d17892bc2fa Mon Sep 17 00:00:00 2001 From: Raelon Masters Date: Sat, 18 Jul 2020 20:10:16 -0400 Subject: [PATCH] User login, logut & register functions now 100% operable --- src/interface/templates/index.html | 14 +++++++------- src/interface/views.py | 22 ++++++++++------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/interface/templates/index.html b/src/interface/templates/index.html index 50eeccf..d6a983c 100755 --- a/src/interface/templates/index.html +++ b/src/interface/templates/index.html @@ -26,12 +26,6 @@
- -
- - -
-
diff --git a/src/interface/views.py b/src/interface/views.py index 4dd1f1d..19405e0 100755 --- a/src/interface/views.py +++ b/src/interface/views.py @@ -8,9 +8,10 @@ from django.http import JsonResponse from django.shortcuts import HttpResponse, render, redirect # render_to_response from django.utils.text import slugify from django.contrib.auth import login, authenticate, logout +from django.contrib.auth.models import User import json from .forms import SignUpForm, UserLoginForm -from .models import Books, Collections, Navigation +from .models import Books, Collections, Navigation, Favorites config = Config(Path("../")) @@ -50,14 +51,16 @@ def userlogin(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) - if user is not None: return redirect('home') - else: form = UserLoginForm() + if user is not None: + login(request, user) + return redirect('home') + form = UserLoginForm() return render(request, 'login.html', {'form': form}) def userlogout(request): logout(request) - return render(request, 'login.html', {'form': UserLoginForm()}) + return redirect('home') def home(request, query=None, _set=1, _limit=None, _order='title'): @@ -211,15 +214,10 @@ def download(request, pk): def favorite(request, pk): """ - Favorite book by primary key + Add book to favorites bu primary key """ _book = Books.objects.all().filter(pk=pk)[0] - _fn = hr_name(_book) - response = HttpResponse( - open(os.path.abspath(_book.file_name), "rb"), content_type="application/zip" - ) - response["Content-Disposition"] = "attachment; filename=%s" % _fn - return response + print(Favorite(book=_book, uname=User)) def share(request, pk): @@ -390,6 +388,6 @@ def payload(request, query, _set, _limit, _order, **kwargs): "NowShowing": _now_showing, "PostedSearch": query, "SearchLen": _r_len, - "Order": _order + "Order": _order, }