diff --git a/server/db.sqlite3 b/server/db.sqlite3 new file mode 100644 index 0000000000..46df19cc21 Binary files /dev/null and b/server/db.sqlite3 differ diff --git a/server/djangoapp/templates/djangoapp/about.html b/server/djangoapp/templates/djangoapp/about.html new file mode 100644 index 0000000000..bb525d5275 --- /dev/null +++ b/server/djangoapp/templates/djangoapp/about.html @@ -0,0 +1,5 @@ + +

+Welcome to Best Cars dealership, home to the best cars in North America. We sell domestic and imported cars at reasonable prices. +

+ \ No newline at end of file diff --git a/server/djangoapp/templates/djangoapp/contact.html b/server/djangoapp/templates/djangoapp/contact.html new file mode 100644 index 0000000000..289c139c79 --- /dev/null +++ b/server/djangoapp/templates/djangoapp/contact.html @@ -0,0 +1,15 @@ + + + +
+

+ Contact information +

+
+ + + +
+
+ + \ No newline at end of file diff --git a/server/djangoapp/templates/djangoapp/index.html b/server/djangoapp/templates/djangoapp/index.html index 1a9ee6e39a..3ac27784ea 100644 --- a/server/djangoapp/templates/djangoapp/index.html +++ b/server/djangoapp/templates/djangoapp/index.html @@ -15,9 +15,38 @@ - This is the index page of your Django app! + + diff --git a/server/djangoapp/templates/djangoapp/registration.html b/server/djangoapp/templates/djangoapp/registration.html index ae11ea4b71..fc1d36d174 100644 --- a/server/djangoapp/templates/djangoapp/registration.html +++ b/server/djangoapp/templates/djangoapp/registration.html @@ -4,8 +4,122 @@ {% load static %} + - +
+
+
+ {% csrf_token %} +
+

Register

+
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+ + Show Password +
+
+
+ +
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/server/djangoapp/urls.py b/server/djangoapp/urls.py index 37b1c89d01..92b1f162e5 100644 --- a/server/djangoapp/urls.py +++ b/server/djangoapp/urls.py @@ -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 diff --git a/server/djangoapp/views.py b/server/djangoapp/views.py index 61cc664da0..eb1636d552 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -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 = {}