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

Module2 #137

Open
wants to merge 3 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
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>
15 changes: 15 additions & 0 deletions server/djangoapp/templates/djangoapp/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<body>
<div class="container">
<p class="contact center">
Contact information
</p>
<div class="contact center">
<ul><b>Phone No:</b> 555 834 6626</ul>
<ul><b>Email:</b> [email protected]"</ul>
<ul><b>Address:</b>1818 West Way Ct.</ul>
</div>
</div>
</body>
</html>
31 changes: 30 additions & 1 deletion server/djangoapp/templates/djangoapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,38 @@

<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-light bg-light">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{% url 'djangoapp:about' %}">About Us</a>
<a class="navbar-brand" href="{% url 'djangoapp:contact' %}">Contact Us</a>
<a class="navbar-brand" href="{% url 'djangoapp:index' %}">Dealerships</a>
</div>
<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li>
<a class="btn btn-link" href="#">{{ user.first_name }}({{ user.username }})</a>
<a class="btn btn-link" href="{% url 'djangoapp:logout' %}">Logout</a>
</li>
{% else %}
<li>
<form class="form-inline" action="{% url 'djangoapp:login_request'%}" 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="Password" >
<button class="btn btn-primary" type="submit">Login</button>
<a class="btn btn-link" href="{% url 'djangoapp:registration_request' %}">Sign Up</a>
</div>
</form>
</li>
{% endif %}
</ul>
</div>
</nav>

<!--Add a dealer table here -->

</body>
Expand Down
116 changes: 115 additions & 1 deletion server/djangoapp/templates/djangoapp/registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,122 @@
<meta charset="UTF-8">
{% load static %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
.register{
display: flex;
justify-content: center;
align-items: center;
/* background-color: aqua; */
gap: 10px;
}
.register-form{
padding: 20px;
box-shadow: rgba(0, 0, 0, 0.16) 0px 10px 36px 0px, rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;
border-radius: 10px;
}
.register-main
{
display: flex;
align-items: center;
justify-content: center;
padding:100px;
}
.login-div , .register-header{
display: flex;
align-items: center;
justify-content: center;
}
.register-label{
font-size: 20px;
font-weight: 400;
}
.register-1{
gap:6px;
}

</style>
</head>
<body>
<!--Add a registration form here -->
<div class="container register-main">
<div class="register-form">
<form method="post" action="{% url 'djangoapp:registration_request'%}">
{% csrf_token %}
<div class="register-header p-4">
<h1>Register</h1>
</div>
<hr/>
<div class="register">
<div>
<div>
<label class="form-label register-label">Email</label>
</div>
<div>
<input class="form-control" type="email" placeholder="Email" name="email"/>
</div>
</div>
<div>
<div>
<label class="form-label register-label">Username</label>
</div>
<div>
<input class="form-control" type="text" placeholder="Username" name="username" minlength="8" maxlength="12"/>
</div>
</div>
</div>
<div class="register">
<div>
<div>
<label class="form-label register-label">Password</label>
</div>
<div>
<input class="form-control" type="password" placeholder="Password" name="password" minlength="12" maxlength="20" id="password"/>
</div>
</div>
<div>
<div>
<label class="form-label register-label">Re-Enter Password</label>
</div>
<div>
<input class="form-control" type="password" placeholder="Password" name="password" minlength="12" maxlength="20" id="re-password"/>
</div>
</div>
</div>
<div class="register-1">
<div>

</div>
<div class="p-3">
<input type="checkbox" class="value1" onclick="showpassword( )"/>
<span>Show Password</span>
</div>
</div>
<div>
<button class="btn btn-primary form-control" >Submit</button>
</div>
<div class="login-div p-3">
<span>Already member?</span><a href="{% url 'djangoapp:index'%}">Sign In</a>
</div>
</form>
</div>
</div>
<script>
function showpassword(){
x = document.getElementById("password")
y = document.getElementById("re-password")
if(x.type == "password" || y.type === "password")
{
x.type = "text";
y.type = "text";
}
else{
x.type = "password";
y.type = "password";
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-Rx+T1VzGupg4BHQYs2gCW9It+akI2MM/mndMCy36UVfodzcJcF0GGLxZIzObiEfa" crossorigin="anonymous"></script>

</body>
</html>
5 changes: 5 additions & 0 deletions server/djangoapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@

# 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="register/", view=views.registration_request , name='registration_request'),
path(route="logout/" , view= views.logout_request, name="logout"),
path(route="login/",view=views.login_request,name="login_request"),

# path for login

Expand Down
58 changes: 50 additions & 8 deletions server/djangoapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,64 @@
# def about(request):
# ...


def about(request):
context={}
if request.method == 'GET':
return render(request , 'djangoapp/about.html' , context)
# Create a `contact` view to return a static contact page
#def contact(request):

def contact(request):
context={}
if request.method == 'GET':
return render(request , 'djangoapp/contact.html' , context)

# Create a `login_request` view to handle sign in request
# def login_request(request):
# ...
def login_request(request):
context = {}
if request.method == 'POST':
username = request.POST['Username']
password = request.POST['Password']

user = authenticate(username=username , password = password)
if user is not None:
login(request,user)
return render(request,"djangoapp/index.html",context)
else:
return render(request,"djangoapp/index.html",context)
else:
return render(request,"djangoapp/index.html",context)

# Create a `logout_request` view to handle sign out request
# def logout_request(request):
# ...
def logout_request(request):
print(f"User is logged out {request.user.username}")
logout(request)
return redirect("djangoapp:index")


# Create a `registration_request` view to handle sign up request
# def registration_request(request):
# ...

def registration_request(request):
context={}
if request.method == 'GET':
return render(request ,'djangoapp/registration.html',context)
elif request.method == "POST":
username = request.POST['username']
email = request.POST['email']
password = request.POST['password']
user_exits = False
try:
User.object.get(username=username)
user_exits = True
except:
logger.debug(f"{username} is a new user")
if not user_exits:
user = User.objects.create_user(username=username,password=password,email=email)
login(request,user)
return redirect('djangoapp:index')
else:
return render(request,'djangoapp/registration.html',context)
else:
return render(request,'djangoapp/registration.html',context)
# Update the `get_dealerships` view to render the index page with a list of dealerships
def get_dealerships(request):
context = {}
Expand Down