From b523f5ff1d9ab2306d131e0f611f1678663ddff0 Mon Sep 17 00:00:00 2001 From: MarekAtGitHub Date: Mon, 16 Oct 2023 11:28:39 -0400 Subject: [PATCH 01/14] first test --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cdd50e544e..974ea42dc6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Final Project Template -The final project for this course has several steps that you must complete. +Thhe final project for this course has several steps that you must complete. To give you an overview of the whole project, all the high-level steps are listed below. The project is then divided into several smaller labs that give the detailed instructions for each step. You must complete all the labs to successfully complete the project. From 5ab3a9291c7a2209fa97563cc03925d66298ed58 Mon Sep 17 00:00:00 2001 From: MarekAtGitHub Date: Mon, 16 Oct 2023 12:51:48 -0400 Subject: [PATCH 02/14] First LAbss --- server/db.sqlite3 | Bin 0 -> 131072 bytes .../djangoapp/templates/djangoapp/about.html | 12 +++++++++ .../templates/djangoapp/contact.html | 12 +++++++++ .../djangoapp/templates/djangoapp/index.html | 24 +++++++++++++++--- server/djangoapp/urls.py | 7 ++++- server/djangoapp/views.py | 9 ++++--- 6 files changed, 57 insertions(+), 7 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..f3fd6c711d48891096efa15f6a437f013369ef0a GIT binary patch literal 131072 zcmeI5dyFH=UB}&a+n$H*n&o2>wU{D1Ri85C|ba5I_kMk0AK#04WIqLH>Y9 zR8?2I+ij1>x5-Jjqpwfb>#F+IufO%FM|V9mzW&A)vu(t88_k;Dj%R#RK1uSu6p#CS zzSH!7_OJc9Ouxu>fc`7Fz904VwC{y8Ukoy1^1sYRvHm&A9PuCk0w4eaAOHd&00JNY z0w4eaAOHeCdIIyaQR;MN@^v5i6Y@DyAxp8pjr~&W<>(KhUya_6W+U%J-j4iqWP0)& zlaH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yh8MXt|MWA(+LkmoTM5_>Yt zSQ&&)PX?jYogq0*Gpy!ZYPnwU3q4K(vlXJ8 z$mc_rwNU0HFl!;tiF__dt&^&sX>?+lDHH0%JSzu%&{s5$7@I z1Jr6YCxp7~giOcM&n<;Wx22HSwM + + + + About Us - Dealership Review + + +

Welcome to Best Cars dealership

+

Home to the best cars in North America. We sell domestic and imported cars at reasonable prices.

+ + + diff --git a/server/djangoapp/templates/djangoapp/contact.html b/server/djangoapp/templates/djangoapp/contact.html new file mode 100644 index 0000000000..36c92577d8 --- /dev/null +++ b/server/djangoapp/templates/djangoapp/contact.html @@ -0,0 +1,12 @@ + + + + + Contact Us - Dealership Review + + +

Contact Us

+

Address: 123 Street, City, Country

+

Telephone: +1-123-456-7890

+ + diff --git a/server/djangoapp/templates/djangoapp/index.html b/server/djangoapp/templates/djangoapp/index.html index 1a9ee6e39a..348b5bcb7b 100644 --- a/server/djangoapp/templates/djangoapp/index.html +++ b/server/djangoapp/templates/djangoapp/index.html @@ -14,10 +14,28 @@ - - This is the index page of your Django app! + - + diff --git a/server/djangoapp/urls.py b/server/djangoapp/urls.py index 37b1c89d01..772c2b913e 100644 --- a/server/djangoapp/urls.py +++ b/server/djangoapp/urls.py @@ -9,9 +9,14 @@ # view refers to the view function # name the URL + # path for index + path(route='', view=views.index, name='index'), + # 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 @@ -19,7 +24,7 @@ # path for logout - path(route='', view=views.get_dealerships, name='index'), + path(route='', view=views.get_dealerships, name='get_dealership'), # path for dealer reviews view diff --git a/server/djangoapp/views.py b/server/djangoapp/views.py index 61cc664da0..0d025be2c4 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -16,14 +16,17 @@ # Create your views here. +def index(request): + return render(request, 'djangoapp/index.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): From be61e42335d31d0994a4ad8039cd31eb1032aad5 Mon Sep 17 00:00:00 2001 From: MarekAtGitHub Date: Mon, 16 Oct 2023 18:11:15 -0400 Subject: [PATCH 03/14] week number 2 --- server/db.sqlite3 | Bin 131072 -> 131072 bytes .../djangoapp/templates/djangoapp/index.html | 26 +++++++++++ .../djangoapp/templates/djangoapp/login.html | 15 ++++++ .../djangoapp/templates/djangoapp/logout.html | 11 +++++ .../templates/djangoapp/registration.html | 33 +++++++++++-- server/djangoapp/urls.py | 4 ++ server/djangoapp/views.py | 44 ++++++++++++++++-- 7 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 server/djangoapp/templates/djangoapp/login.html create mode 100644 server/djangoapp/templates/djangoapp/logout.html diff --git a/server/db.sqlite3 b/server/db.sqlite3 index f3fd6c711d48891096efa15f6a437f013369ef0a..ce3dc00181d552e23ee76481a9f8abe2e7bf8a0a 100644 GIT binary patch delta 2523 zcmc(hON`r86o%t*gJyMM_JnQUv14zP|E3vVVQ&KgYg) zee?SD&37*%ADujVfP8d%?c>W&eHeNSb3@oK*mu}hn2WuQeTvOa7uT>G?v?1vp-||F z<+(N@JLqMk>r96o$L>wg-7rcZAG|O`p1k?(6&!4%J5Pr&Y3H+@r%xB#JHcWXjf57j z#5XTRBAZ+Bh$ZW4A9n0v7gBT-;xqsts>PLhHYXj$QxhU8q}!k^aN~+KoFx;QPtV_oJln&1gKMi2m};o>Fa zw#?ngl?TeKNLIc$&S~>9X+?>KBC%E1gEc4U1EN|h9k$2KBZ?J)QIjUAM6>kjGz|s6 zko4|Ci1Q@N<4lajwdJ{f*1i<0GaKjNl@&k5cV7P>+-T1H+Qdn zgS~hjy@cFJh=y*X&mgy-w6TfqZmpJ)n}~&8xDejH5!(4a^7;999v^Ps*rHDt(Jf@- zgA)b0a`J9;1Nre}VQwJi$>RNBQ3;0&$3$Glhl--8hIMo_F@1{B$DpnsEj!4<| zdVa1iHyd*Wrp>lg&`MfPZsMLM;oMk(oFhTpP>ABN4I4^U^SpdAi|5mxR?Bea@}8c} zaJYJqn5)g=VOuKB+h)U-1wC-2gPbZ=a~zM4?S?_}dA4nJ#4NSnA(GBCZcOdN18>TZ z1=^y^#k@N85}dCM%A8#I6CnXsu3aK$V+0FW$Q|#U3m4w3$A`Y+o2)%NRA}3BjCq&z z38)x-;Eui= z`WdHsyT`XiE~C;teLimWGM!n;(zTAuTHRs1BlR-gQ9dV>L91L&<&9#pA@z{UFDfqjf{u!rMk)Ml11J4>Q zVKVH`1QklK(Xg4BYZb@)B{IOf?X=SLGKqRE4ekMj^MHv_fTjU^ytlF9#MqoO0bL*Z z<3n@Q^;o^zl?|v)l%73=)cjF71^>389+6XU$57=dZ_E>%Baoz7rwprVw6ld~Dxov` z)uce-+*xPQfD~$Rcmrq$DNd> z!@C+3;7OdPmOUQFah5yl@nK8|oyWe!1Z;%;fW3#kce;22LvkmJ7lJ5SKpxhS!)HMc zYjEezf*w}f=vmOZv-$g3dt(nRY&|TmXCI*7FCX9f;udo5`3qsJAHsgdzQ#Vm-opA= z=5#@0$m=KZi@|ef99gfn8KsOKAM!*80ouPR$<+ CfcNJB delta 126 zcmZo@;Am*zm>|t4JyFJ)QF>#-B6*P&3~c;m4E!(ouki2YFXQj#pT%FXu`z*va+$u0 z8V?_{JV#<_Nk)8WacU6*1A{OSBLi_(W@E Contact Us + + + + + + diff --git a/server/djangoapp/templates/djangoapp/login.html b/server/djangoapp/templates/djangoapp/login.html new file mode 100644 index 0000000000..e79cf2681c --- /dev/null +++ b/server/djangoapp/templates/djangoapp/login.html @@ -0,0 +1,15 @@ + + + + + Login + + +

Login

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ + diff --git a/server/djangoapp/templates/djangoapp/logout.html b/server/djangoapp/templates/djangoapp/logout.html new file mode 100644 index 0000000000..7db12df29c --- /dev/null +++ b/server/djangoapp/templates/djangoapp/logout.html @@ -0,0 +1,11 @@ + + + + + Logout + + +

Logout

+

You have been successfully logged out. Thank you for visiting.

+ + diff --git a/server/djangoapp/templates/djangoapp/registration.html b/server/djangoapp/templates/djangoapp/registration.html index ae11ea4b71..d6cadba3b4 100644 --- a/server/djangoapp/templates/djangoapp/registration.html +++ b/server/djangoapp/templates/djangoapp/registration.html @@ -5,7 +5,32 @@ {% load static %} - - - - \ No newline at end of file + + +

Sign Up :)

+
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + diff --git a/server/djangoapp/urls.py b/server/djangoapp/urls.py index 772c2b913e..afea77f5b7 100644 --- a/server/djangoapp/urls.py +++ b/server/djangoapp/urls.py @@ -19,11 +19,15 @@ path(route='contact/', view=views.contact, name='contact'), # path for registration + path(route='registration/', view=views.signup, name='registration'), # path for login + path(route='login/', view=views.login_request, name='login_view'), # path for logout + path(route='logout/', view=views.logout_request, name='logout'), + path(route='', view=views.get_dealerships, name='get_dealership'), # path for dealer reviews view diff --git a/server/djangoapp/views.py b/server/djangoapp/views.py index 0d025be2c4..22d49e493f 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -1,10 +1,12 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect from django.http import HttpResponseRedirect, HttpResponse from django.contrib.auth.models import User from django.shortcuts import get_object_or_404, render, redirect # from .models import related models # from .restapis import related methods from django.contrib.auth import login, logout, authenticate +from django.contrib.auth.forms import AuthenticationForm, UserCreationForm +from django.contrib.auth.decorators import login_required # For authentication checks from django.contrib import messages from datetime import datetime import logging @@ -31,14 +33,46 @@ def contact(request): # Create a `login_request` view to handle sign in request # def login_request(request): # ... +def login_request(request): + if request.method == 'POST': + form = AuthenticationForm(data=request.POST) + if form.is_valid(): + username = form.cleaned_data.get('username') + password = form.cleaned_data.get('password') + user = authenticate(request, username=username, password=password) + if user is not None: + login(request, user) + messages.success(request, "Logged in successfully.") + return redirect('djangoapp:index') # Redirect to the home page after successful login + else: + messages.error(request, "Invalid login credentials. Please try again.") + else: + form = AuthenticationForm() + + return render(request, 'djangoapp/login.html', {'form': form}) # Create a `logout_request` view to handle sign out request -# def logout_request(request): -# ... - +def logout_request(request): + logout(request) + messages.success(request, "Logged out successfully.") + return render(request, 'djangoapp/logout.html') # Create a `registration_request` view to handle sign up request # def registration_request(request): -# ... + +def signup(request): + if request.method == 'POST': + form = UserCreationForm(request.POST) + if form.is_valid(): + form.save() + username = form.cleaned_data.get('username') + messages.success(request, f"Account created for {username}. You can now log in.") + return redirect('djangoapp:login_view') + else: + # Debugging output + print(form.errors) # You can also log this information + else: + form = UserCreationForm() + return render(request, 'djangoapp/registration.html', {'form': form}) # Update the `get_dealerships` view to render the index page with a list of dealerships def get_dealerships(request): From ed58c86108c87403bf30a22f5746cfd5852648e3 Mon Sep 17 00:00:00 2001 From: MarekAtGitHub Date: Mon, 16 Oct 2023 18:18:25 -0400 Subject: [PATCH 04/14] week number 2a --- server/db.sqlite3 | Bin 131072 -> 131072 bytes .../djangoapp/templates/djangoapp/index.html | 7 +++++++ 2 files changed, 7 insertions(+) diff --git a/server/db.sqlite3 b/server/db.sqlite3 index ce3dc00181d552e23ee76481a9f8abe2e7bf8a0a..cbc26640c1fad4ca0afbffe8a74269f23fb2d298 100644 GIT binary patch delta 272 zcmZo@;Am*zm>|u#WTK2S0*U&)M*g(O^$O`Bn6Ei(?V+$h-vnFL0R^R4O$H|536*fYV2{FBwzt0@q2P;<`u?K$fic>+LQg_}IR|tKZ=#Gd$vAdX|=^hDK(aC*(CNGMa5{RN&9e)0Q%$n7D~-)k^G%Y9%O~%i zl^T#^V&!8IRS+NOX{sA<>{43dm{U@mB3ZsKcJU>4x#lTuRdWLcS+9$=Z|Yh++# ztZQhXYiyukWMpMvVP$BcXKZ0$VPx5)%);v19O^i^aJ|Cj3A3wNI6e4t`S0*g;-9p! hQHX!C+IlqwLJn%qS-(AJJtI#553 Contact Us + + + + +