-
Notifications
You must be signed in to change notification settings - Fork 42
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
All Tasks Completed #16
Open
it-is-skywalkerl
wants to merge
4
commits into
COPS-IITBHU:master
Choose a base branch
from
it-is-skywalkerl:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django import forms | ||
from django.contrib.auth.models import User | ||
from django.contrib.auth.forms import UserCreationForm | ||
|
||
class RegisterForm(UserCreationForm): | ||
first_name = forms.CharField(max_length=30, help_text='Required') | ||
last_name = forms.CharField(max_length=30, required=False, help_text='Optional') | ||
email = forms.EmailField(max_length=100, help_text='Enter a valid email-id') | ||
|
||
class Meta: | ||
model = User | ||
fields = ('first_name', 'last_name', 'username', 'email', 'password1', 'password2') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
{% load static %} | ||
<html lang="en"> | ||
<head> | ||
{% block title %} | ||
<title>Authentication</title> | ||
{% endblock %} | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> | ||
<!-- <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://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> | ||
<!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script> --> | ||
</head> | ||
|
||
<body> | ||
<div class="wrapper"> | ||
<div class="form col-xs-10 col-sm-12 col-md-7" style="display: flex; justify-content:center "> | ||
{% block form %} | ||
{% endblock %} | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends "base.html" %} | ||
{% block title %} | ||
<title>Login</title> | ||
{% endblock %} | ||
|
||
{% block form %} | ||
<form action="{% url 'Login' %}" method="POST"> | ||
<h1 style="display: flex; justify-content:center;">Login</h1> | ||
{% csrf_token %} | ||
<div class="form-floating form-group mb-3"> | ||
<input type="text" class="form-control" id="username" name="Username" placeholder="Username" required> | ||
<label for="floatingInput">Username</label> | ||
</div> | ||
<div class="form-floating form-group"> | ||
<input type="password" class="form-control" id="password" name="Password" placeholder="Password" required> | ||
<label for="floatingPassword">Password</label> | ||
</div> | ||
<button type="login" class="btn btn-success mt-3 mb-2" value="Login">Login</button> | ||
<div style="color: red; text-align: center;"> | ||
{% if message %} | ||
{{message}} | ||
{% endif %} | ||
</div> | ||
<h6>Don't have an account? <a href="{% url 'Register' %}">Register</a></h6> | ||
<h6><a href="{% url 'book-list' %}">I just want to view the books</a></h6> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% extends "login.html" %} | ||
|
||
{% block title %} | ||
<title>Register</title> | ||
{% endblock %} | ||
|
||
{% block form %} | ||
<form action="{% url 'Register' %}" method="POST"> | ||
<h1 style="display: flex; justify-content:center;">Register</h1> | ||
{% csrf_token %} | ||
{% for field in form %} | ||
<p> | ||
{{ field.label_tag }} | ||
<br> | ||
{{ field }} | ||
{% if field.help_text %} | ||
<small style="color: rgb(185, 185, 185);">{{field.help_text}}</small> | ||
{% endif %} | ||
{% for error in field.errors %} | ||
<p style="color: red">{{ error }}</p> | ||
{% endfor %} | ||
</p> | ||
{% endfor %} | ||
<button type="submit" class="btn btn-primary">Register</button> | ||
<h6>Already have an account? <a href="{% url 'Login' %}">Login</a></h6> | ||
<h6><a href="{% url 'book-list' %}">I just want to view the books</a></h6> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path,include | ||
from authentication.views import * | ||
|
||
urlpatterns = [ | ||
path('login', loginView, name='Login'), | ||
path('register', registerView, name='Register'), | ||
path('logout', logoutView, name='logout'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,46 @@ | ||
from django.shortcuts import render | ||
from django.shortcuts import redirect,render | ||
from django.contrib.auth import login,logout,authenticate | ||
from django.contrib.auth.models import User | ||
from .forms import RegisterForm | ||
# Create your views here. | ||
|
||
|
||
def loginView(request): | ||
pass | ||
if request.user.is_authenticated: | ||
return redirect('index') | ||
|
||
if request.method == "POST": | ||
data = request.POST | ||
user = authenticate(request, username=data['Username'], password=data['Password']) | ||
if user is not None: | ||
login(request, user) | ||
return redirect('index') | ||
else: | ||
return render(request, 'templates/login.html', {'message': "Username and/or password incorrect"}) | ||
else: | ||
return render(request, 'templates/login.html') | ||
|
||
|
||
def logoutView(request): | ||
pass | ||
logout(request) | ||
return redirect('index') | ||
|
||
|
||
def registerView(request): | ||
pass | ||
if request.user.is_authenticated: | ||
return redirect('index') | ||
|
||
if request.method == "POST": | ||
form = RegisterForm(request.POST) | ||
if form.is_valid(): | ||
data = request.POST | ||
new_user = User.objects.create_user(data['username'], data['email'], data['password1']) | ||
new_user.first_name = data['first_name'] | ||
new_user.last_name = data['last_name'] | ||
new_user.save() | ||
login(request, new_user) | ||
return redirect('index') | ||
else: | ||
return render(request, 'templates/register.html', {'form': form}) | ||
else: | ||
return render(request, 'templates/register.html', {'form': RegisterForm()}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
admin.site.register(Book) | ||
admin.site.register(BookCopy) | ||
admin.site.register(BookRating) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 2.2.1 on 2021-07-20 12:27 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 2.2.1 on 2021-07-22 12:42 | ||
|
||
from django.conf import settings | ||
import django.core.validators | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('store', '0003_auto_20210720_1757'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='BookRating', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('rating', models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(10)])), | ||
('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='store.Book')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of validators here.