From 64910bf6ff68848da7e5e494375fc211b3169ec2 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 19 Dec 2023 18:12:25 -0500 Subject: [PATCH 1/2] static pages --- server/db.sqlite3 | Bin 0 -> 131072 bytes .../djangoapp/templates/djangoapp/about.html | 5 +++++ .../djangoapp/templates/djangoapp/contact.html | 4 ++++ .../djangoapp/templates/djangoapp/index.html | 10 ++++++++-- server/djangoapp/urls.py | 4 ++++ server/djangoapp/views.py | 9 ++++++++- server/requirements.txt | 1 - 7 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 server/db.sqlite3 create mode 100644 server/djangoapp/templates/djangoapp/about.html create mode 100644 server/djangoapp/templates/djangoapp/contact.html diff --git a/server/db.sqlite3 b/server/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..820cf525de840e35532641da591c3a534753f6e8 GIT binary patch literal 131072 zcmeI5dyFH=UB}&a+n$H*n&=);CMVsFzCK;AtLj(3{??}+-SyD;+Uu8%jvn1>w(43Zn)b|iB+2t)H0tqq zPSgL{zt-mx{UTcd`mf~pe$>~~p6B2Apr09&|7A9c`Oi`2hz9`>009sH0T2KI5C8!X z009sH0TB4f6Ih%NQ>Sy&uX)H{kk60`S&95@a~?w}yJk6!NLWi!;>IMaxrCJ=m{k9bMgTHSa%A_w`oYFm(;}kk04w$qR&fc-8Wd z5L&9O=E440GE(_ev2Za$o!k&k5=Cc$YTB6PNoMke#0SFE(KX9a!Rd(M8HYzNCQ$t*dbS9gB zagzG5>N=5e`slG~?stY4B$rI(^A{$l2dl0VX{QIht{Jssnp`qd$QFy2g4BuCcoSCR zwcFY_ttOeyC32Zd0l#PM;+7L5qe%JIn|FJ7RmPV)9f~)Vp;ffw_j?qosZuu@)J0mQ zJZa6e9`JhB${pG_)xDZlRm-=UM)`=!PGpnm!j?>3QOd$q%627W(O%nRZilH!6qChb zCgGzl)_N{R4hVEKNG7wJUdoi_-~+4~q61m=CdjR}#!*DctZ#iHcf zw5;n!wWYB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EU$GR_4mtFWL1Zvp|&4)YWxaNVU?1Ms5)? zErd49LWp9)_l2p&nKhY-v67hz_WkJ)O!3m00ck)1V8`; sKmY_l00cnb1QNjf{{&VliUa~600JNY0w4eaAOHd&00JNY0xkmo4+r}9X#fBK literal 0 HcmV?d00001 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..8c7b4dfc63 --- /dev/null +++ b/server/djangoapp/templates/djangoapp/contact.html @@ -0,0 +1,4 @@ + +

email: email@email.com

+

phone: +1 985 2236 145

+ \ No newline at end of file diff --git a/server/djangoapp/templates/djangoapp/index.html b/server/djangoapp/templates/djangoapp/index.html index 1a9ee6e39a..d68a428257 100644 --- a/server/djangoapp/templates/djangoapp/index.html +++ b/server/djangoapp/templates/djangoapp/index.html @@ -14,9 +14,15 @@ - - This is the index page of your Django app! + diff --git a/server/djangoapp/urls.py b/server/djangoapp/urls.py index 37b1c89d01..7504c3bf6a 100644 --- a/server/djangoapp/urls.py +++ b/server/djangoapp/urls.py @@ -10,8 +10,12 @@ # name the URL # path for about view + path(route='about', view=views.about, name='About Us'), + # path for contact us view + path(route='contact', view=views.contact, name='Contact Us'), + # path for registration diff --git a/server/djangoapp/views.py b/server/djangoapp/views.py index 61cc664da0..4f1d94dea2 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -19,11 +19,18 @@ # Create an `about` view to render a static about page # 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): diff --git a/server/requirements.txt b/server/requirements.txt index 2851cca128..dc42689d89 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -1,6 +1,5 @@ requests Django==3.1.3 -Pillow==8.0.1 gunicorn==20.1.0 ibm-cloud-sdk-core==3.10.0 ibm-watson==5.2.2 From 07c3f6864695404dc8eb86a1f4a45e88c21abc7c Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Sun, 24 Dec 2023 14:49:41 -0500 Subject: [PATCH 2/2] task #2 --- server/db.sqlite3 | Bin 131072 -> 131072 bytes .../djangoapp/templates/djangoapp/index.html | 24 +++++++- .../templates/djangoapp/registration.html | 18 +++++- server/djangoapp/urls.py | 7 ++- server/djangoapp/views.py | 58 +++++++++++++++++- 5 files changed, 99 insertions(+), 8 deletions(-) diff --git a/server/db.sqlite3 b/server/db.sqlite3 index 820cf525de840e35532641da591c3a534753f6e8..f75d540c1b8c0cba19a994a6bf661aae17c205ee 100644 GIT binary patch delta 294 zcmZo@;Am*zm>|ulF;T{uQDb9*ojxPy=K1=m25gM{kqrEi8yo%k>l;-Vc^Mit9XTa= zwK+K*c?*)VQ__s$i!&09OwCk`49yG-3{+eSf{F`_vy#0lQYux-eY4#H49hJ-D)n~q30LF7tiU0rr delta 55 zcmV-70LcG2pQun>aK Nw$K3xAhQU7_zx5Y6yN{= diff --git a/server/djangoapp/templates/djangoapp/index.html b/server/djangoapp/templates/djangoapp/index.html index d68a428257..f080196ed0 100644 --- a/server/djangoapp/templates/djangoapp/index.html +++ b/server/djangoapp/templates/djangoapp/index.html @@ -18,9 +18,29 @@ diff --git a/server/djangoapp/templates/djangoapp/registration.html b/server/djangoapp/templates/djangoapp/registration.html index ae11ea4b71..4c4eba58f0 100644 --- a/server/djangoapp/templates/djangoapp/registration.html +++ b/server/djangoapp/templates/djangoapp/registration.html @@ -6,6 +6,22 @@ - +
+
+

Sign Up

+
+ + + + + + + + +
+ {% csrf_token %} + +
+
\ No newline at end of file diff --git a/server/djangoapp/urls.py b/server/djangoapp/urls.py index 7504c3bf6a..a14f2412c0 100644 --- a/server/djangoapp/urls.py +++ b/server/djangoapp/urls.py @@ -14,18 +14,21 @@ # path for contact us view - path(route='contact', view=views.contact, name='Contact Us'), + path(route='contact', view=views.contact, name='contact'), # path for registration + path('registration/', views.registration_request, name='registration'), # path for login + path('login/', views.login_request, name='login'), # path for logout + path('logout/', views.logout_request, name='logout'), + # path for dealer reviews view path(route='', view=views.get_dealerships, name='index'), - # path for dealer reviews view # path for add a review view diff --git a/server/djangoapp/views.py b/server/djangoapp/views.py index 4f1d94dea2..fd80e41ddb 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -34,15 +34,67 @@ def contact(request): # Create a `login_request` view to handle sign in request # def login_request(request): -# ... +def login_request(request): + context = {} + # Handles POST request + if request.method == "POST": + # Get username and password from request.POST dictionary + username = request.POST['username'] + password = request.POST['psw'] + # Try to check if provide credential can be authenticated + user = authenticate(username=username, password=password) + if user is not None: + # If user is valid, call login method to login current user + login(request, user) + return redirect('djangoapp:contact') + else: + # If not, return to login page again + 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): + # Get the user object based on session id in request + print("Log out the user `{}`".format(request.user.username)) + # Logout user in the request + logout(request) + # Redirect user back to course list view + return redirect('djangoapp:index') # Create a `registration_request` view to handle sign up request # def registration_request(request): -# ... +def registration_request(request): + context = {} + # If it is a GET request, just render the registration page + if request.method == 'GET': + return render(request, 'djangoapp/registration.html', context) + # If it is a POST request + elif request.method == 'POST': + # Get user information from request.POST + username = request.POST['username'] + password = request.POST['psw'] + first_name = request.POST['firstname'] + last_name = request.POST['lastname'] + user_exist = False + try: + # Check if user already exists + User.objects.get(username=username) + user_exist = True + except: + # If not, simply log this is a new user + logger.debug("{} is new user".format(username)) + # If it is a new user + if not user_exist: + # Create user in auth_user table + user = User.objects.create_user(username=username, first_name=first_name, last_name=last_name, + password=password) + # Login the user and redirect to course list page + login(request, user) + return redirect("djangoapp:popular_course_list") + else: + return render(request, 'djangoapp/user_registration.html', context) # Update the `get_dealerships` view to render the index page with a list of dealerships def get_dealerships(request):