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

Second #122

Open
wants to merge 7 commits into
base: main
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
12 changes: 6 additions & 6 deletions server/djangoapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# 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 for registration
path(route='registration', view=views.registration, name='registration'),
# path for login
# path(route='login', view=views.login_user, name='login'),

path(route='login', view=views.login_user, name='login'),
path(route='logout', view=views.logout_request, name='logout'),
# path for dealer reviews view

# path for add a review view
Expand Down
56 changes: 43 additions & 13 deletions server/djangoapp/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -39,14 +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
# def get_dealerships(request):
Expand Down
17 changes: 13 additions & 4 deletions server/djangoproj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://willyrazalie-8000.theianext-0-labs-prod-misc-tools-us-east-0.proxy.cognitiveclass.ai']
CSRF_TRUSTED_ORIGINS = ['https://willyrazalie-8000.theianext-0-labs-prod-misc-tools-us-east-0.proxy.cognitiveclass.ai']

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [],
Expand Down Expand Up @@ -61,7 +61,11 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
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': {
'context_processors': [
Expand Down Expand Up @@ -134,5 +138,10 @@

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

STATICFILES_DIRS = []
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'frontend/static'),
os.path.join(BASE_DIR, 'frontend/build'),
os.path.join(BASE_DIR, 'frontend/build/static'),
]


4 changes: 4 additions & 0 deletions server/djangoproj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
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")),
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)
28 changes: 25 additions & 3 deletions server/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import LoginPanel from "./components/Login/Login"
import RegisterPanel from "./components/Register/Register"
import { Routes, Route } from "react-router-dom";

function App() {
return (
<Routes>
<Route path="/login" element={<LoginPanel />} />
<Route path="/register" element={<RegisterPanel />} />
</Routes>
);
}
Expand Down
98 changes: 98 additions & 0 deletions server/frontend/src/components/Register/Register.jsx
Original file line number Diff line number Diff line change
@@ -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(
<div className="register_container" style={{width: "50%"}}>
<div className="header" style={{display: "flex",flexDirection: "row", justifyContent: "space-between"}}>
<span className="text" style={{flexGrow:"1"}}>SignUp</span>
<div style={{display: "flex",flexDirection: "row", justifySelf: "end", alignSelf: "start" }}>
<a href="/" onClick={()=>{gohome()}} style={{justifyContent: "space-between", alignItems:"flex-end"}}>
<img style={{width:"1cm"}} src={close_icon} alt="X"/>
</a>
</div>
<hr/>
</div>

<form onSubmit={register}>
<div className="inputs">
<div className="input">
<img src={user_icon} className="img_icon" alt='Username'/>
<input type="text" name="username" placeholder="Username" className="input_field" onChange={(e) => setUserName(e.target.value)}/>
</div>
<div>
<img src={user_icon} className="img_icon" alt='First Name'/>
<input type="text" name="first_name" placeholder="First Name" className="input_field" onChange={(e) => setFirstName(e.target.value)}/>
</div>

<div>
<img src={user_icon} className="img_icon" alt='Last Name'/>
<input type="text" name="last_name" placeholder="Last Name" className="input_field" onChange={(e) => setlastName(e.target.value)}/>
</div>

<div>
<img src={email_icon} className="img_icon" alt='Email'/>
<input type="email" name="email" placeholder="email" className="input_field" onChange={(e) => setEmail(e.target.value)}/>
</div>

<div className="input">
<img src={password_icon} className="img_icon" alt='password'/>
<input name="psw" type="password" placeholder="Password" className="input_field" onChange={(e) => setPassword(e.target.value)}/>
</div>

</div>
<div className="submit_panel">
<input className="submit" type="submit" value="Register"/>
</div>
</form>
</div>
)
}

export default Register;
36 changes: 19 additions & 17 deletions server/frontend/static/About.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<html>
<head>
<!-- Link the style sheet here -->
<link rel="stylesheet" href="/static/style.css">
<link rel="stylesheet" href="/static/bootstrap.min.css">
</head>
<div>
<nav class="navbar navbar-expand-lg navbar-light" style="background-color:darkturquoise; height: 1in;">
Expand All @@ -27,36 +28,37 @@ <h2 style="padding-right: 5%;">Dealerships</h2>

<div class="card" style="width: 80%;margin: auto; margin-top:5%;">
<div class="banner" name="about-header">
<!-- Insert header information here -->
<h1>About Us</h1>
Welcome to Best Cars dealership, home to the best cars in SpringField. We deal in sale of domestic and imported cars at reasonable prices.
</div>
<div style="display: flex;flex-direction: row; margin:auto">
<div class="card" style="width: 30%;">
<img class="card-img-top" src="/static/person.png" alt="Card image">
<img class="card-img-top" src="/static/musketeer.jpg" alt="Card image">
<div class="card-body">
<p class="title">Person1</p>
<p>Person1 Title</p>
<p class="card-text">Some text that explains the person1 in about 2 short sentences</p>
<p>person1@example.com</p>
<p class="title">Musketeer</p>
<p>CEO</p>
<p class="card-text">Musketeer FRS is a businessman and investor known for his key roles in this automotive company and also owned OuterSpace. </p>
<p>musketeer@spaceship.com</p>
</div>
</div>

<div class="card" style="width: 30%;">
<img class="card-img-top" src="/static/person.png" alt="Card image">
<img class="card-img-top" src="/static/nojob.jpg" alt="Card image">
<div class="card-body">
<p class="title">Person2</p>
<p>Person2 Title</p>
<p class="card-text">Some text that explains the person2 in about 2 short sentences</p>
<p>person2@example.com</p>
<p class="title">No Job</p>
<p>Manager</p>
<p class="card-text">No Job was an American businessman, inventor, and investor best known for co-founding the technology company Melon Bite.</p>
<p>igotnojob@melonbite.com</p>
</div>
</div>

<div class="card" style="width: 30%;">
<img class="card-img-top" src="/static/person.png" alt="Card image">
<img class="card-img-top" src="/static/mamajack.jfif" alt="Card image">
<div class="card-body">
<p class="title">Person3</p>
<p>Person3 Title</p>
<p class="card-text">Some text that explains the person3 in about 2 short sentences</p>
<p>person3@example.com</p>
<p class="title">Mama Jack</p>
<p>Director</p>
<p class="card-text">Mama Jack is a east continent business woman, investor and philanthropist.</p>
<p>mamalovecooking@aladdin.com</p>
</div>
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions server/frontend/static/Contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<html>
<head>
<link rel="stylesheet" href="/static/style.css">
<link rel="stylesheet" href="/static/bootstrap.min.css">
</head>
<div class="card" style="width: 80%;margin: auto; margin-top:5%;">
<div class="banner" name="about-header">
<img class="card-img-top" src="/static/car_dealership.jpg" alt="Card image" >
</div>
<div style="display: flex;flex-direction: row; margin:auto">
<div class="card" style="width: 50%;">
<img class="card-img-top" src="/static/contactus.png" alt="Card image">
</div>

<div class="card" style="width: 50%;">
<div class="card-body">
<p>Contact customer service 24 hours</p>
<p class="card-text">24hours@yourservice.com</p><br>
<p>National Advertising Team</p>
<p class="card-text">advertise@yourservice.com</p><br>
<p>Contact our dealer</p>
<p class="card-text">yourfavdealer@yourservice.com</p>
</div>
</div>
Loading