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

IBM #192

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

IBM #192

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
Binary file added server/db.sqlite3
Binary file not shown.
5 changes: 5 additions & 0 deletions server/djangoapp/templates/djangoapp/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<h1>
Welcome to Best Cars dealership, home to the best cars in North America. We sell domestic and imported cars at reasonable prices.
</h1>
</html>
6 changes: 6 additions & 0 deletions server/djangoapp/templates/djangoapp/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<h1>Address</h1>
<p>30 street departement 5</p>
<h1>Phone</h1>
<p>1111111111</p>
</html>
1 change: 1 addition & 0 deletions server/djangoapp/templates/djangoapp/djangotemplete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
49 changes: 45 additions & 4 deletions server/djangoapp/templates/djangoapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,57 @@
<link href="https://unpkg.com/[email protected]/dist/bootstrap-table.min.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
</head>

<body>
<!-- Remove this line the first time you edit this file -->
This is the index page of your Django app!
<!--Add a nav bar here -->

<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="#">Best Cars</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>

</ul>
<div class="w-100 text-end">
<ul class="nav navbar-nav navbar-right d-inline-block ">
{% if user.is_authenticated %}
<li>
<a class="btn btn-link">{{ user.first_name }}{{ user.username }}</a>
<a class="btn btn-link" href="logout">Logout</a>
</li>
{% else %}
<li>
<form class="form-inline" action="login" method="post">
{% csrf_token %}
<div class="input-group">
<input type="text" class="form-control" placeholder="Username" name="username" >
<input type="password" class="form-control" placeholder="Password" name="psw" >
<button class="btn btn-primary" type="submit">Login</button>
<a class="btn btn-link" href="registeration">Sign Up</a>
</div>
</form>
</li>
{% endif %}
</ul>
</div>
</div>
</nav>
<!--Add a dealer table here -->

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>

</html>
28 changes: 28 additions & 0 deletions server/djangoapp/templates/djangoapp/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{% load static %}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>

<form action="login" method="post">
{% csrf_token %}
<div class="container">
<h1>Login</h1>
<label for="username"><b>User Name</b></label>
<input class="form-control" type="text" placeholder="Enter User Name: " name="username" required>
<label for="psw"><b>Password</b></label>
<input class="form-control" type="password" placeholder="Enter Password: " name="psw" required>
<div>
<button class="button btn btn-primary mt-2" type="submit">Login</button>
</div>
</div>
</form>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>

</body>
</html>
25 changes: 23 additions & 2 deletions server/djangoapp/templates/djangoapp/registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@
<head>
<meta charset="UTF-8">
{% load static %}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<!--Add a registration form here -->
</body>
<form action="registeration" method="post">
<div class="container">
<h1>Sign Up</h1>
<hr>
<label for="username"><b>User Name</b></label>
<input class="form-control" type="text" placeholder="Enter User Name: " name="username" required>
<label for="firstname"><b>First Name</b></label>
<input class="form-control" type="text" placeholder="Enter First Name: " name="firstname" required>
<label for="lastname"><b>Last Name</b></label>
<input class="form-control" type="text" placeholder="Enter Last Name: " name="lastname" required>
<label for="psw"><b>Password</b></label>
<input class="form-control" type="password" placeholder="Enter Password: " name="psw" required>
<div>
{% csrf_token %}
<button class="button btn btn-primary mt-2" type="submit">Sign Up</button>
</div>
</div>
</form>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>

</body>
</html>
8 changes: 6 additions & 2 deletions server/djangoapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
# name the URL

# path for about view
path(route='about', view=views.about, name='about'),

# path for contact us view
path(route='contact', view=views.contact, name='contact'),

# path for registration
path(route='registeration', view=views.registration_request, name='registeration'),

# path for login
path(route='login', view=views.login_request, name='login'),

# path for logout

path(route='logout', view=views.logout_request, name='logout'),
path(route='', view=views.get_dealerships, name='index'),

path(route='django/', view=views.get_templete, name='django'),
# path for dealer reviews view

# path for add a review view
Expand Down
46 changes: 33 additions & 13 deletions server/djangoapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,47 @@

# Create your views here.


def get_templete(request):
return render (request,'djangoapp/djangotemplete.html')
# Create an `about` view to render a static about page
# def about(request):
# ...
def about(request):
return render (request,'djangoapp/about.html')


# Create a `contact` view to return a static contact page
#def contact(request):
def contact(request):
return render (request,'djangoapp/contact.html')

# Create a `login_request` view to handle sign in request
# def login_request(request):
# ...

def login_request(request):
if request.method == "POST":
username = request.POST['username']
password = request.POST['psw']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return redirect('/djangoapp/about')
else:
return render(request,'djangoapp/login.html')
else:
return render(request, 'djangoapp/login.html')
# Create a `logout_request` view to handle sign out request
# def logout_request(request):
# ...

def logout_request(request):
logout(request)
return redirect('/djangoapp/login')
# Create a `registration_request` view to handle sign up request
# def registration_request(request):
# ...

def registration_request(request):
if request.method == 'GET':
return render(request, 'djangoapp/registration.html')
elif request.method == 'POST':
username = request.POST['username']
password = request.POST['psw']
first_name = request.POST['firstname']
last_name = request.POST['lastname']
user = User.objects.create_user(username=username, first_name=first_name, last_name=last_name,
password=password)
return render(request, 'djangoapp/login.html')
return render(request, 'djangoapp/registration.html')
# Update the `get_dealerships` view to render the index page with a list of dealerships
def get_dealerships(request):
context = {}
Expand Down