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

Django Task Complete #7

Open
wants to merge 8 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
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sqlparse = "==0.3.0"
Django = "==2.2.1"
gunicorn = "*"
django-heroku = "*"
psycopg2 = "*"

[requires]
python_version = "3.8"
python_version = "3.8.10"
42 changes: 20 additions & 22 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions authentication/templates/store/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<html>
<head>

{% block title %}
<title>Library</title>
{% endblock %}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
{% load static %}
</head>

<body>

<div class="container-fluid">

<div class="row">
<div class="col-sm-2">
{% block sidebar %}
<ul class="sidebar-nav">
<li><a href="{% url 'index' %}">Home</a></li>
<li><a href="{% url 'book-list' %}">All books</a></li>
</ul>

<ul class="sidebar-nav">
{% if user.is_authenticated %}
<li>User: {{ user.first_name }}</li>
<li><a href="{% url 'view-loaned' %}">My Borrowed</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'login'%}">Login</a></li>
<li><a href="{% url 'register'%}">Register</a></li>
{% endif %}
</ul>


{% endblock %}
</div>
<div class="col-sm-10 ">
{% block content %}{% endblock %}
</div>
</div>

</div>
</body>
</html>
27 changes: 27 additions & 0 deletions authentication/templates/store/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "store/base.html" %}
{% block title %}
<title>LOGIN</title>
{% endblock %}

{% block content %}
<h3>LOGIN</h3>
<form method="POST" action="/accounts/login/">{% csrf_token %}
<div class="row">
<div class="col-sm-3">
Username : <input type="text" name="username" id="username">
</div>
</div>
<br>
<div class="row">
<div class="col-sm-3">
Password : <input type="password" name="password" id="password">
</div>
</div>
<br>

<div class="row">
<div class="col-1"></div>
<button class="btn btn-primary col-1" id="login-button" type="submit">Login</button>
</div>
</form>
{% endblock %}
27 changes: 27 additions & 0 deletions authentication/templates/store/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "store/base.html" %}

{% block title %}
<title>REGISTER</title>
{% endblock %}
{% block content %}
<h3>REGISTER</h3>

<form method="POST" action="/accounts/register/">{% csrf_token %}
<div class="row">
<div class="col-sm-3">
Username : <input type="text" name="username" id="username">
</div>
</div>
<br>
<div class="row">
<div class="col-sm-3">
Password : <input type="password" name="password" id="password">
</div>
</div>
<br>
<div class="row">
<div class="col-1"></div>
<button class="btn btn-primary col-1" id="register-button" type="submit">Register</button>
</div>
</form>
{% endblock %}
8 changes: 8 additions & 0 deletions authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from authentication.views import *

urlpatterns = [
path('login/', loginView, name="login"),
path('logout/', logoutView, name="logout"),
path('register/', registerView, name="register"),
]
41 changes: 36 additions & 5 deletions authentication/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
from django.shortcuts import render
from django.contrib.auth import login,logout,authenticate
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')
print(username)
user = authenticate(username=username, password=password)
if (user is not None):
login(request, user)
return redirect('/')
return redirect('/accounts/login')

return render(request, 'store/login.html')


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


def registerView(request):
pass

if (request.method == 'POST'):

username = request.POST.get('username')
password = request.POST.get('password')

if (User.objects.filter(username=username).exists()):
return redirect('/accounts/register')

user = User.objects.create_user(
username=username, password=password)
user.save()
loggedIn = authenticate(username=username, password=password)
login(request, loggedIn)
return redirect('/')

return render(request, 'store/register.html')
10 changes: 6 additions & 4 deletions library/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
SECRET_KEY = '==e^87*tib$+f)9$46#-jc&toydks5v^g5ym7wq^shf5(hno3&'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['https://django-library-task.herokuapp.com/','127.0.0.1']


# Application definition
Expand All @@ -44,6 +44,7 @@

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -108,13 +109,13 @@

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Kolkata'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good that you updated timezone.


USE_I18N = True

USE_L10N = True

USE_TZ = True
USE_TZ = False


# Static files (CSS, JavaScript, Images)
Expand All @@ -127,3 +128,4 @@

# Activate Django-Heroku.
django_heroku.settings(locals())

2 changes: 1 addition & 1 deletion library/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
urlpatterns = [
path('',include('store.urls')),
path('admin/', admin.site.urls),
path('accounts/',include('django.contrib.auth.urls')),
path('accounts/',include('authentication.urls')),
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Loading