From ef471e2d9808a373bdb9e65b7d38c470437a1dbf Mon Sep 17 00:00:00 2001 From: khemPha Date: Wed, 4 Jun 2025 13:18:58 +0700 Subject: [PATCH 1/2] update create about-us contact us --- server/djangoproj/settings.py | 10 ++++- server/djangoproj/urls.py | 2 + server/frontend/static/About.html | 26 +++++++----- server/frontend/static/Contact.html | 65 +++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 server/frontend/static/Contact.html diff --git a/server/djangoproj/settings.py b/server/djangoproj/settings.py index e0b1092a5c..c716177f97 100644 --- a/server/djangoproj/settings.py +++ b/server/djangoproj/settings.py @@ -30,6 +30,8 @@ ALLOWED_HOSTS = [] CSRF_TRUSTED_ORIGINS = [] +# ALLOWED_HOSTS=['localhost',' + + +
- -
- - +
+
+ - + \ No newline at end of file diff --git a/server/frontend/static/Contact.html b/server/frontend/static/Contact.html new file mode 100644 index 0000000000..874f98591e --- /dev/null +++ b/server/frontend/static/Contact.html @@ -0,0 +1,65 @@ + + + + + + + +
+ + +
+ +
+
+
+ Card image +
+

+ +
+

Contact Customer + Service

+

support@bestcars.com

+

Contact our National Advertising team +

+

NationalSales@bestcars.com

+

Contact our Publice Relation team

+

PR@bestcars.com

+

Contat the bestcars.com offices

+

312-611-1111

+

Become a bestcars.com car dealer

+

Visit growwithbestcars.com

+ +
+
+
+
+ + + + \ No newline at end of file From be4d88d7b90ec5a2c7b94c946df4c377fb532e6d Mon Sep 17 00:00:00 2001 From: khemPha Date: Tue, 10 Jun 2025 15:26:16 +0700 Subject: [PATCH 2/2] completed login,logout and register --- server/djangoapp/urls.py | 14 +- server/djangoapp/views.py | 84 ++++-- server/djangoenv/bin/Activate.ps1 | 241 ++++++++++++++++++ server/djangoenv/bin/activate | 76 ++++++ server/djangoenv/bin/activate.csh | 37 +++ server/djangoenv/bin/activate.fish | 75 ++++++ server/djangoenv/bin/django-admin | 8 + server/djangoenv/bin/dotenv | 8 + server/djangoenv/bin/easy_install | 8 + server/djangoenv/bin/easy_install-3.8 | 8 + server/djangoenv/bin/gunicorn | 8 + server/djangoenv/bin/normalizer | 8 + server/djangoenv/bin/pip | 8 + server/djangoenv/bin/pip3 | 8 + server/djangoenv/bin/pip3.8 | 8 + server/djangoenv/bin/python | 1 + server/djangoenv/bin/python3 | 1 + server/djangoenv/bin/sqlformat | 8 + server/djangoenv/pyvenv.cfg | 3 + server/djangoproj/settings.py | 18 +- server/djangoproj/urls.py | 2 + server/frontend/package-lock.json | 30 ++- server/frontend/src/App.js | 2 + .../frontend/src/components/Login/Login.jsx | 1 + .../src/components/Register/Register.jsx | 101 ++++++++ server/frontend/static/Home.html | 127 +++++---- 26 files changed, 798 insertions(+), 95 deletions(-) create mode 100644 server/djangoenv/bin/Activate.ps1 create mode 100644 server/djangoenv/bin/activate create mode 100644 server/djangoenv/bin/activate.csh create mode 100644 server/djangoenv/bin/activate.fish create mode 100755 server/djangoenv/bin/django-admin create mode 100755 server/djangoenv/bin/dotenv create mode 100755 server/djangoenv/bin/easy_install create mode 100755 server/djangoenv/bin/easy_install-3.8 create mode 100755 server/djangoenv/bin/gunicorn create mode 100755 server/djangoenv/bin/normalizer create mode 100755 server/djangoenv/bin/pip create mode 100755 server/djangoenv/bin/pip3 create mode 100755 server/djangoenv/bin/pip3.8 create mode 120000 server/djangoenv/bin/python create mode 120000 server/djangoenv/bin/python3 create mode 100755 server/djangoenv/bin/sqlformat create mode 100644 server/djangoenv/pyvenv.cfg create mode 100644 server/frontend/src/components/Register/Register.jsx diff --git a/server/djangoapp/urls.py b/server/djangoapp/urls.py index 0edc274f90..fa4dde828a 100644 --- a/server/djangoapp/urls.py +++ b/server/djangoapp/urls.py @@ -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 +from django.contrib.auth import views as auth_views + app_name = 'djangoapp' urlpatterns = [ - # # path for registration - - # path for login - # path(route='login', view=views.login_user, name='login'), - + path('register/', views.registration, name='Register'), + path(route='login', view=views.login_user, name='login'), + path('logout/', auth_views.LogoutView.as_view(), 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..ab391b916d 100644 --- a/server/djangoapp/views.py +++ b/server/djangoapp/views.py @@ -1,19 +1,19 @@ # 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 import logging import json from django.views.decorators.csrf import csrf_exempt -# from .populate import initiate +from .populate import initiate # Get an instance of a logger @@ -25,28 +25,62 @@ # Create a `login_request` view to handle sign in request @csrf_exempt def login_user(request): - # Get username and password from request.POST dictionary - data = json.loads(request.body) - username = data['userName'] - password = data['password'] - # Try to check if provide credential can be authenticated - user = authenticate(username=username, password=password) - data = {"userName": username} - if user is not None: - # If user is valid, call login method to login current user - login(request, user) - data = {"userName": username, "status": "Authenticated"} - return JsonResponse(data) + if request.method == 'POST': + try: + data = json.loads(request.body) + username = data.get('userName') + password = data.get('password') + + user = authenticate(username=username, password=password) + if user is not None: + login(request, user) + return JsonResponse({"userName": username, "status": "Authenticated"}, status=200) + else: + return JsonResponse({"error": "Invalid credentials"}, status=401) + except json.JSONDecodeError: + return JsonResponse({"error": "Invalid JSON"}, status=400) + else: + return JsonResponse({"error": "Only POST method allowed"}, status=405) + # 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 = {} + # Load JSON data from the request body + 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): diff --git a/server/djangoenv/bin/Activate.ps1 b/server/djangoenv/bin/Activate.ps1 new file mode 100644 index 0000000000..2fb3852c3c --- /dev/null +++ b/server/djangoenv/bin/Activate.ps1 @@ -0,0 +1,241 @@ +<# +.Synopsis +Activate a Python virtual environment for the current PowerShell session. + +.Description +Pushes the python executable for a virtual environment to the front of the +$Env:PATH environment variable and sets the prompt to signify that you are +in a Python virtual environment. Makes use of the command line switches as +well as the `pyvenv.cfg` file values present in the virtual environment. + +.Parameter VenvDir +Path to the directory that contains the virtual environment to activate. The +default value for this is the parent of the directory that the Activate.ps1 +script is located within. + +.Parameter Prompt +The prompt prefix to display when this virtual environment is activated. By +default, this prompt is the name of the virtual environment folder (VenvDir) +surrounded by parentheses and followed by a single space (ie. '(.venv) '). + +.Example +Activate.ps1 +Activates the Python virtual environment that contains the Activate.ps1 script. + +.Example +Activate.ps1 -Verbose +Activates the Python virtual environment that contains the Activate.ps1 script, +and shows extra information about the activation as it executes. + +.Example +Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv +Activates the Python virtual environment located in the specified location. + +.Example +Activate.ps1 -Prompt "MyPython" +Activates the Python virtual environment that contains the Activate.ps1 script, +and prefixes the current prompt with the specified string (surrounded in +parentheses) while the virtual environment is active. + +.Notes +On Windows, it may be required to enable this Activate.ps1 script by setting the +execution policy for the user. You can do this by issuing the following PowerShell +command: + +PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser + +For more information on Execution Policies: +https://go.microsoft.com/fwlink/?LinkID=135170 + +#> +Param( + [Parameter(Mandatory = $false)] + [String] + $VenvDir, + [Parameter(Mandatory = $false)] + [String] + $Prompt +) + +<# Function declarations --------------------------------------------------- #> + +<# +.Synopsis +Remove all shell session elements added by the Activate script, including the +addition of the virtual environment's Python executable from the beginning of +the PATH variable. + +.Parameter NonDestructive +If present, do not remove this function from the global namespace for the +session. + +#> +function global:deactivate ([switch]$NonDestructive) { + # Revert to original values + + # The prior prompt: + if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { + Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt + Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT + } + + # The prior PYTHONHOME: + if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) { + Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME + Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME + } + + # The prior PATH: + if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) { + Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH + Remove-Item -Path Env:_OLD_VIRTUAL_PATH + } + + # Just remove the VIRTUAL_ENV altogether: + if (Test-Path -Path Env:VIRTUAL_ENV) { + Remove-Item -Path env:VIRTUAL_ENV + } + + # Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: + if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { + Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force + } + + # Leave deactivate function in the global namespace if requested: + if (-not $NonDestructive) { + Remove-Item -Path function:deactivate + } +} + +<# +.Description +Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the +given folder, and returns them in a map. + +For each line in the pyvenv.cfg file, if that line can be parsed into exactly +two strings separated by `=` (with any amount of whitespace surrounding the =) +then it is considered a `key = value` line. The left hand string is the key, +the right hand is the value. + +If the value starts with a `'` or a `"` then the first and last character is +stripped from the value before being captured. + +.Parameter ConfigDir +Path to the directory that contains the `pyvenv.cfg` file. +#> +function Get-PyVenvConfig( + [String] + $ConfigDir +) { + Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg" + + # Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue). + $pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue + + # An empty map will be returned if no config file is found. + $pyvenvConfig = @{ } + + if ($pyvenvConfigPath) { + + Write-Verbose "File exists, parse `key = value` lines" + $pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath + + $pyvenvConfigContent | ForEach-Object { + $keyval = $PSItem -split "\s*=\s*", 2 + if ($keyval[0] -and $keyval[1]) { + $val = $keyval[1] + + # Remove extraneous quotations around a string value. + if ("'""".Contains($val.Substring(0, 1))) { + $val = $val.Substring(1, $val.Length - 2) + } + + $pyvenvConfig[$keyval[0]] = $val + Write-Verbose "Adding Key: '$($keyval[0])'='$val'" + } + } + } + return $pyvenvConfig +} + + +<# Begin Activate script --------------------------------------------------- #> + +# Determine the containing directory of this script +$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition +$VenvExecDir = Get-Item -Path $VenvExecPath + +Write-Verbose "Activation script is located in path: '$VenvExecPath'" +Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)" +Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)" + +# Set values required in priority: CmdLine, ConfigFile, Default +# First, get the location of the virtual environment, it might not be +# VenvExecDir if specified on the command line. +if ($VenvDir) { + Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values" +} +else { + Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir." + $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/") + Write-Verbose "VenvDir=$VenvDir" +} + +# Next, read the `pyvenv.cfg` file to determine any required value such +# as `prompt`. +$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir + +# Next, set the prompt from the command line, or the config file, or +# just use the name of the virtual environment folder. +if ($Prompt) { + Write-Verbose "Prompt specified as argument, using '$Prompt'" +} +else { + Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value" + if ($pyvenvCfg -and $pyvenvCfg['prompt']) { + Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'" + $Prompt = $pyvenvCfg['prompt']; + } + else { + Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virutal environment)" + Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'" + $Prompt = Split-Path -Path $venvDir -Leaf + } +} + +Write-Verbose "Prompt = '$Prompt'" +Write-Verbose "VenvDir='$VenvDir'" + +# Deactivate any currently active virtual environment, but leave the +# deactivate function in place. +deactivate -nondestructive + +# Now set the environment variable VIRTUAL_ENV, used by many tools to determine +# that there is an activated venv. +$env:VIRTUAL_ENV = $VenvDir + +if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) { + + Write-Verbose "Setting prompt to '$Prompt'" + + # Set the prompt to include the env name + # Make sure _OLD_VIRTUAL_PROMPT is global + function global:_OLD_VIRTUAL_PROMPT { "" } + Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT + New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt + + function global:prompt { + Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " + _OLD_VIRTUAL_PROMPT + } +} + +# Clear PYTHONHOME +if (Test-Path -Path Env:PYTHONHOME) { + Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME + Remove-Item -Path Env:PYTHONHOME +} + +# Add the venv to the PATH +Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH +$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH" diff --git a/server/djangoenv/bin/activate b/server/djangoenv/bin/activate new file mode 100644 index 0000000000..50970e1d01 --- /dev/null +++ b/server/djangoenv/bin/activate @@ -0,0 +1,76 @@ +# This file must be used with "source bin/activate" *from bash* +# you cannot run it directly + +deactivate () { + # reset old environment variables + if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then + PATH="${_OLD_VIRTUAL_PATH:-}" + export PATH + unset _OLD_VIRTUAL_PATH + fi + if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then + PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" + export PYTHONHOME + unset _OLD_VIRTUAL_PYTHONHOME + fi + + # This should detect bash and zsh, which have a hash command that must + # be called to get it to forget past commands. Without forgetting + # past commands the $PATH changes we made may not be respected + if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then + hash -r + fi + + if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then + PS1="${_OLD_VIRTUAL_PS1:-}" + export PS1 + unset _OLD_VIRTUAL_PS1 + fi + + unset VIRTUAL_ENV + if [ ! "${1:-}" = "nondestructive" ] ; then + # Self destruct! + unset -f deactivate + fi +} + +# unset irrelevant variables +deactivate nondestructive + +VIRTUAL_ENV="/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv" +export VIRTUAL_ENV + +_OLD_VIRTUAL_PATH="$PATH" +PATH="$VIRTUAL_ENV/bin:$PATH" +export PATH + +# unset PYTHONHOME if set +# this will fail if PYTHONHOME is set to the empty string (which is bad anyway) +# could use `if (set -u; : $PYTHONHOME) ;` in bash +if [ -n "${PYTHONHOME:-}" ] ; then + _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" + unset PYTHONHOME +fi + +if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then + _OLD_VIRTUAL_PS1="${PS1:-}" + if [ "x(djangoenv) " != x ] ; then + PS1="(djangoenv) ${PS1:-}" + else + if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then + # special case for Aspen magic directories + # see https://aspen.io/ + PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1" + else + PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1" + fi + fi + export PS1 +fi + +# This should detect bash and zsh, which have a hash command that must +# be called to get it to forget past commands. Without forgetting +# past commands the $PATH changes we made may not be respected +if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then + hash -r +fi diff --git a/server/djangoenv/bin/activate.csh b/server/djangoenv/bin/activate.csh new file mode 100644 index 0000000000..a3e7eedcb6 --- /dev/null +++ b/server/djangoenv/bin/activate.csh @@ -0,0 +1,37 @@ +# This file must be used with "source bin/activate.csh" *from csh*. +# You cannot run it directly. +# Created by Davide Di Blasi . +# Ported to Python 3.3 venv by Andrew Svetlov + +alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate' + +# Unset irrelevant variables. +deactivate nondestructive + +setenv VIRTUAL_ENV "/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv" + +set _OLD_VIRTUAL_PATH="$PATH" +setenv PATH "$VIRTUAL_ENV/bin:$PATH" + + +set _OLD_VIRTUAL_PROMPT="$prompt" + +if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then + if ("djangoenv" != "") then + set env_name = "djangoenv" + else + if (`basename "VIRTUAL_ENV"` == "__") then + # special case for Aspen magic directories + # see https://aspen.io/ + set env_name = `basename \`dirname "$VIRTUAL_ENV"\`` + else + set env_name = `basename "$VIRTUAL_ENV"` + endif + endif + set prompt = "[$env_name] $prompt" + unset env_name +endif + +alias pydoc python -m pydoc + +rehash diff --git a/server/djangoenv/bin/activate.fish b/server/djangoenv/bin/activate.fish new file mode 100644 index 0000000000..ebac44d66f --- /dev/null +++ b/server/djangoenv/bin/activate.fish @@ -0,0 +1,75 @@ +# This file must be used with ". bin/activate.fish" *from fish* (http://fishshell.org) +# you cannot run it directly + +function deactivate -d "Exit virtualenv and return to normal shell environment" + # reset old environment variables + if test -n "$_OLD_VIRTUAL_PATH" + set -gx PATH $_OLD_VIRTUAL_PATH + set -e _OLD_VIRTUAL_PATH + end + if test -n "$_OLD_VIRTUAL_PYTHONHOME" + set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME + set -e _OLD_VIRTUAL_PYTHONHOME + end + + if test -n "$_OLD_FISH_PROMPT_OVERRIDE" + functions -e fish_prompt + set -e _OLD_FISH_PROMPT_OVERRIDE + functions -c _old_fish_prompt fish_prompt + functions -e _old_fish_prompt + end + + set -e VIRTUAL_ENV + if test "$argv[1]" != "nondestructive" + # Self destruct! + functions -e deactivate + end +end + +# unset irrelevant variables +deactivate nondestructive + +set -gx VIRTUAL_ENV "/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv" + +set -gx _OLD_VIRTUAL_PATH $PATH +set -gx PATH "$VIRTUAL_ENV/bin" $PATH + +# unset PYTHONHOME if set +if set -q PYTHONHOME + set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME + set -e PYTHONHOME +end + +if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" + # fish uses a function instead of an env var to generate the prompt. + + # save the current fish_prompt function as the function _old_fish_prompt + functions -c fish_prompt _old_fish_prompt + + # with the original prompt function renamed, we can override with our own. + function fish_prompt + # Save the return status of the last command + set -l old_status $status + + # Prompt override? + if test -n "(djangoenv) " + printf "%s%s" "(djangoenv) " (set_color normal) + else + # ...Otherwise, prepend env + set -l _checkbase (basename "$VIRTUAL_ENV") + if test $_checkbase = "__" + # special case for Aspen magic directories + # see https://aspen.io/ + printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) + else + printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) + end + end + + # Restore the return status of the previous command. + echo "exit $old_status" | . + _old_fish_prompt + end + + set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" +end diff --git a/server/djangoenv/bin/django-admin b/server/djangoenv/bin/django-admin new file mode 100755 index 0000000000..372404dd97 --- /dev/null +++ b/server/djangoenv/bin/django-admin @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from django.core.management import execute_from_command_line +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(execute_from_command_line()) diff --git a/server/djangoenv/bin/dotenv b/server/djangoenv/bin/dotenv new file mode 100755 index 0000000000..2bbd296c6a --- /dev/null +++ b/server/djangoenv/bin/dotenv @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from dotenv.__main__ import cli +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(cli()) diff --git a/server/djangoenv/bin/easy_install b/server/djangoenv/bin/easy_install new file mode 100755 index 0000000000..66b352f497 --- /dev/null +++ b/server/djangoenv/bin/easy_install @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from setuptools.command.easy_install import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/server/djangoenv/bin/easy_install-3.8 b/server/djangoenv/bin/easy_install-3.8 new file mode 100755 index 0000000000..66b352f497 --- /dev/null +++ b/server/djangoenv/bin/easy_install-3.8 @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from setuptools.command.easy_install import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/server/djangoenv/bin/gunicorn b/server/djangoenv/bin/gunicorn new file mode 100755 index 0000000000..d3c0c614d4 --- /dev/null +++ b/server/djangoenv/bin/gunicorn @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from gunicorn.app.wsgiapp import run +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(run()) diff --git a/server/djangoenv/bin/normalizer b/server/djangoenv/bin/normalizer new file mode 100755 index 0000000000..8b81204652 --- /dev/null +++ b/server/djangoenv/bin/normalizer @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from charset_normalizer import cli +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(cli.cli_detect()) diff --git a/server/djangoenv/bin/pip b/server/djangoenv/bin/pip new file mode 100755 index 0000000000..543b9e04a7 --- /dev/null +++ b/server/djangoenv/bin/pip @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/server/djangoenv/bin/pip3 b/server/djangoenv/bin/pip3 new file mode 100755 index 0000000000..543b9e04a7 --- /dev/null +++ b/server/djangoenv/bin/pip3 @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/server/djangoenv/bin/pip3.8 b/server/djangoenv/bin/pip3.8 new file mode 100755 index 0000000000..543b9e04a7 --- /dev/null +++ b/server/djangoenv/bin/pip3.8 @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/server/djangoenv/bin/python b/server/djangoenv/bin/python new file mode 120000 index 0000000000..b8a0adbbb9 --- /dev/null +++ b/server/djangoenv/bin/python @@ -0,0 +1 @@ +python3 \ No newline at end of file diff --git a/server/djangoenv/bin/python3 b/server/djangoenv/bin/python3 new file mode 120000 index 0000000000..975a95faeb --- /dev/null +++ b/server/djangoenv/bin/python3 @@ -0,0 +1 @@ +/Applications/Xcode.app/Contents/Developer/usr/bin/python3 \ No newline at end of file diff --git a/server/djangoenv/bin/sqlformat b/server/djangoenv/bin/sqlformat new file mode 100755 index 0000000000..37371d87ae --- /dev/null +++ b/server/djangoenv/bin/sqlformat @@ -0,0 +1,8 @@ +#!/Users/khempha/Desktop/xrwvm-fullstack_developer_capstone/server/djangoenv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from sqlparse.__main__ import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/server/djangoenv/pyvenv.cfg b/server/djangoenv/pyvenv.cfg new file mode 100644 index 0000000000..85a3d54d49 --- /dev/null +++ b/server/djangoenv/pyvenv.cfg @@ -0,0 +1,3 @@ +home = /Applications/Xcode.app/Contents/Developer/usr/bin +include-system-site-packages = false +version = 3.8.9 diff --git a/server/djangoproj/settings.py b/server/djangoproj/settings.py index c716177f97..273d6b0a77 100644 --- a/server/djangoproj/settings.py +++ b/server/djangoproj/settings.py @@ -30,8 +30,6 @@ ALLOWED_HOSTS = [] CSRF_TRUSTED_ORIGINS = [] -# ALLOWED_HOSTS=['localhost','=6.9.0" }, @@ -1891,6 +1903,18 @@ "@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==", + "license": "MIT", + "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/App.js b/server/frontend/src/App.js index aceac6974d..8ea0b2cd33 100644 --- a/server/frontend/src/App.js +++ b/server/frontend/src/App.js @@ -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 ( } /> + } /> ); } diff --git a/server/frontend/src/components/Login/Login.jsx b/server/frontend/src/components/Login/Login.jsx index b1790e7f90..b8d183930f 100644 --- a/server/frontend/src/components/Login/Login.jsx +++ b/server/frontend/src/components/Login/Login.jsx @@ -64,6 +64,7 @@ const Login = ({ onClose }) => { setOpen(false)}/> Register Now + diff --git a/server/frontend/src/components/Register/Register.jsx b/server/frontend/src/components/Register/Register.jsx new file mode 100644 index 0000000000..52d592872d --- /dev/null +++ b/server/frontend/src/components/Register/Register.jsx @@ -0,0 +1,101 @@ +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 = () => { +// State variables for form inputs + const [userName, setUserName] = useState(""); + const [password, setPassword] = useState(""); + const [email, setEmail] = useState(""); + const [firstName, setFirstName] = useState(""); + const [lastName, setlastName] = useState(""); + +// Redirect to home + const gohome = ()=> { + window.location.href = window.location.origin; + } + +// Handle form submission + const register = async (e) => { + console.log('e', e) + e.preventDefault(); + let register_url = window.location.origin+"/djangoapp/register"; + +// Send POST request to register endpoint + 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) { + // Save username in session and reload home + 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( +
+ + +
+
+
+ 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 fb0c3fb617..b0d74856df 100644 --- a/server/frontend/static/Home.html +++ b/server/frontend/static/Home.html @@ -1,64 +1,85 @@ - - + + - + let checkSession = () => { + let curr_user = sessionStorage.getItem("username"); + if (curr_user && curr_user !== "") { + document.getElementById("loginlogout").innerHTML = + '' + curr_user + '' + + 'Logout' + } else { + document.getElementById("loginlogout").innerHTML = + 'Login' + + 'Register' + } + } + + - -
-
- ... - -
-
- + + \ No newline at end of file