Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some tasks done #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions authentication/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!doctype html>
<html lang="en">

<head>
<title>Log in</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">

<!--Convert to an external stylesheet-->
<style>
html,
body {
height: 100%;
}

body {
background: black;
color: white;
display: flex;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
}

.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
color: #212121;
border: 4px solid #ff993b;
border-radius: 25px;
}

.form-signin .checkbox {
font-weight: 400;
}

.form-signin .form-floating:focus-within {
z-index: 2;
}

.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}

.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
</style>

</head>
<body class="text-center py-0" style="flex-direction:column;background-color:black">
<nav class="navbar navbar-expand-lg navbar-light bg-light w-100">
<div class="container-fluid">
<a class="navbar-brand" href="#">Library</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/store">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register/">Register</a>
</li>
</div>
</div>
</nav>
<div class="form-signin bg-dark">
<form method="POST" action="./">
{% csrf_token %}
<h1 class="h3 mb-3" style="color:white">Log In</h1>

<div class="form-floating" >
<input name='username' type="text" class="form-control" id="floatingInput" placeholder="username">
<label for="floatingInput">Username</label>
</div>
<div class="form-floating">
<input name='password' type="password" class="form-control" id="floatingPassword" placeholder="Password">
<label for="floatingPassword">Password</label>
</div>
<button class="w-100 btn btn-lg btn-light" type="submit">Sign in</button>
<p class="mt-5 mb-3 text-muted">&copy; 2020–2025</p>
</form>
</div>


<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous">
</script>
</body>

</html>
73 changes: 73 additions & 0 deletions authentication/templates/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<title>Register</title>
</head>
<body style='background-color:black'>

<!-- Optional JavaScript; choose one of the two! -->

<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
-->
<nav class="navbar navbar-expand-lg navbar-light bg-light w-100" style="padding: 10px">
<a class="navbar-brand" href="#">Library</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/store/">Home <span class="sr-only"></span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/">Log-in</a>
</li>
</ul>
</div>
</nav>


<form class="container my-4 py-5 bg-dark" style="border: 4px solid #ff993b; border-radius: 25px;" method="post" action="/registerform/">
{% csrf_token %}
<div class="mb-3 form-group">
<label for="username" class="form-label text-white">Username</label>
<input id="username" type="text" class="form-control" placeholder="Username" aria-label="Username"
aria-describedby="basic-addon1" name="username">
</div>


<div class="mb-3 form-group">
<label for="email" class="form-label text-white">Email</label>
<input id="email" name="email" type="text" class="form-control" placeholder="Email" id="basic-url" aria-describedby="basic-addon3">
</div>

<div class="mb-3 form-group">
<label for="firstname" class="form-label text-white">First name</label>
<input id="firstname" name="firstname" type="text" placeholder="Firstname" class="form-control" aria-label="Amount (to the nearest dollar)">
</div>

<div class="mb-3 form-group">
<label for="password" class="form-label text-white">Password</label>
<input id="password" name="password" type="password" placeholder="Password" class="form-control" aria-label="Amount (to the nearest dollar)">
</div>
<div class="mb-3 w-100" style="display:flex; align-items:center; justify-content:center;">
<button class="btn btn-primary" type="submit">Register</button>
</div>
</form>
</body>
</html>
9 changes: 9 additions & 0 deletions authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
from authentication.views import *

urlpatterns = [
path('register/',registerView,name='registeruser'),
path('',loginView,name='loginuser'),
path('logout/',logoutView,name='logoutuser'),
path('registerform/',registerform,name='registerform'),
]
31 changes: 27 additions & 4 deletions authentication/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
from django.shortcuts import render
from django.shortcuts import render,redirect
from django.contrib.auth import login,logout,authenticate
from django.contrib.auth.models import User
# Create your views here.


def loginView(request):
pass
if request.method == "POST":
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user is not None:
login(request,user)
return redirect("store/")
else:
return render(request,'login.html')
return render(request,'login.html')

def logoutView(request):
pass
logout(request)
return redirect("/")

def registerView(request):
pass
return render(request,'register.html')

def registerform(request):
if request.method=='POST':
name=request.POST.get('username')
email=request.POST.get('email')
firstname=request.POST.get('firstname')
password=request.POST.get('password')
user=User.objects.create_user(name,email,password)
user.first_name=firstname
user.save()
return redirect('/')
return render(request,'register.html')
4 changes: 2 additions & 2 deletions library/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'store',
'authentication',
'authentication.apps.AuthenticationConfig',
]

MIDDLEWARE = [
Expand All @@ -57,7 +57,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': ['BASE_DIR/authentication/templates', 'BASE_DIR/store/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down
5 changes: 4 additions & 1 deletion library/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
from django.conf import settings

urlpatterns = [
path('',include('store.urls')),
path('',include('authentication.urls')),
path('store/',include('store.urls')),
path('book/',include('store.urls')),
path('books/',include('store.urls')),
path('admin/', admin.site.urls),
path('accounts/',include('django.contrib.auth.urls')),
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
26 changes: 26 additions & 0 deletions store/migrations/0003_auto_20210724_1422.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.2.5 on 2021-07-24 14:22

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('store', '0002_auto_20190607_1302'),
]

operations = [
migrations.AlterField(
model_name='bookcopy',
name='borrow_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='bookcopy',
name='borrower',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='borrower', to=settings.AUTH_USER_MODEL),
),
]
18 changes: 18 additions & 0 deletions store/migrations/0004_book_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.5 on 2021-07-24 15:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('store', '0003_auto_20210724_1422'),
]

operations = [
migrations.AddField(
model_name='book',
name='number',
field=models.PositiveIntegerField(default=0),
),
]
18 changes: 18 additions & 0 deletions store/migrations/0005_rename_number_book_num_avail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.5 on 2021-07-24 15:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('store', '0004_book_number'),
]

operations = [
migrations.RenameField(
model_name='book',
old_name='number',
new_name='num_avail',
),
]
1 change: 1 addition & 0 deletions store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Book(models.Model):
description = models.TextField(null=True)
mrp = models.PositiveIntegerField()
rating = models.FloatField(default=0.0)
num_avail = models.PositiveIntegerField(default=0)

class Meta:
ordering = ('title',)
Expand Down
20 changes: 19 additions & 1 deletion store/templates/store/loaned_books.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@ <h3>Loaned Books list</h3>
<script>
// Fill in this function by yourself. It should make a post call to the returnBookView and display an appropriate message
function returnBook(bid){
;
$.ajax({
url: "{% url 'return-book' %}",
method: "POST",
data: {
book_id: bid
},
success: function(data, status, xhr){
if(data['message'] == "success"){
alert("Book successfully returned");
window.location.replace("/books");
}
else{
alert("Unable to return this book");
}
},
error: function(xhr, status, err){
alert("Some error occured");
}
})
}
</script>
{% endblock %}
8 changes: 4 additions & 4 deletions store/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
urlpatterns = [
path('', index, name="index"),
path('books/', bookListView, name="book-list"),
path('book/<int:bid>/', bookDetailView, name='book-detail' ),
path('books/loaned/', viewLoanedBooks, name="view-loaned"),
path('books/loan/', loanBookView, name="loan-book"),
path('books/return/', returnBookView, name="return-book"),
path('<int:bid>/', bookDetailView, name='book-detail' ),
path('loaned/', viewLoanedBooks, name="view-loaned"),
path('loan/', loanBookView, name="loan-book"),
path('return/', returnBookView, name="return-book"),
]
Loading