From 6a346c3b69f51504a194221e44ed2fad8d04f82d Mon Sep 17 00:00:00 2001 From: rockbjson Date: Mon, 5 Aug 2024 02:47:51 -0400 Subject: [PATCH 01/51] Added About Me and Conact Us pages --- server/djangoproj/settings.py | 12 ++++-- server/djangoproj/urls.py | 2 + server/frontend/static/About.html | 22 ++++++----- server/frontend/static/Contact.html | 60 +++++++++++++++++++++++++++++ server/frontend/static/Home.html | 4 +- server/frontend/static/style.css | 53 +++++++++++++++++++++---- 6 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 server/frontend/static/Contact.html diff --git a/server/djangoproj/settings.py b/server/djangoproj/settings.py index e0b1092a5c..ece0bd4046 100644 --- a/server/djangoproj/settings.py +++ b/server/djangoproj/settings.py @@ -28,8 +28,8 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] -CSRF_TRUSTED_ORIGINS = [] +ALLOWED_HOSTS=['localhost','https://tanisidas21-8000.theianext-0-labs-prod-misc-tools-us-east-0.proxy.cognitiveclass.ai'] +CSRF_TRUSTED_ORIGINS=['https://tanisidas21-8000.theianext-0-labs-prod-misc-tools-us-east-0.proxy.cognitiveclass.ai'] REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [], @@ -61,7 +61,9 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [ + os.path.join(BASE_DIR,'frontend/static') + ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -134,5 +136,7 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -STATICFILES_DIRS = [] +STATICFILES_DIRS = [ + os.path.join(BASE_DIR,'frontend/static') +] diff --git a/server/djangoproj/urls.py b/server/djangoproj/urls.py index 6808da9141..5825f366ef 100644 --- a/server/djangoproj/urls.py +++ b/server/djangoproj/urls.py @@ -23,4 +23,6 @@ path('admin/', admin.site.urls), path('djangoapp/', include('djangoapp.urls')), path('', TemplateView.as_view(template_name="Home.html")), + path('about/', TemplateView.as_view(template_name="About.html")), + path('contact/', TemplateView.as_view(template_name="Contact.html")), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/server/frontend/static/About.html b/server/frontend/static/About.html index 484efd960f..eb0fedefce 100644 --- a/server/frontend/static/About.html +++ b/server/frontend/static/About.html @@ -1,9 +1,10 @@ - + +
-
diff --git a/server/frontend/static/style.css b/server/frontend/static/style.css index 0543af014a..0b6a82e829 100644 --- a/server/frontend/static/style.css +++ b/server/frontend/static/style.css @@ -7,8 +7,8 @@ img{ border: rgb(103, 102, 105) 3px solid; display: flex; flex-direction: column; - margin-left:5%; - margin-right:5%; + margin-left:2%; + margin-right: 2%; margin-top: 1%; margin-bottom: 1%; } @@ -28,13 +28,13 @@ img{ } .details{ font-size: 20px; - color: rgb(97, 64, 128); + color: #F5D48A; padding:20px; } .title{ font-size: 20px; - background-color: rgb(97, 64, 128); + background-color: #F5D48A; color: white; text-align: center; margin:20px; @@ -42,7 +42,7 @@ img{ } .homepage_links{ - color: rgb(97, 64, 128); + color: #F5D48A; padding: 25%; font-size: larger; } @@ -57,8 +57,27 @@ img{ display: flex; flex-direction: column; align-items: center; + text-align: center; justify-content: center; - flex:1 + flex:1; +} + +.about-banner{ + display: flex; + flex-direction: column; + align-items: center; + text-align: center; + justify-content: center; + flex:1; +} + +.contact-banner{ + display: flex; + flex-direction: column; + align-items: center; + text-align: center; + justify-content: center; + flex:1; } .form_panel { @@ -75,6 +94,10 @@ img{ background-color: black; } +.navbar { + color: white; +} + .navitems{ display: flex; flex-direction: row; @@ -82,12 +105,13 @@ img{ flex: 1; justify-content: flex-start; justify-self: center; + color: white; } .nav_item{ margin-left:15px; font-size: 20px; - color: black; + color: white; align-self: center; } @@ -118,9 +142,22 @@ img{ .img_icon { align-self: center; width:40px; - background-color:#0C9; + background-color:#F5D48A; color:#FFF; border-radius:50px; text-align:center; box-shadow: 2px 2px 3px #999; } + +.btn { + color: white; +} + +.contact-header{ + margin-left: .5 cm; +} + +.contact-info{ + text-align:left; + margin-left: 0.6cm; +} \ No newline at end of file From 68dc8a8d175090da6e6391e42e64e0d5a8695f70 Mon Sep 17 00:00:00 2001 From: rockbjson Date: Mon, 5 Aug 2024 03:31:44 -0400 Subject: [PATCH 02/51] updated Login and Regisrtat6ion --- server/djangoapp/urls.py | 11 ++- server/djangoapp/views.py | 53 ++++++++--- server/djangoproj/settings.py | 8 +- server/djangoproj/urls.py | 2 + server/frontend/package-lock.json | 28 +++++- server/frontend/src/components/Register.jsx | 98 +++++++++++++++++++++ server/frontend/static/Home.html | 17 +++- 7 files changed, 196 insertions(+), 21 deletions(-) create mode 100644 server/frontend/src/components/Register.jsx diff --git a/server/djangoapp/urls.py b/server/djangoapp/urls.py index 0edc274f90..a662e89124 100644 --- a/server/djangoapp/urls.py +++ b/server/djangoapp/urls.py @@ -1,16 +1,19 @@ # Uncomment the imports before you add the code -# from django.urls import path +from django.urls import path from django.conf.urls.static import static from django.conf import settings -# from . import views +from . import views app_name = 'djangoapp' urlpatterns = [ # # path for registration + path(route='register', view=views.registration, name='register'), # path for login - # path(route='login', view=views.login_user, name='login'), - + path(route='login', view=views.login_user, name='login'), + + # path for logout + path(route='logout', view=views.logout_request, name='logout'), # path for dealer reviews view # path for add a review view diff --git a/server/djangoapp/views.py b/server/djangoapp/views.py index b16409f419..b9bcfbbf07 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -1,12 +1,12 @@ # Uncomment the required imports before adding the code -# from django.shortcuts import render -# from django.http import HttpResponseRedirect, HttpResponse -# from django.contrib.auth.models import User -# from django.shortcuts import get_object_or_404, render, redirect -# from django.contrib.auth import logout -# from django.contrib import messages -# from datetime import datetime +from django.shortcuts import render +from django.http import HttpResponseRedirect, HttpResponse +from django.contrib.auth.models import User +from django.shortcuts import get_object_or_404, render, redirect +from django.contrib.auth import logout +from django.contrib import messages +from datetime import datetime from django.http import JsonResponse from django.contrib.auth import login, authenticate @@ -39,13 +39,44 @@ def login_user(request): return JsonResponse(data) # Create a `logout_request` view to handle sign out request -# def logout_request(request): -# ... +def logout_request(request): + logout(request) + data = {"userName":""} + return JsonResponse(data) # Create a `registration` view to handle sign up request # @csrf_exempt -# def registration(request): -# ... +@csrf_exempt +def registration(request): + context = {} + + data = json.loads(request.body) + username = data['userName'] + password = data['password'] + first_name = data['firstName'] + last_name = data['lastName'] + email = data['email'] + username_exist = False + email_exist = False + try: + # Check if user already exists + User.objects.get(username=username) + username_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 username_exist: + # Create user in auth_user table + user = User.objects.create_user(username=username, first_name=first_name, last_name=last_name,password=password, email=email) + # Login the user and redirect to list page + login(request, user) + data = {"userName":username,"status":"Authenticated"} + return JsonResponse(data) + else : + data = {"userName":username,"error":"Already Registered"} + return JsonResponse(data) # # Update the `get_dealerships` view to render the index page with # a list of dealerships diff --git a/server/djangoproj/settings.py b/server/djangoproj/settings.py index ece0bd4046..1b7a090cd0 100644 --- a/server/djangoproj/settings.py +++ b/server/djangoproj/settings.py @@ -62,7 +62,9 @@ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ - os.path.join(BASE_DIR,'frontend/static') + os.path.join(BASE_DIR, 'frontend/static'), + os.path.join(BASE_DIR, 'frontend/build'), + os.path.join(BASE_DIR, 'frontend/build/static'), ], 'APP_DIRS': True, 'OPTIONS': { @@ -137,6 +139,8 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' STATICFILES_DIRS = [ - os.path.join(BASE_DIR,'frontend/static') + os.path.join(BASE_DIR, 'frontend/static'), + os.path.join(BASE_DIR, 'frontend/build'), + os.path.join(BASE_DIR, 'frontend/build/static'), ] diff --git a/server/djangoproj/urls.py b/server/djangoproj/urls.py index 5825f366ef..eaf6254de6 100644 --- a/server/djangoproj/urls.py +++ b/server/djangoproj/urls.py @@ -25,4 +25,6 @@ path('', TemplateView.as_view(template_name="Home.html")), path('about/', TemplateView.as_view(template_name="About.html")), path('contact/', TemplateView.as_view(template_name="Contact.html")), + path('login/', TemplateView.as_view(template_name="index.html")), + path('register/', TemplateView.as_view(template_name="index.html")), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/server/frontend/package-lock.json b/server/frontend/package-lock.json index 0797425307..b9244446c9 100644 --- a/server/frontend/package-lock.json +++ b/server/frontend/package-lock.json @@ -16,6 +16,9 @@ "react-router-dom": "^6.19.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4" + }, + "devDependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -646,9 +649,17 @@ } }, "node_modules/@babel/plugin-proposal-private-property-in-object": { - "version": "7.21.0-placeholder-for-preset-env.2", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", - "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "version": "7.21.11", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz", + "integrity": "sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead.", + "dev": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.18.6", + "@babel/helper-create-class-features-plugin": "^7.21.0", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5" + }, "engines": { "node": ">=6.9.0" }, @@ -1891,6 +1902,17 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/preset-env/node_modules/@babel/plugin-proposal-private-property-in-object": { + "version": "7.21.0-placeholder-for-preset-env.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", + "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/preset-env/node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", diff --git a/server/frontend/src/components/Register.jsx b/server/frontend/src/components/Register.jsx new file mode 100644 index 0000000000..9f1a290327 --- /dev/null +++ b/server/frontend/src/components/Register.jsx @@ -0,0 +1,98 @@ +import React, { useState } from "react"; +import "./Register.css"; +import user_icon from "../assets/person.png" +import email_icon from "../assets/email.png" +import password_icon from "../assets/password.png" +import close_icon from "../assets/close.png" + +const Register = () => { + + const [userName, setUserName] = useState(""); + const [password, setPassword] = useState(""); + const [email, setEmail] = useState(""); + const [firstName, setFirstName] = useState(""); + const [lastName, setlastName] = useState(""); + + + const gohome = ()=> { + window.location.href = window.location.origin; + } + + const register = async (e) => { + e.preventDefault(); + + let register_url = window.location.origin+"/djangoapp/register"; + + const res = await fetch(register_url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + "userName": userName, + "password": password, + "firstName":firstName, + "lastName":lastName, + "email":email + }), + }); + + const json = await res.json(); + if (json.status) { + sessionStorage.setItem('username', json.userName); + window.location.href = window.location.origin; + } + else if (json.error === "Already Registered") { + alert("The user with same username is already registered"); + window.location.href = window.location.origin; + } +}; + + return( +
+
+ SignUp +
+ {gohome()}} style={{justifyContent: "space-between", alignItems:"flex-end"}}> + X + +
+
+
+ +
+
+
+ Username + setUserName(e.target.value)}/> +
+
+ First Name + setFirstName(e.target.value)}/> +
+ +
+ Last Name + setlastName(e.target.value)}/> +
+ +
+ Email + setEmail(e.target.value)}/> +
+ +
+ password + setPassword(e.target.value)}/> +
+ +
+
+ +
+
+
+ ) +} + +export default Register; \ No newline at end of file diff --git a/server/frontend/static/Home.html b/server/frontend/static/Home.html index c6634ef387..0055693311 100644 --- a/server/frontend/static/Home.html +++ b/server/frontend/static/Home.html @@ -7,7 +7,22 @@