Repository: foysal-mahmud/E-BookShop----Spring-boot Branch: master Commit: 8802dc749387 Files: 128 Total size: 320.5 KB Directory structure: gitextract_kryo0iqb/ ├── .github/ │ ├── dependabot.yml │ └── workflows/ │ └── maven.yml ├── .gitignore ├── .mvn/ │ └── wrapper/ │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .vscode/ │ └── launch.json ├── README.md ├── adminportal/ │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src/ │ ├── main/ │ │ ├── java/ │ │ │ └── com/ │ │ │ └── adminportal/ │ │ │ ├── AdminportalApplication.java │ │ │ ├── config/ │ │ │ │ └── SecurityConfig.java │ │ │ ├── controller/ │ │ │ │ ├── BookController.java │ │ │ │ ├── HomeController.java │ │ │ │ └── ResourceController.java │ │ │ ├── domain/ │ │ │ │ ├── Book.java │ │ │ │ ├── User.java │ │ │ │ └── security/ │ │ │ │ ├── Authority.java │ │ │ │ ├── PasswordResetToken.java │ │ │ │ ├── Role.java │ │ │ │ └── UserRole.java │ │ │ ├── repository/ │ │ │ │ ├── BookRepository.java │ │ │ │ ├── RoleRepository.java │ │ │ │ └── UserRepository.java │ │ │ ├── service/ │ │ │ │ ├── BookService.java │ │ │ │ ├── UserService.java │ │ │ │ └── impl/ │ │ │ │ ├── BookServiceImpl.java │ │ │ │ ├── UserSecurityService.java │ │ │ │ └── UserServiceImpl.java │ │ │ └── utility/ │ │ │ └── SecurityUtility.java │ │ └── resources/ │ │ ├── application.properties │ │ ├── static/ │ │ │ ├── css/ │ │ │ │ ├── non-responsive.css │ │ │ │ └── style.css │ │ │ └── fonts/ │ │ │ └── FontAwesome.otf │ │ └── templates/ │ │ ├── addBook.html │ │ ├── bookInfo.html │ │ ├── bookList.html │ │ ├── common/ │ │ │ └── header.html │ │ ├── home.html │ │ ├── login.html │ │ └── updateBook.html │ └── test/ │ └── java/ │ └── com/ │ └── adminportal/ │ └── AdminportalApplicationTests.java ├── bin/ │ ├── .gitignore │ ├── .mvn/ │ │ └── wrapper/ │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src/ │ └── main/ │ └── resources/ │ └── application.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src/ ├── main/ │ ├── java/ │ │ └── com/ │ │ └── eCommerce/ │ │ ├── ECommerceApplication.java │ │ ├── config/ │ │ │ └── SecurityConfig.java │ │ ├── controller/ │ │ │ ├── CheckoutController.java │ │ │ ├── HomeController.java │ │ │ ├── SearchController.java │ │ │ └── ShoppingCartController.java │ │ ├── domain/ │ │ │ ├── BillingAddress.java │ │ │ ├── Book.java │ │ │ ├── BookToCartItem.java │ │ │ ├── CartItem.java │ │ │ ├── Order.java │ │ │ ├── Payment.java │ │ │ ├── ShippingAddress.java │ │ │ ├── ShoppingCart.java │ │ │ ├── User.java │ │ │ ├── UserBilling.java │ │ │ ├── UserPayment.java │ │ │ ├── UserShipping.java │ │ │ └── security/ │ │ │ ├── Authority.java │ │ │ ├── PasswordResetToken.java │ │ │ ├── Role.java │ │ │ └── UserRole.java │ │ ├── repository/ │ │ │ ├── BookRepository.java │ │ │ ├── BookToCartItemRepository.java │ │ │ ├── CartItemRepository.java │ │ │ ├── OrderRepository.java │ │ │ ├── PasswordResetTokenRepository.java │ │ │ ├── RoleRepository.java │ │ │ ├── ShoppingCartRepository.java │ │ │ ├── UserPaymentRepository.java │ │ │ ├── UserRepository.java │ │ │ └── UserShippingRepository.java │ │ ├── service/ │ │ │ ├── BillingAddressService.java │ │ │ ├── BookService.java │ │ │ ├── CartItemService.java │ │ │ ├── OrderService.java │ │ │ ├── PaymentService.java │ │ │ ├── ShippingAddressService.java │ │ │ ├── ShoppingCartService.java │ │ │ ├── UserPaymentService.java │ │ │ ├── UserService.java │ │ │ ├── UserShippingService.java │ │ │ └── impl/ │ │ │ ├── BillingAddressServiceImpl.java │ │ │ ├── BookServiceImpl.java │ │ │ ├── CartItemServiceImpl.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── PaymentServiceImpl.java │ │ │ ├── ShippingAddressServiceImpl.java │ │ │ ├── ShoppingCartServiceImpl.java │ │ │ ├── UserPaymentServiceImpl.java │ │ │ ├── UserSecurityService.java │ │ │ ├── UserServiceImpl.java │ │ │ └── UserShippingServiceImpl.java │ │ └── utility/ │ │ ├── MailConstructor.java │ │ ├── SecurityUtility.java │ │ └── USConstants.java │ └── resources/ │ ├── application.properties │ ├── messages.properties │ ├── static/ │ │ ├── css/ │ │ │ ├── jquery.dataTables_themeroller.css │ │ │ ├── non-responsive.css │ │ │ └── style.css │ │ ├── fonts/ │ │ │ └── FontAwesome.otf │ │ └── js/ │ │ └── scripts.js │ └── templates/ │ ├── badRequestPage.html │ ├── bookDetail.html │ ├── bookshelf.html │ ├── checkout.html │ ├── common/ │ │ └── header.html │ ├── faq.html │ ├── index.html │ ├── myAccount.html │ ├── myProfile.html │ ├── orderConfirmationEmailTemplate.html │ ├── orderSubmittedPage.html │ └── shoppingCart.html └── test/ └── java/ └── com/ └── eCommerce/ └── ECommerceApplicationTests.java ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/dependabot.yml ================================================ version: 2 updates: - package-ecosystem: maven directory: "/" schedule: interval: daily time: '21:00' timezone: Asia/Jakarta open-pull-requests-limit: 10 ================================================ FILE: .github/workflows/maven.yml ================================================ # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven # This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by # separate terms of service, privacy policy, and support # documentation. name: Java CI with Maven on: push: branches: [ "master" ] pull_request: branches: [ "master" ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' cache: maven - name: Build with Maven run: mvn -B package --file pom.xml # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive # - name: Update dependency graph # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 ================================================ FILE: .gitignore ================================================ target/ !.mvn/wrapper/maven-wrapper.jar ### STS ### .apt_generated .classpath .factorypath .project .settings .springBeans ### IntelliJ IDEA ### .idea logs *.iws *.iml *.ipr ### NetBeans ### nbproject/private/ build/ nbbuild/ dist/ nbdist/ .nb-gradle/ ================================================ FILE: .mvn/wrapper/maven-wrapper.properties ================================================ distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip ================================================ FILE: .vscode/launch.json ================================================ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { "version": "0.2.0", "configurations": [ { "name": "Launch Chrome 127.0.0.1", "type": "chrome", "request": "launch", "port": 9249, "webRoot": "${workspaceFolder}", "url": "http://127.0.0.1:2331/p/Bookstore/src/main/resources/templates/index.html?_cmAuth\u003drewvcqiueo" } ] } ================================================ FILE: README.md ================================================ # E-Commerce Complete E-Commerce Project using Spring, Hibernate, Bootstrap & MySQL > [!WARNING] > **Note Regarding This Project:** > > It has been a long time (3+ years) since I transitioned to JavaScript, and I have mostly forgotten a lot of things about Spring Boot. As a result, it is now very difficult for me to answer project-related questions regarding this technology. > [!TIP] > There are two separate projects in this repository: > - **🔮 Admin Panel** > - **🍄 Main Ecommerce** > > Download the repository and move the projects to different folders to run them separately. > 📹 You can find video demo of this 2 projects in "𝐷𝑒𝑚𝑜 𝑉𝑖𝑑𝑒𝑜" folder.

🎉 Thank You! 🎉


## Project Demo video : In "Demo Video" folder ## Home Page: ![Project Snapsort1](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook1.png) ![Project Snapsort2](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook2.png) ![Project Snapsort3](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook3.png) ## Book Details Page: ![Project Snapsort4](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook4.png) ![Project Snapsort5](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook5.png) ## Login and Registation: ![Project Snapsort6](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook6.png) ![Project Snapsort7](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook7.png) ![Project Snapsort8](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook8.png) ![Project Snapsort9](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook9.png) ![Project Snapsort10](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook10.png) ![Project Snapsort11](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook11.png) ![Project Snapsort12](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook12.png) ![Project Snapsort13](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook13.png) ![Project Snapsort14](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook14.png) ![Project Snapsort15](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook15.png) ![Project Snapsort16](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook16.png) ## Billing Address: ![Project Snapsort17](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook17.png) ![Project Snapsort18](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook18.png) ![Project Snapsort19](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook19.png) ## Shipping Address: ![Project Snapsort21](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook21.png) ![Project Snapsort22](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook22.png) ![Project Snapsort23](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook23.png) ## Shopping Cart: ![Project Snapsort23](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook23copy.png) ![Project Snapsort24](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook24.png) ![Project Snapsort25](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook25.png) ![Project Snapsort26](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook26.png) ## Checkout: ![Project Snapsort27](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook27.png) ![Project Snapsort28](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook28.png) ![Project Snapsort29](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook29.png) ![Project Snapsort30](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook30.png) ![Project Snapsort32](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook32.png) ## Order Confirmation: ![Project Snapsort33](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook33.png) ![Project Snapsort34](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook34.png) ![Project Snapsort35](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook35.png) ![Project Snapsort36](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook36.png) ![Project Snapsort37](https://github.com/foysal-mahmud/E-Commerce/blob/master/screensort/ebook37.png) ## --------------- The End ------------------- ================================================ FILE: adminportal/mvnw ================================================ #!/bin/sh # ---------------------------------------------------------------------------- # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- # Maven2 Start Up Batch script # # Required ENV vars: # ------------------ # JAVA_HOME - location of a JDK home dir # # Optional ENV vars # ----------------- # M2_HOME - location of maven2's installed home dir # MAVEN_OPTS - parameters passed to the Java VM when running Maven # e.g. to debug Maven itself, use # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files # ---------------------------------------------------------------------------- if [ -z "$MAVEN_SKIP_RC" ] ; then if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi if [ -f "$HOME/.mavenrc" ] ; then . "$HOME/.mavenrc" fi fi # OS specific support. $var _must_ be set to either true or false. cygwin=false; darwin=false; mingw=false case "`uname`" in CYGWIN*) cygwin=true ;; MINGW*) mingw=true;; Darwin*) darwin=true # # Look for the Apple JDKs first to preserve the existing behaviour, and then look # for the new JDKs provided by Oracle. # if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then # # Apple JDKs # export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home fi if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then # # Apple JDKs # export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home fi if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then # # Oracle JDKs # export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home fi if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then # # Apple JDKs # export JAVA_HOME=`/usr/libexec/java_home` fi ;; esac if [ -z "$JAVA_HOME" ] ; then if [ -r /etc/gentoo-release ] ; then JAVA_HOME=`java-config --jre-home` fi fi if [ -z "$M2_HOME" ] ; then ## resolve links - $0 may be a link to maven's home PRG="$0" # need this for relative symlinks while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG="`dirname "$PRG"`/$link" fi done saveddir=`pwd` M2_HOME=`dirname "$PRG"`/.. # make it fully qualified M2_HOME=`cd "$M2_HOME" && pwd` cd "$saveddir" # echo Using m2 at $M2_HOME fi # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin ; then [ -n "$M2_HOME" ] && M2_HOME=`cygpath --unix "$M2_HOME"` [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"` fi # For Migwn, ensure paths are in UNIX format before anything is touched if $mingw ; then [ -n "$M2_HOME" ] && M2_HOME="`(cd "$M2_HOME"; pwd)`" [ -n "$JAVA_HOME" ] && JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" # TODO classpath? fi if [ -z "$JAVA_HOME" ]; then javaExecutable="`which javac`" if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then # readlink(1) is not available as standard on Solaris 10. readLink=`which readlink` if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then if $darwin ; then javaHome="`dirname \"$javaExecutable\"`" javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" else javaExecutable="`readlink -f \"$javaExecutable\"`" fi javaHome="`dirname \"$javaExecutable\"`" javaHome=`expr "$javaHome" : '\(.*\)/bin'` JAVA_HOME="$javaHome" export JAVA_HOME fi fi fi if [ -z "$JAVACMD" ] ; then if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi else JAVACMD="`which java`" fi fi if [ ! -x "$JAVACMD" ] ; then echo "Error: JAVA_HOME is not defined correctly." >&2 echo " We cannot execute $JAVACMD" >&2 exit 1 fi if [ -z "$JAVA_HOME" ] ; then echo "Warning: JAVA_HOME environment variable is not set." fi CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher # For Cygwin, switch paths to Windows format before running java if $cygwin; then [ -n "$M2_HOME" ] && M2_HOME=`cygpath --path --windows "$M2_HOME"` [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"` fi # traverses directory structure from process work directory to filesystem root # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { local basedir=$(pwd) local wdir=$(pwd) while [ "$wdir" != '/' ] ; do if [ -d "$wdir"/.mvn ] ; then basedir=$wdir break fi wdir=$(cd "$wdir/.."; pwd) done echo "${basedir}" } # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then echo "$(tr -s '\n' ' ' < "$1")" fi } export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # Provide a "standardized" way to retrieve the CLI args that will # work with both Windows and non-Windows executions. MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" export MAVEN_CMD_LINE_ARGS WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain exec "$JAVACMD" \ $MAVEN_OPTS \ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${WRAPPER_LAUNCHER} "$@" ================================================ FILE: adminportal/mvnw.cmd ================================================ @REM ---------------------------------------------------------------------------- @REM Licensed to the Apache Software Foundation (ASF) under one @REM or more contributor license agreements. See the NOTICE file @REM distributed with this work for additional information @REM regarding copyright ownership. The ASF licenses this file @REM to you under the Apache License, Version 2.0 (the @REM "License"); you may not use this file except in compliance @REM with the License. You may obtain a copy of the License at @REM @REM http://www.apache.org/licenses/LICENSE-2.0 @REM @REM Unless required by applicable law or agreed to in writing, @REM software distributed under the License is distributed on an @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @REM KIND, either express or implied. See the License for the @REM specific language governing permissions and limitations @REM under the License. @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- @REM Maven2 Start Up Batch script @REM @REM Required ENV vars: @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars @REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @REM e.g. to debug Maven itself, use @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files @REM ---------------------------------------------------------------------------- @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' @echo off @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% @REM set %HOME% to equivalent of $HOME if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") @REM Execute a user defined script before this one if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre @REM check for pre script, once with legacy .bat ending and once with .cmd ending if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" :skipRcPre @setlocal set ERROR_CODE=0 @REM To isolate internal variables from possible post scripts, we use another setlocal @setlocal @REM ==== START VALIDATION ==== if not "%JAVA_HOME%" == "" goto OkJHome echo. echo Error: JAVA_HOME not found in your environment. >&2 echo Please set the JAVA_HOME variable in your environment to match the >&2 echo location of your Java installation. >&2 echo. goto error :OkJHome if exist "%JAVA_HOME%\bin\java.exe" goto init echo. echo Error: JAVA_HOME is set to an invalid directory. >&2 echo JAVA_HOME = "%JAVA_HOME%" >&2 echo Please set the JAVA_HOME variable in your environment to match the >&2 echo location of your Java installation. >&2 echo. goto error @REM ==== END VALIDATION ==== :init set MAVEN_CMD_LINE_ARGS=%* @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". @REM Fallback to current working directory if not found. set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir set EXEC_DIR=%CD% set WDIR=%EXEC_DIR% :findBaseDir IF EXIST "%WDIR%"\.mvn goto baseDirFound cd .. IF "%WDIR%"=="%CD%" goto baseDirNotFound set WDIR=%CD% goto findBaseDir :baseDirFound set MAVEN_PROJECTBASEDIR=%WDIR% cd "%EXEC_DIR%" goto endDetectBaseDir :baseDirNotFound set MAVEN_PROJECTBASEDIR=%EXEC_DIR% cd "%EXEC_DIR%" :endDetectBaseDir IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig @setlocal EnableExtensions EnableDelayedExpansion for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% :endReadAdditionalConfig SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% if ERRORLEVEL 1 goto error goto end :error set ERROR_CODE=1 :end @endlocal & set ERROR_CODE=%ERROR_CODE% if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost @REM check for post script, once with legacy .bat ending and once with .cmd ending if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" :skipRcPost @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' if "%MAVEN_BATCH_PAUSE%" == "on" pause if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% exit /B %ERROR_CODE% ================================================ FILE: adminportal/pom.xml ================================================ 4.0.0 com.adminportal adminportal 0.0.1-SNAPSHOT jar Bookstore frontend part for our bookstore project org.springframework.boot spring-boot-starter-parent 2.1.0.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-security mysql mysql-connector-java org.thymeleaf.extras thymeleaf-extras-springsecurity5 org.springframework spring-context-support javax.mail mail 1.4.7 org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin ================================================ FILE: adminportal/src/main/java/com/adminportal/AdminportalApplication.java ================================================ package com.adminportal; import java.util.HashSet; import java.util.Set; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import com.adminportal.domain.User; import com.adminportal.domain.security.Role; import com.adminportal.domain.security.UserRole; import com.adminportal.service.UserService; import com.adminportal.utility.SecurityUtility; @SpringBootApplication public class AdminportalApplication implements CommandLineRunner{ @Autowired private UserService userService; public static void main(String[] args) { SpringApplication.run(AdminportalApplication.class, args); } @Override public void run(String... args) throws Exception { User user1 = new User(); user1.setUsername("admin"); user1.setPassword(SecurityUtility.passwordEncoder().encode("admin")); user1.setEmail("admin@gmail.com"); Set userRoles = new HashSet<>(); Role role1= new Role(); role1.setRoleId(0); role1.setName("ROLE_ADMIN"); userRoles.add(new UserRole(user1, role1)); userService.createUser(user1, userRoles); } } ================================================ FILE: adminportal/src/main/java/com/adminportal/config/SecurityConfig.java ================================================ package com.adminportal.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import com.adminportal.service.impl.UserSecurityService; import com.adminportal.utility.SecurityUtility; @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled=true) public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private Environment env; @Autowired private UserSecurityService userSecurityService; private BCryptPasswordEncoder passwordEncoder() { return SecurityUtility.passwordEncoder(); } private static final String[] PUBLIC_MATCHERS = { "/css/**", "/js/**", "/image/**", "/newUser", "/forgetPassword", "/login", "/fonts/**" }; @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests(). /* antMatchers("/**").*/ antMatchers(PUBLIC_MATCHERS). permitAll().anyRequest().authenticated(); http .csrf().disable().cors().disable() .formLogin().failureUrl("/login?error") .defaultSuccessUrl("/") .loginPage("/login").permitAll() .and() .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll() .and() .rememberMe(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userSecurityService).passwordEncoder(passwordEncoder()); } } ================================================ FILE: adminportal/src/main/java/com/adminportal/controller/BookController.java ================================================ package com.adminportal.controller; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import com.adminportal.domain.Book; import com.adminportal.service.BookService; @Controller @RequestMapping("/book") public class BookController { @Autowired private BookService bookService; @RequestMapping(value = "/add", method = RequestMethod.GET) public String addBook(Model model) { Book book = new Book(); model.addAttribute("book", book); return "addBook"; } @RequestMapping(value = "/add", method = RequestMethod.POST) public String addBookPost(@ModelAttribute("book") Book book, HttpServletRequest request) { bookService.save(book); MultipartFile bookImage = book.getBookImage(); try { byte[] bytes = bookImage.getBytes(); String name = book.getId() + ".png"; BufferedOutputStream stream = new BufferedOutputStream( new FileOutputStream(new File("src/main/resources/static/image/book/" + name))); stream.write(bytes); stream.close(); } catch (Exception e) { e.printStackTrace(); } return "redirect:bookList"; } @RequestMapping("/bookInfo") public String bookInfo(@RequestParam("id") Long id, Model model) { Book book = bookService.findById(id); model.addAttribute("book", book); return "bookInfo"; } @RequestMapping("/updateBook") public String updateBook(@RequestParam("id") Long id, Model model) { Book book = bookService.findById(id); model.addAttribute("book", book); return "updateBook"; } @RequestMapping(value="/updateBook", method=RequestMethod.POST) public String updateBookPost(@ModelAttribute("book") Book book, HttpServletRequest request) { bookService.save(book); MultipartFile bookImage = book.getBookImage(); if(!bookImage.isEmpty()) { try { byte[] bytes = bookImage.getBytes(); String name = book.getId() + ".png"; Files.delete(Paths.get("src/main/resources/static/image/book/"+name)); BufferedOutputStream stream = new BufferedOutputStream( new FileOutputStream(new File("src/main/resources/static/image/book/" + name))); stream.write(bytes); stream.close(); } catch (Exception e) { e.printStackTrace(); } } return "redirect:/book/bookInfo?id="+book.getId(); } @RequestMapping("/bookList") public String bookList(Model model) { List bookList = bookService.findAll(); model.addAttribute("bookList", bookList); return "bookList"; } @RequestMapping(value="/remove", method=RequestMethod.POST) public String remove( @ModelAttribute("id") String id, Model model ) { bookService.deleteById(Long.parseLong(id.substring(8))); List bookList = bookService.findAll(); model.addAttribute("bookList", bookList); return "redirect:/book/bookList"; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/controller/HomeController.java ================================================ package com.adminportal.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HomeController { @RequestMapping("/") public String index(){ return "redirect:/home"; } @RequestMapping("/home") public String home(){ return "home"; } @RequestMapping("/login") public String login(){ return "login"; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/controller/ResourceController.java ================================================ package com.adminportal.controller; import java.util.ArrayList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.adminportal.service.BookService; @RestController public class ResourceController { @Autowired private BookService bookService; @RequestMapping(value="/book/removeList", method=RequestMethod.POST) public String removeList( @RequestBody ArrayList bookIdList, Model model ){ for (String id : bookIdList) { String bookId =id.substring(8); bookService.deleteById(Long.parseLong(bookId)); } return "delete success"; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/domain/Book.java ================================================ package com.adminportal.domain; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Transient; import org.springframework.web.multipart.MultipartFile; import com.fasterxml.jackson.annotation.JsonIgnore; @Entity public class Book { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; private String title; private String author; private String publisher; private String publicationDate; private String language; private String category; private int numberOfPages; private String format; private int isbn; private double shippingWeight; private double listPrice; private double ourPrice; private boolean active=true; @Column(columnDefinition="text") private String description; private int inStockNumber; @Transient private MultipartFile bookImage; @OneToMany(mappedBy = "book") @JsonIgnore private List bookToCartItemList; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getPublisher() { return publisher; } public void setPublisher(String publisher) { this.publisher = publisher; } public String getPublicationDate() { return publicationDate; } public void setPublicationDate(String publicationDate) { this.publicationDate = publicationDate; } public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } public int getNumberOfPages() { return numberOfPages; } public void setNumberOfPages(int numberOfPages) { this.numberOfPages = numberOfPages; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public int getIsbn() { return isbn; } public void setIsbn(int isbn) { this.isbn = isbn; } public double getShippingWeight() { return shippingWeight; } public void setShippingWeight(double shippingWeight) { this.shippingWeight = shippingWeight; } public double getListPrice() { return listPrice; } public void setListPrice(double listPrice) { this.listPrice = listPrice; } public double getOurPrice() { return ourPrice; } public void setOurPrice(double ourPrice) { this.ourPrice = ourPrice; } public boolean isActive() { return active; } public void setActive(boolean active) { this.active = active; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getInStockNumber() { return inStockNumber; } public void setInStockNumber(int inStockNumber) { this.inStockNumber = inStockNumber; } public MultipartFile getBookImage() { return bookImage; } public void setBookImage(MultipartFile bookImage) { this.bookImage = bookImage; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/domain/User.java ================================================ package com.adminportal.domain; import java.util.Collection; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import com.adminportal.domain.security.Authority; import com.adminportal.domain.security.UserRole; import com.fasterxml.jackson.annotation.JsonIgnore; @Entity public class User implements UserDetails{ @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id", nullable = false, updatable = false) private Long id; private String username; private String password; private String firstName; private String lastName; @Column(name="email", nullable = false, updatable = false) private String email; private String phone; private boolean enabled=true; @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JsonIgnore private Set userRoles = new HashSet<>(); public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public Set getUserRoles() { return userRoles; } public void setUserRoles(Set userRoles) { this.userRoles = userRoles; } @Override public Collection getAuthorities() { Set authorites = new HashSet<>(); userRoles.forEach(ur -> authorites.add(new Authority(ur.getRole().getName()))); return authorites; } @Override public boolean isAccountNonExpired() { // TODO Auto-generated method stub return true; } @Override public boolean isAccountNonLocked() { // TODO Auto-generated method stub return true; } @Override public boolean isCredentialsNonExpired() { // TODO Auto-generated method stub return true; } @Override public boolean isEnabled() { return enabled; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/domain/security/Authority.java ================================================ package com.adminportal.domain.security; import org.springframework.security.core.GrantedAuthority; public class Authority implements GrantedAuthority{ private final String authority; public Authority(String authority) { this.authority = authority; } @Override public String getAuthority() { return authority; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/domain/security/PasswordResetToken.java ================================================ package com.adminportal.domain.security; import java.util.Calendar; import java.util.Date; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import com.adminportal.domain.User; @Entity public class PasswordResetToken { private static final int EXPIRATION = 60 * 24; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String token; @OneToOne(targetEntity = User.class, fetch = FetchType.EAGER) @JoinColumn(nullable=false, name="user_id") private User user; private Date expiryDate; public PasswordResetToken(){} public PasswordResetToken(final String token, final User user) { super (); this.token = token; this.user = user; this.expiryDate = calculateExpiryDate(EXPIRATION); } private Date calculateExpiryDate (final int expiryTimeInMinutes) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(new Date().getTime()); cal.add(Calendar.MINUTE, expiryTimeInMinutes); return new Date(cal.getTime().getTime()); } public void updateToken(final String token) { this.token = token; this.expiryDate = calculateExpiryDate(EXPIRATION); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Date getExpiryDate() { return expiryDate; } public void setExpiryDate(Date expiryDate) { this.expiryDate = expiryDate; } public static int getExpiration() { return EXPIRATION; } @Override public String toString() { return "PasswordResetToken [id=" + id + ", token=" + token + ", user=" + user + ", expiryDate=" + expiryDate + "]"; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/domain/security/Role.java ================================================ package com.adminportal.domain.security; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.OneToMany; @Entity public class Role { @Id private int roleId; private String name; @OneToMany(mappedBy = "role", cascade = CascadeType.ALL, fetch=FetchType.LAZY) private Set userRoles = new HashSet<>(); public int getRoleId() { return roleId; } public void setRoleId(int roleId) { this.roleId = roleId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set getUserRoles() { return userRoles; } public void setUserRoles(Set userRoles) { this.userRoles = userRoles; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/domain/security/UserRole.java ================================================ package com.adminportal.domain.security; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import com.adminportal.domain.User; @Entity @Table(name="user_role") public class UserRole { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long userRoleId; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name="user_id") private User user; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name="role_id") private Role role; public UserRole(){} public UserRole(User user, Role role) { this.user = user; this.role = role; } public Long getUserRoleId() { return userRoleId; } public void setUserRoleId(Long userRoleId) { this.userRoleId = userRoleId; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Role getRole() { return role; } public void setRole(Role role) { this.role = role; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/repository/BookRepository.java ================================================ package com.adminportal.repository; import org.springframework.data.repository.CrudRepository; import com.adminportal.domain.Book; public interface BookRepository extends CrudRepository{ } ================================================ FILE: adminportal/src/main/java/com/adminportal/repository/RoleRepository.java ================================================ package com.adminportal.repository; import org.springframework.data.repository.CrudRepository; import com.adminportal.domain.security.Role; public interface RoleRepository extends CrudRepository { Role findByname(String name); } ================================================ FILE: adminportal/src/main/java/com/adminportal/repository/UserRepository.java ================================================ package com.adminportal.repository; import org.springframework.data.repository.CrudRepository; import com.adminportal.domain.User; public interface UserRepository extends CrudRepository { User findByUsername(String username); } ================================================ FILE: adminportal/src/main/java/com/adminportal/service/BookService.java ================================================ package com.adminportal.service; import java.util.List; import com.adminportal.domain.Book; public interface BookService { Book save(Book book); List findAll(); Book findById(Long id); } ================================================ FILE: adminportal/src/main/java/com/adminportal/service/UserService.java ================================================ package com.adminportal.service; import java.util.Set; import com.adminportal.domain.User; import com.adminportal.domain.security.UserRole; public interface UserService { User createUser(User user, Set userRoles) throws Exception; User save(User user); } ================================================ FILE: adminportal/src/main/java/com/adminportal/service/impl/BookServiceImpl.java ================================================ package com.adminportal.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.adminportal.domain.Book; import com.adminportal.repository.BookRepository; import com.adminportal.service.BookService; @Service public class BookServiceImpl implements BookService{ @Autowired private BookRepository bookRepository; public Book save(Book book) { return bookRepository.save(book); } public List findAll() { return (List) bookRepository.findAll(); } public Book findById(Long id) { return bookRepository.findById(id).orElse(null); } } ================================================ FILE: adminportal/src/main/java/com/adminportal/service/impl/UserSecurityService.java ================================================ package com.adminportal.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import com.adminportal.domain.User; import com.adminportal.repository.UserRepository; @Service public class UserSecurityService implements UserDetailsService{ @Autowired private UserRepository userRepository; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userRepository.findByUsername(username); if(null == user) { throw new UsernameNotFoundException("Username not found"); } return user; } } ================================================ FILE: adminportal/src/main/java/com/adminportal/service/impl/UserServiceImpl.java ================================================ package com.adminportal.service.impl; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.adminportal.domain.User; import com.adminportal.domain.security.UserRole; import com.adminportal.repository.RoleRepository; import com.adminportal.repository.UserRepository; import com.adminportal.service.UserService; @Service public class UserServiceImpl implements UserService { private static final Logger LOG = LoggerFactory.getLogger(UserService.class); @Autowired private UserRepository userRepository; @Autowired private RoleRepository roleRepository; @Override public User createUser(User user, Set userRoles) { User localUser = userRepository.findByUsername(user.getUsername()); if (localUser != null) { LOG.info("user {} already exists. Nothing will be done.", user.getUsername()); } else { for (UserRole ur : userRoles) { roleRepository.save(ur.getRole()); } user.getUserRoles().addAll(userRoles); localUser = userRepository.save(user); } return localUser; } @Override public User save(User user) { return userRepository.save(user); } } ================================================ FILE: adminportal/src/main/java/com/adminportal/utility/SecurityUtility.java ================================================ package com.adminportal.utility; import java.security.SecureRandom; import java.util.Random; import org.springframework.context.annotation.Bean; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Component; @Component public class SecurityUtility { private static final String SALT = "salt"; // Salt should be protected carefully @Bean public static BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes())); } @Bean public static String randomPassword() { String SALTCHARS = "ABCEFGHIJKLMNOPQRSTUVWXYZ1234567890"; StringBuilder salt = new StringBuilder(); Random rnd = new Random(); while (salt.length()<18) { int index= (int) (rnd.nextFloat()*SALTCHARS.length()); salt.append(SALTCHARS.charAt(index)); } String saltStr = salt.toString(); return saltStr; } } ================================================ FILE: adminportal/src/main/resources/application.properties ================================================ server.port=8081 server.context-path=/adminportal spring.thymeleaf.cache=false # =============================== # = DATA SOURCE # =============================== # Set here configurations for the database connection spring.datasource.url=jdbc:mysql://localhost:3306/ecommercedatabase # Username and secret spring.datasource.username=root spring.datasource.password=foysal28 # Keep the connection alive if idle for a long time (needed in production) spring.datasource.testWhileIdle = true spring.datasource.validationQuery = SELECT 1 # =============================== # = JPA / HIBERNATE # =============================== # Use spring.jpa.properties.* for Hibernate native properties (the prefix is # stripped before adding them to the entity manager). # Show or not log for each sql query spring.jpa.show-sql=true # Hibernate ddl auto (create, create-drop, update): with "update" the database # schema will be automatically updated accordingly to java entities found in # the project spring.jpa.hibernate.ddl-auto = update # Allows Hibernate to generate SQL optimized for a particular DBMS spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect ================================================ FILE: adminportal/src/main/resources/static/css/non-responsive.css ================================================ /* Template-specific stuff * * Customizations just for the template; these are not necessary for anything * with disabling the responsiveness. */ /* Account for fixed navbar */ body { padding-top: 70px; padding-bottom: 30px; } body, .navbar-fixed-top, .navbar-fixed-bottom { min-width: 970px; } /* Don't let the lead text change font-size. */ .lead { font-size: 16px; } /* Finesse the page header spacing */ .page-header { margin-bottom: 30px; } .page-header .lead { margin-bottom: 10px; } /* Non-responsive overrides * * Utilize the following CSS to disable the responsive-ness of the container, * grid system, and navbar. */ /* Reset the container */ .container { width: 970px; max-width: none !important; } /* Demonstrate the grids */ .col-xs-4 { padding-top: 15px; padding-bottom: 15px; /*background-color: #eee;*/ /*background-color: rgba(86,61,124,.15);*/ /*border: 1px solid #ddd;*/ /*border: 1px solid rgba(86,61,124,.2);*/ } .container .navbar-header, .container .navbar-collapse { margin-right: 0; margin-left: 0; } /* Always float the navbar header */ .navbar-header { float: left; } /* Undo the collapsing navbar */ .navbar-collapse { display: block !important; height: auto !important; padding-bottom: 0; overflow: visible !important; visibility: visible !important; } .navbar-toggle { display: none; } .navbar-collapse { border-top: 0; } .navbar-brand { margin-left: -15px; } /* Always apply the floated nav */ .navbar-nav { float: left; margin: 0; } .navbar-nav > li { float: left; } .navbar-nav > li > a { padding: 15px; } /* Redeclare since we override the float above */ .navbar-nav.navbar-right { float: right; } /* Undo custom dropdowns */ .navbar .navbar-nav .open .dropdown-menu { position: absolute; float: left; background-color: #fff; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, .15); border-width: 0 1px 1px; border-radius: 0 0 4px 4px; -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175); box-shadow: 0 6px 12px rgba(0, 0, 0, .175); } .navbar-default .navbar-nav .open .dropdown-menu > li > a { color: #333; } .navbar .navbar-nav .open .dropdown-menu > li > a:hover, .navbar .navbar-nav .open .dropdown-menu > li > a:focus, .navbar .navbar-nav .open .dropdown-menu > .active > a, .navbar .navbar-nav .open .dropdown-menu > .active > a:hover, .navbar .navbar-nav .open .dropdown-menu > .active > a:focus { color: #fff !important; background-color: #428bca !important; } .navbar .navbar-nav .open .dropdown-menu > .disabled > a, .navbar .navbar-nav .open .dropdown-menu > .disabled > a:hover, .navbar .navbar-nav .open .dropdown-menu > .disabled > a:focus { color: #999 !important; background-color: transparent !important; } /* Undo form expansion */ .navbar-form { float: left; width: auto; padding-top: 0; padding-bottom: 0; margin-right: 0; margin-left: 0; border: 0; -webkit-box-shadow: none; box-shadow: none; } /* Copy-pasted from forms.less since we mixin the .form-inline styles. */ .navbar-form .form-group { display: inline-block; margin-bottom: 0; vertical-align: middle; } .navbar-form .form-control { display: inline-block; width: auto; vertical-align: middle; } .navbar-form .form-control-static { display: inline-block; } .navbar-form .input-group { display: inline-table; vertical-align: middle; } .navbar-form .input-group .input-group-addon, .navbar-form .input-group .input-group-btn, .navbar-form .input-group .form-control { width: auto; } .navbar-form .input-group > .form-control { width: 100%; } .navbar-form .control-label { margin-bottom: 0; vertical-align: middle; } .navbar-form .radio, .navbar-form .checkbox { display: inline-block; margin-top: 0; margin-bottom: 0; vertical-align: middle; } .navbar-form .radio label, .navbar-form .checkbox label { padding-left: 0; } .navbar-form .radio input[type="radio"], .navbar-form .checkbox input[type="checkbox"] { position: relative; margin-left: 0; } .navbar-form .has-feedback .form-control-feedback { top: 0; } /* Undo inline form compaction on small screens */ .form-inline .form-group { display: inline-block; margin-bottom: 0; vertical-align: middle; } .form-inline .form-control { display: inline-block; width: auto; vertical-align: middle; } .form-inline .form-control-static { display: inline-block; } .form-inline .input-group { display: inline-table; vertical-align: middle; } .form-inline .input-group .input-group-addon, .form-inline .input-group .input-group-btn, .form-inline .input-group .form-control { width: auto; } .form-inline .input-group > .form-control { width: 100%; } .form-inline .control-label { margin-bottom: 0; vertical-align: middle; } .form-inline .radio, .form-inline .checkbox { display: inline-block; margin-top: 0; margin-bottom: 0; vertical-align: middle; } .form-inline .radio label, .form-inline .checkbox label { padding-left: 0; } .form-inline .radio input[type="radio"], .form-inline .checkbox input[type="checkbox"] { position: relative; margin-left: 0; } .form-inline .has-feedback .form-control-feedback { top: 0; } ================================================ FILE: adminportal/src/main/resources/static/css/style.css ================================================ body { } hr { border: none; height: 1px; color: #333; background-color: #333; } .container { width: 90%; } .page-top { margin-top: -70px; } .navbar { margin-bottom: 20px; } .box { border: 1px solid red; } .home-headline{ font-family: 'Times New Roman', Times, serif; font-size:24px; color: #fff; margin: auto; text-align: center; margin-top: -13px; } .home-headline span { background-color: #231F20; padding: 5px 22px; } .section-headline { font-family: 'Times New Roman', Times, serif; font-size:24px; color: #fff; margin: auto; text-align: center; margin-top: 90px; } .section-headline span { background-color: #231F20; padding: 5px 22px; } ================================================ FILE: adminportal/src/main/resources/templates/addBook.html ================================================
New Book Information * is a required field
Title of the book
Author of the book
Publisher of the book
Publication Date of the book
Number of pages of the book
ISBN of the book
Ounces
Shipping Weight of the book
$
List price of the book
$
Our price of the book
Number of in-stock copies
Whether the book is active or inactive
Description of the book
Cancel
================================================ FILE: adminportal/src/main/resources/templates/bookInfo.html ================================================


Author:

Publisher:

Publication Date:

Language:

Category:

Pages:

Format:

ISBN:

Shipping Weight:

List Price:

Our Price:

Number in Stock:


Description:



================================================ FILE: adminportal/src/main/resources/templates/bookList.html ================================================
Title Author Category List Price Our Price Active? Operation
================================================ FILE: adminportal/src/main/resources/templates/common/header.html ================================================ E-Commerce Admin
================================================ FILE: adminportal/src/main/resources/templates/home.html ================================================

Admin Portal





================================================ FILE: adminportal/src/main/resources/templates/login.html ================================================

Admin Authentication


Invalid username and password.
You have been logged out.
================================================ FILE: adminportal/src/main/resources/templates/updateBook.html ================================================
Update Book Information * is a required field
Title of the book
Author of the book
Publisher of the book
Publication Date of the book
Number of pages of the book
ISBN of the book
Ounces
Shipping Weight of the book
Tk/=
List price of the book
Tk/=
Our price of the book
Number of in-stock copies
Whether the book is active or inactive
Description of the book
Cancel
================================================ FILE: adminportal/src/test/java/com/adminportal/AdminportalApplicationTests.java ================================================ package com.adminportal; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest public class AdminportalApplicationTests { @Test public void contextLoads() { } } ================================================ FILE: bin/.gitignore ================================================ target/ !.mvn/wrapper/maven-wrapper.jar ### STS ### .apt_generated .classpath .factorypath .project .settings .springBeans ### IntelliJ IDEA ### .idea *.iws *.iml *.ipr ### NetBeans ### nbproject/private/ build/ nbbuild/ dist/ nbdist/ .nb-gradle/ ================================================ FILE: bin/.mvn/wrapper/maven-wrapper.properties ================================================ distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip ================================================ FILE: bin/mvnw ================================================ #!/bin/sh # ---------------------------------------------------------------------------- # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- # Maven2 Start Up Batch script # # Required ENV vars: # ------------------ # JAVA_HOME - location of a JDK home dir # # Optional ENV vars # ----------------- # M2_HOME - location of maven2's installed home dir # MAVEN_OPTS - parameters passed to the Java VM when running Maven # e.g. to debug Maven itself, use # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files # ---------------------------------------------------------------------------- if [ -z "$MAVEN_SKIP_RC" ] ; then if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi if [ -f "$HOME/.mavenrc" ] ; then . "$HOME/.mavenrc" fi fi # OS specific support. $var _must_ be set to either true or false. cygwin=false; darwin=false; mingw=false case "`uname`" in CYGWIN*) cygwin=true ;; MINGW*) mingw=true;; Darwin*) darwin=true # # Look for the Apple JDKs first to preserve the existing behaviour, and then look # for the new JDKs provided by Oracle. # if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then # # Apple JDKs # export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home fi if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then # # Apple JDKs # export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home fi if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then # # Oracle JDKs # export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home fi if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then # # Apple JDKs # export JAVA_HOME=`/usr/libexec/java_home` fi ;; esac if [ -z "$JAVA_HOME" ] ; then if [ -r /etc/gentoo-release ] ; then JAVA_HOME=`java-config --jre-home` fi fi if [ -z "$M2_HOME" ] ; then ## resolve links - $0 may be a link to maven's home PRG="$0" # need this for relative symlinks while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG="`dirname "$PRG"`/$link" fi done saveddir=`pwd` M2_HOME=`dirname "$PRG"`/.. # make it fully qualified M2_HOME=`cd "$M2_HOME" && pwd` cd "$saveddir" # echo Using m2 at $M2_HOME fi # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin ; then [ -n "$M2_HOME" ] && M2_HOME=`cygpath --unix "$M2_HOME"` [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"` fi # For Migwn, ensure paths are in UNIX format before anything is touched if $mingw ; then [ -n "$M2_HOME" ] && M2_HOME="`(cd "$M2_HOME"; pwd)`" [ -n "$JAVA_HOME" ] && JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" # TODO classpath? fi if [ -z "$JAVA_HOME" ]; then javaExecutable="`which javac`" if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then # readlink(1) is not available as standard on Solaris 10. readLink=`which readlink` if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then if $darwin ; then javaHome="`dirname \"$javaExecutable\"`" javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" else javaExecutable="`readlink -f \"$javaExecutable\"`" fi javaHome="`dirname \"$javaExecutable\"`" javaHome=`expr "$javaHome" : '\(.*\)/bin'` JAVA_HOME="$javaHome" export JAVA_HOME fi fi fi if [ -z "$JAVACMD" ] ; then if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi else JAVACMD="`which java`" fi fi if [ ! -x "$JAVACMD" ] ; then echo "Error: JAVA_HOME is not defined correctly." >&2 echo " We cannot execute $JAVACMD" >&2 exit 1 fi if [ -z "$JAVA_HOME" ] ; then echo "Warning: JAVA_HOME environment variable is not set." fi CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher # For Cygwin, switch paths to Windows format before running java if $cygwin; then [ -n "$M2_HOME" ] && M2_HOME=`cygpath --path --windows "$M2_HOME"` [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"` fi # traverses directory structure from process work directory to filesystem root # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { local basedir=$(pwd) local wdir=$(pwd) while [ "$wdir" != '/' ] ; do if [ -d "$wdir"/.mvn ] ; then basedir=$wdir break fi wdir=$(cd "$wdir/.."; pwd) done echo "${basedir}" } # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then echo "$(tr -s '\n' ' ' < "$1")" fi } export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # Provide a "standardized" way to retrieve the CLI args that will # work with both Windows and non-Windows executions. MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" export MAVEN_CMD_LINE_ARGS WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain exec "$JAVACMD" \ $MAVEN_OPTS \ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${WRAPPER_LAUNCHER} "$@" ================================================ FILE: bin/mvnw.cmd ================================================ @REM ---------------------------------------------------------------------------- @REM Licensed to the Apache Software Foundation (ASF) under one @REM or more contributor license agreements. See the NOTICE file @REM distributed with this work for additional information @REM regarding copyright ownership. The ASF licenses this file @REM to you under the Apache License, Version 2.0 (the @REM "License"); you may not use this file except in compliance @REM with the License. You may obtain a copy of the License at @REM @REM http://www.apache.org/licenses/LICENSE-2.0 @REM @REM Unless required by applicable law or agreed to in writing, @REM software distributed under the License is distributed on an @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @REM KIND, either express or implied. See the License for the @REM specific language governing permissions and limitations @REM under the License. @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- @REM Maven2 Start Up Batch script @REM @REM Required ENV vars: @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars @REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @REM e.g. to debug Maven itself, use @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files @REM ---------------------------------------------------------------------------- @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' @echo off @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% @REM set %HOME% to equivalent of $HOME if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") @REM Execute a user defined script before this one if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre @REM check for pre script, once with legacy .bat ending and once with .cmd ending if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" :skipRcPre @setlocal set ERROR_CODE=0 @REM To isolate internal variables from possible post scripts, we use another setlocal @setlocal @REM ==== START VALIDATION ==== if not "%JAVA_HOME%" == "" goto OkJHome echo. echo Error: JAVA_HOME not found in your environment. >&2 echo Please set the JAVA_HOME variable in your environment to match the >&2 echo location of your Java installation. >&2 echo. goto error :OkJHome if exist "%JAVA_HOME%\bin\java.exe" goto init echo. echo Error: JAVA_HOME is set to an invalid directory. >&2 echo JAVA_HOME = "%JAVA_HOME%" >&2 echo Please set the JAVA_HOME variable in your environment to match the >&2 echo location of your Java installation. >&2 echo. goto error @REM ==== END VALIDATION ==== :init set MAVEN_CMD_LINE_ARGS=%* @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". @REM Fallback to current working directory if not found. set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir set EXEC_DIR=%CD% set WDIR=%EXEC_DIR% :findBaseDir IF EXIST "%WDIR%"\.mvn goto baseDirFound cd .. IF "%WDIR%"=="%CD%" goto baseDirNotFound set WDIR=%CD% goto findBaseDir :baseDirFound set MAVEN_PROJECTBASEDIR=%WDIR% cd "%EXEC_DIR%" goto endDetectBaseDir :baseDirNotFound set MAVEN_PROJECTBASEDIR=%EXEC_DIR% cd "%EXEC_DIR%" :endDetectBaseDir IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig @setlocal EnableExtensions EnableDelayedExpansion for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% :endReadAdditionalConfig SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% if ERRORLEVEL 1 goto error goto end :error set ERROR_CODE=1 :end @endlocal & set ERROR_CODE=%ERROR_CODE% if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost @REM check for post script, once with legacy .bat ending and once with .cmd ending if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" :skipRcPost @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' if "%MAVEN_BATCH_PAUSE%" == "on" pause if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% exit /B %ERROR_CODE% ================================================ FILE: bin/pom.xml ================================================ 4.0.0 com.bookstore bookstore 0.0.1-SNAPSHOT jar Bookstore frontend part for our bookstore project org.springframework.boot spring-boot-starter-parent 1.4.3.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin ================================================ FILE: bin/src/main/resources/application.properties ================================================ ================================================ FILE: mvnw ================================================ #!/bin/sh # ---------------------------------------------------------------------------- # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- # Maven2 Start Up Batch script # # Required ENV vars: # ------------------ # JAVA_HOME - location of a JDK home dir # # Optional ENV vars # ----------------- # M2_HOME - location of maven2's installed home dir # MAVEN_OPTS - parameters passed to the Java VM when running Maven # e.g. to debug Maven itself, use # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files # ---------------------------------------------------------------------------- if [ -z "$MAVEN_SKIP_RC" ] ; then if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi if [ -f "$HOME/.mavenrc" ] ; then . "$HOME/.mavenrc" fi fi # OS specific support. $var _must_ be set to either true or false. cygwin=false; darwin=false; mingw=false case "`uname`" in CYGWIN*) cygwin=true ;; MINGW*) mingw=true;; Darwin*) darwin=true # # Look for the Apple JDKs first to preserve the existing behaviour, and then look # for the new JDKs provided by Oracle. # if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then # # Apple JDKs # export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home fi if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then # # Apple JDKs # export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home fi if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then # # Oracle JDKs # export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home fi if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then # # Apple JDKs # export JAVA_HOME=`/usr/libexec/java_home` fi ;; esac if [ -z "$JAVA_HOME" ] ; then if [ -r /etc/gentoo-release ] ; then JAVA_HOME=`java-config --jre-home` fi fi if [ -z "$M2_HOME" ] ; then ## resolve links - $0 may be a link to maven's home PRG="$0" # need this for relative symlinks while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG="`dirname "$PRG"`/$link" fi done saveddir=`pwd` M2_HOME=`dirname "$PRG"`/.. # make it fully qualified M2_HOME=`cd "$M2_HOME" && pwd` cd "$saveddir" # echo Using m2 at $M2_HOME fi # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin ; then [ -n "$M2_HOME" ] && M2_HOME=`cygpath --unix "$M2_HOME"` [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"` fi # For Migwn, ensure paths are in UNIX format before anything is touched if $mingw ; then [ -n "$M2_HOME" ] && M2_HOME="`(cd "$M2_HOME"; pwd)`" [ -n "$JAVA_HOME" ] && JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" # TODO classpath? fi if [ -z "$JAVA_HOME" ]; then javaExecutable="`which javac`" if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then # readlink(1) is not available as standard on Solaris 10. readLink=`which readlink` if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then if $darwin ; then javaHome="`dirname \"$javaExecutable\"`" javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" else javaExecutable="`readlink -f \"$javaExecutable\"`" fi javaHome="`dirname \"$javaExecutable\"`" javaHome=`expr "$javaHome" : '\(.*\)/bin'` JAVA_HOME="$javaHome" export JAVA_HOME fi fi fi if [ -z "$JAVACMD" ] ; then if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi else JAVACMD="`which java`" fi fi if [ ! -x "$JAVACMD" ] ; then echo "Error: JAVA_HOME is not defined correctly." >&2 echo " We cannot execute $JAVACMD" >&2 exit 1 fi if [ -z "$JAVA_HOME" ] ; then echo "Warning: JAVA_HOME environment variable is not set." fi CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher # For Cygwin, switch paths to Windows format before running java if $cygwin; then [ -n "$M2_HOME" ] && M2_HOME=`cygpath --path --windows "$M2_HOME"` [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"` fi # traverses directory structure from process work directory to filesystem root # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { local basedir=$(pwd) local wdir=$(pwd) while [ "$wdir" != '/' ] ; do if [ -d "$wdir"/.mvn ] ; then basedir=$wdir break fi wdir=$(cd "$wdir/.."; pwd) done echo "${basedir}" } # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then echo "$(tr -s '\n' ' ' < "$1")" fi } export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # Provide a "standardized" way to retrieve the CLI args that will # work with both Windows and non-Windows executions. MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" export MAVEN_CMD_LINE_ARGS WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain exec "$JAVACMD" \ $MAVEN_OPTS \ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${WRAPPER_LAUNCHER} "$@" ================================================ FILE: mvnw.cmd ================================================ @REM ---------------------------------------------------------------------------- @REM Licensed to the Apache Software Foundation (ASF) under one @REM or more contributor license agreements. See the NOTICE file @REM distributed with this work for additional information @REM regarding copyright ownership. The ASF licenses this file @REM to you under the Apache License, Version 2.0 (the @REM "License"); you may not use this file except in compliance @REM with the License. You may obtain a copy of the License at @REM @REM http://www.apache.org/licenses/LICENSE-2.0 @REM @REM Unless required by applicable law or agreed to in writing, @REM software distributed under the License is distributed on an @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @REM KIND, either express or implied. See the License for the @REM specific language governing permissions and limitations @REM under the License. @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- @REM Maven2 Start Up Batch script @REM @REM Required ENV vars: @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars @REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @REM e.g. to debug Maven itself, use @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files @REM ---------------------------------------------------------------------------- @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' @echo off @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% @REM set %HOME% to equivalent of $HOME if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") @REM Execute a user defined script before this one if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre @REM check for pre script, once with legacy .bat ending and once with .cmd ending if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" :skipRcPre @setlocal set ERROR_CODE=0 @REM To isolate internal variables from possible post scripts, we use another setlocal @setlocal @REM ==== START VALIDATION ==== if not "%JAVA_HOME%" == "" goto OkJHome echo. echo Error: JAVA_HOME not found in your environment. >&2 echo Please set the JAVA_HOME variable in your environment to match the >&2 echo location of your Java installation. >&2 echo. goto error :OkJHome if exist "%JAVA_HOME%\bin\java.exe" goto init echo. echo Error: JAVA_HOME is set to an invalid directory. >&2 echo JAVA_HOME = "%JAVA_HOME%" >&2 echo Please set the JAVA_HOME variable in your environment to match the >&2 echo location of your Java installation. >&2 echo. goto error @REM ==== END VALIDATION ==== :init set MAVEN_CMD_LINE_ARGS=%* @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". @REM Fallback to current working directory if not found. set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir set EXEC_DIR=%CD% set WDIR=%EXEC_DIR% :findBaseDir IF EXIST "%WDIR%"\.mvn goto baseDirFound cd .. IF "%WDIR%"=="%CD%" goto baseDirNotFound set WDIR=%CD% goto findBaseDir :baseDirFound set MAVEN_PROJECTBASEDIR=%WDIR% cd "%EXEC_DIR%" goto endDetectBaseDir :baseDirNotFound set MAVEN_PROJECTBASEDIR=%EXEC_DIR% cd "%EXEC_DIR%" :endDetectBaseDir IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig @setlocal EnableExtensions EnableDelayedExpansion for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% :endReadAdditionalConfig SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% if ERRORLEVEL 1 goto error goto end :error set ERROR_CODE=1 :end @endlocal & set ERROR_CODE=%ERROR_CODE% if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost @REM check for post script, once with legacy .bat ending and once with .cmd ending if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" :skipRcPost @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' if "%MAVEN_BATCH_PAUSE%" == "on" pause if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% exit /B %ERROR_CODE% ================================================ FILE: pom.xml ================================================ 4.0.0 com.bookstore bookstore 0.0.1-SNAPSHOT jar eCommerce frontend part org.springframework.boot spring-boot-starter-parent 3.3.1 UTF-8 UTF-8 21 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-security org.springframework.boot spring-boot-starter-mail com.mysql mysql-connector-j org.thymeleaf.extras thymeleaf-extras-springsecurity6 org.springframework.boot spring-boot-starter-test test org.testcontainers junit-jupiter test org.testcontainers mysql test org.springframework.boot spring-boot-maven-plugin ================================================ FILE: src/main/java/com/eCommerce/ECommerceApplication.java ================================================ package com.eCommerce; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class ECommerceApplication { public static void main(String[] args) { SpringApplication.run(ECommerceApplication.class, args); } } ================================================ FILE: src/main/java/com/eCommerce/config/SecurityConfig.java ================================================ package com.eCommerce.config; import com.eCommerce.service.impl.UserSecurityService; import com.eCommerce.utility.SecurityUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration @EnableWebSecurity @EnableMethodSecurity public class SecurityConfig { @Autowired private Environment env; @Autowired private UserSecurityService userSecurityService; private BCryptPasswordEncoder passwordEncoder() { return SecurityUtility.passwordEncoder(); } private static final String[] PUBLIC_MATCHERS = { "/css/**", "/js/**", "/image/**", "/", "/newUser", "/forgetPassword", "/login", "/fonts/**", "/bookshelf", "/bookDetail", "/faq", "/searchByCategory", "/searchBook" }; @Bean public SecurityFilterChain configure(HttpSecurity http) throws Exception { http .cors(AbstractHttpConfigurer::disable) .csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests(authz -> authz .requestMatchers(PUBLIC_MATCHERS).permitAll().anyRequest().authenticated() ) .formLogin(formLogin -> formLogin .loginPage("/login") .defaultSuccessUrl("/", true) .failureUrl("/login?error") ) .logout(logout -> logout .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll() ); return http.build(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userSecurityService).passwordEncoder(passwordEncoder()); } } ================================================ FILE: src/main/java/com/eCommerce/controller/CheckoutController.java ================================================ package com.eCommerce.controller; import java.security.Principal; import java.time.LocalDate; import java.util.Collections; import java.util.List; import java.util.Locale; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import com.eCommerce.domain.BillingAddress; import com.eCommerce.domain.CartItem; import com.eCommerce.domain.Order; import com.eCommerce.domain.Payment; import com.eCommerce.domain.ShippingAddress; import com.eCommerce.domain.ShoppingCart; import com.eCommerce.domain.User; import com.eCommerce.domain.UserBilling; import com.eCommerce.domain.UserPayment; import com.eCommerce.domain.UserShipping; import com.eCommerce.service.BillingAddressService; import com.eCommerce.service.CartItemService; import com.eCommerce.service.OrderService; import com.eCommerce.service.PaymentService; import com.eCommerce.service.ShippingAddressService; import com.eCommerce.service.ShoppingCartService; import com.eCommerce.service.UserPaymentService; import com.eCommerce.service.UserService; import com.eCommerce.service.UserShippingService; import com.eCommerce.utility.MailConstructor; import com.eCommerce.utility.USConstants; @Controller public class CheckoutController { private ShippingAddress shippingAddress = new ShippingAddress(); private BillingAddress billingAddress = new BillingAddress(); private Payment payment = new Payment(); @Autowired private JavaMailSender mailSender; @Autowired private MailConstructor mailConstructor; @Autowired private UserService userService; @Autowired private CartItemService cartItemService; @Autowired private ShoppingCartService shoppingCartService; @Autowired private ShippingAddressService shippingAddressService; @Autowired private BillingAddressService billingAddressService; @Autowired private PaymentService paymentService; @Autowired private UserShippingService userShippingService; @Autowired private UserPaymentService userPaymentService; @Autowired private OrderService orderService; @RequestMapping("/checkout") public String checkout( @RequestParam("id") Long cartId, @RequestParam(value="missingRequiredField", required=false) boolean missingRequiredField, Model model, Principal principal ){ User user = userService.findByUsername(principal.getName()); if(cartId != user.getShoppingCart().getId()) { return "badRequestPage"; } List cartItemList = cartItemService.findByShoppingCart(user.getShoppingCart()); if(cartItemList.size() == 0) { model.addAttribute("emptyCart", true); return "forward:/shoppintCart/cart"; } for (CartItem cartItem : cartItemList) { if(cartItem.getBook().getInStockNumber() < cartItem.getQty()) { model.addAttribute("notEnoughStock", true); return "forward:/shoppingCart/cart"; } } List userShippingList = user.getUserShippingList(); List userPaymentList = user.getUserPaymentList(); model.addAttribute("userShippingList", userShippingList); model.addAttribute("userPaymentList", userPaymentList); if (userPaymentList.size() == 0) { model.addAttribute("emptyPaymentList", true); } else { model.addAttribute("emptyPaymentList", false); } if (userShippingList.size() == 0) { model.addAttribute("emptyShippingList", true); } else { model.addAttribute("emptyShippingList", false); } ShoppingCart shoppingCart = user.getShoppingCart(); for(UserShipping userShipping : userShippingList) { if(userShipping.isUserShippingDefault()) { shippingAddressService.setByUserShipping(userShipping, shippingAddress); } } for (UserPayment userPayment : userPaymentList) { if(userPayment.isDefaultPayment()) { paymentService.setByUserPayment(userPayment, payment); billingAddressService.setByUserBilling(userPayment.getUserBilling(), billingAddress); } } model.addAttribute("shippingAddress", shippingAddress); model.addAttribute("payment", payment); model.addAttribute("billingAddress", billingAddress); model.addAttribute("cartItemList", cartItemList); model.addAttribute("shoppingCart", user.getShoppingCart()); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); model.addAttribute("classActiveShipping", true); if(missingRequiredField) { model.addAttribute("missingRequiredField", true); } return "checkout"; } @RequestMapping(value = "/checkout", method = RequestMethod.POST) public String checkoutPost(@ModelAttribute("shippingAddress") ShippingAddress shippingAddress, @ModelAttribute("billingAddress") BillingAddress billingAddress, @ModelAttribute("payment") Payment payment, @ModelAttribute("billingSameAsShipping") String billingSameAsShipping, @ModelAttribute("shippingMethod") String shippingMethod, Principal principal, Model model) { ShoppingCart shoppingCart = userService.findByUsername(principal.getName()).getShoppingCart(); List cartItemList = cartItemService.findByShoppingCart(shoppingCart); model.addAttribute("cartItemList", cartItemList); if (billingSameAsShipping.equals("true")) { billingAddress.setBillingAddressName(shippingAddress.getShippingAddressName()); billingAddress.setBillingAddressStreet1(shippingAddress.getShippingAddressStreet1()); billingAddress.setBillingAddressStreet2(shippingAddress.getShippingAddressStreet2()); billingAddress.setBillingAddressCity(shippingAddress.getShippingAddressCity()); billingAddress.setBillingAddressState(shippingAddress.getShippingAddressState()); billingAddress.setBillingAddressCountry(shippingAddress.getShippingAddressCountry()); billingAddress.setBillingAddressZipcode(shippingAddress.getShippingAddressZipcode()); } if (shippingAddress.getShippingAddressStreet1().isEmpty() || shippingAddress.getShippingAddressCity().isEmpty() || shippingAddress.getShippingAddressState().isEmpty() || shippingAddress.getShippingAddressName().isEmpty() || shippingAddress.getShippingAddressZipcode().isEmpty() || payment.getCardNumber().isEmpty() || payment.getCvc() == 0 || billingAddress.getBillingAddressStreet1().isEmpty() || billingAddress.getBillingAddressCity().isEmpty() || billingAddress.getBillingAddressState().isEmpty() || billingAddress.getBillingAddressName().isEmpty() || billingAddress.getBillingAddressZipcode().isEmpty()) return "redirect:/checkout?id=" + shoppingCart.getId() + "&missingRequiredField=true"; User user = userService.findByUsername(principal.getName()); Order order = orderService.createOrder(shoppingCart, shippingAddress, billingAddress, payment, shippingMethod, user); mailSender.send(mailConstructor.constructOrderConfirmationEmail(user, order, Locale.ENGLISH)); shoppingCartService.clearShoppingCart(shoppingCart); LocalDate today = LocalDate.now(); LocalDate estimatedDeliveryDate; if (shippingMethod.equals("groundShipping")) { estimatedDeliveryDate = today.plusDays(5); } else { estimatedDeliveryDate = today.plusDays(3); } model.addAttribute("estimatedDeliveryDate", estimatedDeliveryDate); return "orderSubmittedPage"; } @RequestMapping("/setShippingAddress") public String setShippingAddress( @RequestParam("userShippingId") Long userShippingId, Principal principal, Model model ) { User user = userService.findByUsername(principal.getName()); UserShipping userShipping = userShippingService.findById(userShippingId); if(userShipping.getUser().getId() != user.getId()) { return "badRequestPage"; } else { shippingAddressService.setByUserShipping(userShipping, shippingAddress); List cartItemList = cartItemService.findByShoppingCart(user.getShoppingCart()); model.addAttribute("shippingAddress", shippingAddress); model.addAttribute("payment", payment); model.addAttribute("billingAddress", billingAddress); model.addAttribute("cartItemList", cartItemList); model.addAttribute("shoppingCart", user.getShoppingCart()); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); List userShippingList = user.getUserShippingList(); List userPaymentList = user.getUserPaymentList(); model.addAttribute("userShippingList", userShippingList); model.addAttribute("userPaymentList", userPaymentList); model.addAttribute("shippingAddress", shippingAddress); model.addAttribute("classActiveShipping", true); if (userPaymentList.size() == 0) { model.addAttribute("emptyPaymentList", true); } else { model.addAttribute("emptyPaymentList", false); } model.addAttribute("emptyShippingList", false); return "checkout"; } } @RequestMapping("/setPaymentMethod") public String setPaymentMethod( @RequestParam("userPaymentId") Long userPaymentId, Principal principal, Model model ) { User user = userService.findByUsername(principal.getName()); UserPayment userPayment = userPaymentService.findById(userPaymentId); UserBilling userBilling = userPayment.getUserBilling(); if(userPayment.getUser().getId() != user.getId()){ return "badRequestPage"; } else { paymentService.setByUserPayment(userPayment, payment); List cartItemList = cartItemService.findByShoppingCart(user.getShoppingCart()); billingAddressService.setByUserBilling(userBilling, billingAddress); model.addAttribute("shippingAddress", shippingAddress); model.addAttribute("payment", payment); model.addAttribute("billingAddress", billingAddress); model.addAttribute("cartItemList", cartItemList); model.addAttribute("shoppingCart", user.getShoppingCart()); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); List userShippingList = user.getUserShippingList(); List userPaymentList = user.getUserPaymentList(); model.addAttribute("userShippingList", userShippingList); model.addAttribute("userPaymentList", userPaymentList); model.addAttribute("shippingAddress", shippingAddress); model.addAttribute("classActivePayment", true); model.addAttribute("emptyPaymentList", false); if (userShippingList.size() == 0) { model.addAttribute("emptyShippingList", true); } else { model.addAttribute("emptyShippingList", false); } return "checkout"; } } } ================================================ FILE: src/main/java/com/eCommerce/controller/HomeController.java ================================================ package com.eCommerce.controller; import com.eCommerce.domain.Book; import com.eCommerce.domain.CartItem; import com.eCommerce.domain.Order; import com.eCommerce.domain.User; import com.eCommerce.domain.UserBilling; import com.eCommerce.domain.UserPayment; import com.eCommerce.domain.UserShipping; import com.eCommerce.domain.security.PasswordResetToken; import com.eCommerce.domain.security.Role; import com.eCommerce.domain.security.UserRole; import com.eCommerce.service.BookService; import com.eCommerce.service.CartItemService; import com.eCommerce.service.OrderService; import com.eCommerce.service.UserPaymentService; import com.eCommerce.service.UserService; import com.eCommerce.service.UserShippingService; import com.eCommerce.service.impl.UserSecurityService; import com.eCommerce.utility.MailConstructor; import com.eCommerce.utility.SecurityUtility; import com.eCommerce.utility.USConstants; import jakarta.servlet.http.HttpServletRequest; import jakarta.websocket.server.PathParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import java.security.Principal; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; import java.util.UUID; @Controller public class HomeController { @Autowired private JavaMailSender mailSender; @Autowired private MailConstructor mailConstructor; @Autowired private UserService userService; @Autowired private UserSecurityService userSecurityService; @Autowired private BookService bookService; @Autowired private UserPaymentService userPaymentService; @Autowired private UserShippingService userShippingService; @Autowired private CartItemService cartItemService; @Autowired private OrderService orderService; @GetMapping("/") public String index() { return "index"; } @GetMapping("/login") public String login(Model model) { model.addAttribute("classActiveLogin", true); return "myAccount"; } @GetMapping("/faq") public String faq() { return "faq"; } @GetMapping("/bookshelf") public String bookshelf(Model model, Principal principal) { if(principal != null) { String username = principal.getName(); User user = userService.findByUsername(username); model.addAttribute("user", user); } List bookList = bookService.findAll(); model.addAttribute("bookList", bookList); model.addAttribute("activeAll",true); return "bookshelf"; } @GetMapping("/bookDetail") public String bookDetail( @PathParam("id") Long id, Model model, Principal principal ) { if(principal != null) { String username = principal.getName(); User user = userService.findByUsername(username); model.addAttribute("user", user); } Book book = bookService.findById(id); model.addAttribute("book", book); List qtyList = Arrays.asList(1,2,3,4,5,6,7,8,9,10); model.addAttribute("qtyList", qtyList); model.addAttribute("qty", 1); return "bookDetail"; } @GetMapping("/forgetPassword") public String forgetPassword( HttpServletRequest request, @ModelAttribute("email") String email, Model model ) { model.addAttribute("classActiveForgetPassword", true); User user = userService.findByEmail(email); if (user == null) { model.addAttribute("emailNotExist", true); return "myAccount"; } String password = SecurityUtility.randomPassword(); String encryptedPassword = SecurityUtility.passwordEncoder().encode(password); user.setPassword(encryptedPassword); userService.save(user); String token = UUID.randomUUID().toString(); userService.createPasswordResetTokenForUser(user, token); String appUrl = "http://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath(); SimpleMailMessage newEmail = mailConstructor.constructResetTokenEmail(appUrl, request.getLocale(), token, user, password); mailSender.send(newEmail); model.addAttribute("forgetPasswordEmailSent", "true"); return "myAccount"; } @GetMapping("/myProfile") public String myProfile(Model model, Principal principal) { User user = userService.findByUsername(principal.getName()); model.addAttribute("user", user); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); UserShipping userShipping = new UserShipping(); model.addAttribute("userShipping", userShipping); model.addAttribute("listOfCreditCards", true); model.addAttribute("listOfShippingAddresses", true); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); model.addAttribute("classActiveEdit", true); return "myProfile"; } @GetMapping("/listOfCreditCards") public String listOfCreditCards( Model model, Principal principal, HttpServletRequest request ) { User user = userService.findByUsername(principal.getName()); model.addAttribute("user", user); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); model.addAttribute("listOfCreditCards", true); model.addAttribute("classActiveBilling", true); model.addAttribute("listOfShippingAddresses", true); return "myProfile"; } @GetMapping("/listOfShippingAddresses") public String listOfShippingAddresses( Model model, Principal principal, HttpServletRequest request ) { User user = userService.findByUsername(principal.getName()); model.addAttribute("user", user); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); model.addAttribute("listOfCreditCards", true); model.addAttribute("classActiveShipping", true); model.addAttribute("listOfShippingAddresses", true); return "myProfile"; } @GetMapping("/addNewCreditCard") public String addNewCreditCard( Model model, Principal principal ){ User user = userService.findByUsername(principal.getName()); model.addAttribute("user", user); model.addAttribute("addNewCreditCard", true); model.addAttribute("classActiveBilling", true); model.addAttribute("listOfShippingAddresses", true); UserBilling userBilling = new UserBilling(); UserPayment userPayment = new UserPayment(); model.addAttribute("userBilling", userBilling); model.addAttribute("userPayment", userPayment); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } @GetMapping("/addNewShippingAddress") public String addNewShippingAddress( Model model, Principal principal ){ User user = userService.findByUsername(principal.getName()); model.addAttribute("user", user); model.addAttribute("addNewShippingAddress", true); model.addAttribute("classActiveShipping", true); model.addAttribute("listOfCreditCards", true); UserShipping userShipping = new UserShipping(); model.addAttribute("userShipping", userShipping); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } @PostMapping(value = "/addNewCreditCard") public String addNewCreditCard( @ModelAttribute("userPayment") UserPayment userPayment, @ModelAttribute("userBilling") UserBilling userBilling, Principal principal, Model model ){ User user = userService.findByUsername(principal.getName()); userService.updateUserBilling(userBilling, userPayment, user); model.addAttribute("user", user); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("listOfCreditCards", true); model.addAttribute("classActiveBilling", true); model.addAttribute("listOfShippingAddresses", true); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } @PostMapping(value = "/addNewShippingAddress") public String addNewShippingAddressPost( @ModelAttribute("userShipping") UserShipping userShipping, Principal principal, Model model ){ User user = userService.findByUsername(principal.getName()); userService.updateUserShipping(userShipping, user); model.addAttribute("user", user); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("listOfShippingAddresses", true); model.addAttribute("classActiveShipping", true); model.addAttribute("listOfCreditCards", true); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } @GetMapping("/updateCreditCard") public String updateCreditCard( @ModelAttribute("id") Long creditCardId, Principal principal, Model model ) { User user = userService.findByUsername(principal.getName()); UserPayment userPayment = userPaymentService.findById(creditCardId); if(user.getId() != userPayment.getUser().getId()) { return "badRequestPage"; } else { model.addAttribute("user", user); UserBilling userBilling = userPayment.getUserBilling(); model.addAttribute("userPayment", userPayment); model.addAttribute("userBilling", userBilling); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); model.addAttribute("addNewCreditCard", true); model.addAttribute("classActiveBilling", true); model.addAttribute("listOfShippingAddresses", true); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } } @GetMapping("/updateUserShipping") public String updateUserShipping( @ModelAttribute("id") Long shippingAddressId, Principal principal, Model model ) { User user = userService.findByUsername(principal.getName()); UserShipping userShipping = userShippingService.findById(shippingAddressId); if(user.getId() != userShipping.getUser().getId()) { return "badRequestPage"; } else { model.addAttribute("user", user); model.addAttribute("userShipping", userShipping); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); model.addAttribute("addNewShippingAddress", true); model.addAttribute("classActiveShipping", true); model.addAttribute("listOfCreditCards", true); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } } @PostMapping(value = "/setDefaultPayment") public String setDefaultPayment( @ModelAttribute("defaultUserPaymentId") Long defaultPaymentId, Principal principal, Model model ) { User user = userService.findByUsername(principal.getName()); userService.setUserDefaultPayment(defaultPaymentId, user); model.addAttribute("user", user); model.addAttribute("listOfCreditCards", true); model.addAttribute("classActiveBilling", true); model.addAttribute("listOfShippingAddresses", true); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } @PostMapping(value = "/setDefaultShippingAddress") public String setDefaultShippingAddress( @ModelAttribute("defaultShippingAddressId") Long defaultShippingId, Principal principal, Model model ) { User user = userService.findByUsername(principal.getName()); userService.setUserDefaultShipping(defaultShippingId, user); model.addAttribute("user", user); model.addAttribute("listOfCreditCards", true); model.addAttribute("classActiveShipping", true); model.addAttribute("listOfShippingAddresses", true); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } @GetMapping("/removeCreditCard") public String removeCreditCard( @ModelAttribute("id") Long creditCardId, Principal principal, Model model ){ User user = userService.findByUsername(principal.getName()); UserPayment userPayment = userPaymentService.findById(creditCardId); if(user.getId() != userPayment.getUser().getId()) { return "badRequestPage"; } else { model.addAttribute("user", user); userPaymentService.deleteById(creditCardId); model.addAttribute("listOfCreditCards", true); model.addAttribute("classActiveBilling", true); model.addAttribute("listOfShippingAddresses", true); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } } @GetMapping("/removeUserShipping") public String removeUserShipping( @ModelAttribute("id") Long userShippingId, Principal principal, Model model ){ User user = userService.findByUsername(principal.getName()); UserShipping userShipping = userShippingService.findById(userShippingId); if(user.getId() != userShipping.getUser().getId()) { return "badRequestPage"; } else { model.addAttribute("user", user); userShippingService.deleteById(userShippingId); model.addAttribute("listOfShippingAddresses", true); model.addAttribute("classActiveShipping", true); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } } @PostMapping(value = "/newUser") public String newUserPost( HttpServletRequest request, @ModelAttribute("email") String userEmail, @ModelAttribute("username") String username, Model model ) throws Exception{ model.addAttribute("classActiveNewAccount", true); model.addAttribute("email", userEmail); model.addAttribute("username", username); if (userService.findByUsername(username) != null) { model.addAttribute("usernameExists", true); return "myAccount"; } if (userService.findByEmail(userEmail) != null) { model.addAttribute("emailExists", true); return "myAccount"; } User user = new User(); user.setUsername(username); user.setEmail(userEmail); String password = SecurityUtility.randomPassword(); String encryptedPassword = SecurityUtility.passwordEncoder().encode(password); user.setPassword(encryptedPassword); Role role = new Role(); role.setRoleId(1); role.setName("ROLE_USER"); Set userRoles = new HashSet<>(); userRoles.add(new UserRole(user, role)); userService.createUser(user, userRoles); String token = UUID.randomUUID().toString(); userService.createPasswordResetTokenForUser(user, token); String appUrl = "http://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath(); SimpleMailMessage email = mailConstructor.constructResetTokenEmail(appUrl, request.getLocale(), token, user, password); mailSender.send(email); model.addAttribute("emailSent", "true"); model.addAttribute("orderList", user.getOrderList()); return "myAccount"; } @GetMapping("/newUser") public String newUser(Locale locale, @RequestParam("token") String token, Model model) { PasswordResetToken passToken = userService.getPasswordResetToken(token); if (passToken == null) { String message = "Invalid Token."; model.addAttribute("message", message); return "redirect:/badRequest"; } User user = passToken.getUser(); String username = user.getUsername(); UserDetails userDetails = userSecurityService.loadUserByUsername(username); Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities()); SecurityContextHolder.getContext().setAuthentication(authentication); model.addAttribute("user", user); model.addAttribute("classActiveEdit", true); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } @PostMapping(value = "/updateUserInfo") public String updateUserInfo( @ModelAttribute("user") User user, @ModelAttribute("newPassword") String newPassword, Model model ) throws Exception { User currentUser = userService.findById(user.getId()); if(currentUser == null) { throw new Exception ("User not found"); } /*check email already exists*/ if (userService.findByEmail(user.getEmail())!=null) { if(userService.findByEmail(user.getEmail()).getId() != currentUser.getId()) { model.addAttribute("emailExists", true); return "myProfile"; } } /*check username already exists*/ if (userService.findByUsername(user.getUsername())!=null) { if(userService.findByUsername(user.getUsername()).getId() != currentUser.getId()) { model.addAttribute("usernameExists", true); return "myProfile"; } } // update password if (newPassword != null && !newPassword.isEmpty() && !newPassword.equals("")){ BCryptPasswordEncoder passwordEncoder = SecurityUtility.passwordEncoder(); String dbPassword = currentUser.getPassword(); if(passwordEncoder.matches(user.getPassword(), dbPassword)){ currentUser.setPassword(passwordEncoder.encode(newPassword)); } else { model.addAttribute("incorrectPassword", true); return "myProfile"; } } currentUser.setFirstName(user.getFirstName()); currentUser.setLastName(user.getLastName()); currentUser.setUsername(user.getUsername()); currentUser.setEmail(user.getEmail()); userService.save(currentUser); model.addAttribute("updateSuccess", true); model.addAttribute("user", currentUser); model.addAttribute("classActiveEdit", true); UserDetails userDetails = userSecurityService.loadUserByUsername(currentUser.getUsername()); Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities()); SecurityContextHolder.getContext().setAuthentication(authentication); model.addAttribute("orderList", user.getOrderList()); return "myProfile"; } @GetMapping("/orderDetail") public String orderDetail( @RequestParam("id") Long orderId, Principal principal, Model model ){ User user = userService.findByUsername(principal.getName()); Order order = orderService.findById(orderId); if(order.getUser().getId()!=user.getId()) { return "badRequestPage"; } else { List cartItemList = cartItemService.findByOrder(order); model.addAttribute("cartItemList", cartItemList); model.addAttribute("user", user); model.addAttribute("order", order); model.addAttribute("userPaymentList", user.getUserPaymentList()); model.addAttribute("userShippingList", user.getUserShippingList()); model.addAttribute("orderList", user.getOrderList()); UserShipping userShipping = new UserShipping(); model.addAttribute("userShipping", userShipping); List stateList = USConstants.listOfUSStatesCode; Collections.sort(stateList); model.addAttribute("stateList", stateList); model.addAttribute("listOfShippingAddresses", true); model.addAttribute("classActiveOrders", true); model.addAttribute("listOfCreditCards", true); model.addAttribute("displayOrderDetail", true); return "myProfile"; } } } ================================================ FILE: src/main/java/com/eCommerce/controller/SearchController.java ================================================ package com.eCommerce.controller; import java.security.Principal; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import com.eCommerce.domain.Book; import com.eCommerce.domain.User; import com.eCommerce.service.BookService; import com.eCommerce.service.UserService; @Controller public class SearchController { @Autowired private UserService userService; @Autowired private BookService bookService; @RequestMapping("/searchByCategory") public String searchByCategory( @RequestParam("category") String category, Model model, Principal principal ){ if(principal!=null) { String username = principal.getName(); User user = userService.findByUsername(username); model.addAttribute("user", user); } String classActiveCategory = "active"+category; classActiveCategory = classActiveCategory.replaceAll("\\s+", ""); classActiveCategory = classActiveCategory.replaceAll("&", ""); model.addAttribute(classActiveCategory, true); List bookList = bookService.findByCategory(category); if (bookList.isEmpty()) { model.addAttribute("emptyList", true); return "bookshelf"; } model.addAttribute("bookList", bookList); return "bookshelf"; } @RequestMapping("/searchBook") public String searchBook( @ModelAttribute("keyword") String keyword, Principal principal, Model model ) { if(principal!=null) { String username = principal.getName(); User user = userService.findByUsername(username); model.addAttribute("user", user); } List bookList = bookService.blurrySearch(keyword); if (bookList.isEmpty()) { model.addAttribute("emptyList", true); return "bookshelf"; } model.addAttribute("bookList", bookList); return "bookshelf"; } } ================================================ FILE: src/main/java/com/eCommerce/controller/ShoppingCartController.java ================================================ package com.eCommerce.controller; import java.security.Principal; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import com.eCommerce.domain.Book; import com.eCommerce.domain.CartItem; import com.eCommerce.domain.ShoppingCart; import com.eCommerce.domain.User; import com.eCommerce.service.BookService; import com.eCommerce.service.CartItemService; import com.eCommerce.service.ShoppingCartService; import com.eCommerce.service.UserService; @Controller @RequestMapping("/shoppingCart") public class ShoppingCartController { @Autowired private UserService userService; @Autowired private CartItemService cartItemService; @Autowired private BookService bookService; @Autowired private ShoppingCartService shoppingCartService; @RequestMapping("/cart") public String shoppingCart(Model model, Principal principal) { User user = userService.findByUsername(principal.getName()); ShoppingCart shoppingCart = user.getShoppingCart(); List cartItemList = cartItemService.findByShoppingCart(shoppingCart); shoppingCartService.updateShoppingCart(shoppingCart); model.addAttribute("cartItemList", cartItemList); model.addAttribute("shoppingCart", shoppingCart); return "shoppingCart"; } @RequestMapping("/addItem") public String addItem( @ModelAttribute("book") Book book, @ModelAttribute("qty") String qty, Model model, Principal principal ) { User user = userService.findByUsername(principal.getName()); book = bookService.findById(book.getId()); if (Integer.parseInt(qty) > book.getInStockNumber()) { model.addAttribute("notEnoughStock", true); return "forward:/bookDetail?id="+book.getId(); } CartItem cartItem = cartItemService.addBookToCartItem(book, user, Integer.parseInt(qty)); model.addAttribute("addBookSuccess", true); return "forward:/bookDetail?id="+book.getId(); } @RequestMapping("/updateCartItem") public String updateShoppingCart( @ModelAttribute("id") Long cartItemId, @ModelAttribute("qty") int qty ) { CartItem cartItem = cartItemService.findById(cartItemId); cartItem.setQty(qty); cartItemService.updateCartItem(cartItem); return "forward:/shoppingCart/cart"; } @RequestMapping("/removeItem") public String removeItem(@RequestParam("id") Long id) { cartItemService.removeCartItem(cartItemService.findById(id)); return "forward:/shoppingCart/cart"; } } ================================================ FILE: src/main/java/com/eCommerce/domain/BillingAddress.java ================================================ package com.eCommerce.domain; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; @Entity public class BillingAddress { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String BillingAddressName; private String BillingAddressStreet1; private String BillingAddressStreet2; private String BillingAddressCity; private String BillingAddressState; private String BillingAddressCountry; private String BillingAddressZipcode; @OneToOne private Order order; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getBillingAddressName() { return BillingAddressName; } public void setBillingAddressName(String billingAddressName) { BillingAddressName = billingAddressName; } public String getBillingAddressStreet1() { return BillingAddressStreet1; } public void setBillingAddressStreet1(String billingAddressStreet1) { BillingAddressStreet1 = billingAddressStreet1; } public String getBillingAddressStreet2() { return BillingAddressStreet2; } public void setBillingAddressStreet2(String billingAddressStreet2) { BillingAddressStreet2 = billingAddressStreet2; } public String getBillingAddressCity() { return BillingAddressCity; } public void setBillingAddressCity(String billingAddressCity) { BillingAddressCity = billingAddressCity; } public String getBillingAddressState() { return BillingAddressState; } public void setBillingAddressState(String billingAddressState) { BillingAddressState = billingAddressState; } public String getBillingAddressCountry() { return BillingAddressCountry; } public void setBillingAddressCountry(String billingAddressCountry) { BillingAddressCountry = billingAddressCountry; } public String getBillingAddressZipcode() { return BillingAddressZipcode; } public void setBillingAddressZipcode(String billingAddressZipcode) { BillingAddressZipcode = billingAddressZipcode; } public Order getOrder() { return order; } public void setOrder(Order order) { this.order = order; } } ================================================ FILE: src/main/java/com/eCommerce/domain/Book.java ================================================ package com.eCommerce.domain; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.Transient; import org.springframework.web.multipart.MultipartFile; import java.util.List; @Entity public class Book { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String title; private String author; private String publisher; private String publicationDate; private String language; private String category; private int numberOfPages; private String format; private int isbn; private double shippingWeight; private double listPrice; private double ourPrice; private boolean active=true; @Column(columnDefinition="text") private String description; private int inStockNumber; @Transient private MultipartFile bookImage; @OneToMany(mappedBy = "book") @JsonIgnore private List bookToCartItemList; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getPublisher() { return publisher; } public void setPublisher(String publisher) { this.publisher = publisher; } public String getPublicationDate() { return publicationDate; } public void setPublicationDate(String publicationDate) { this.publicationDate = publicationDate; } public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } public int getNumberOfPages() { return numberOfPages; } public void setNumberOfPages(int numberOfPages) { this.numberOfPages = numberOfPages; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public int getIsbn() { return isbn; } public void setIsbn(int isbn) { this.isbn = isbn; } public double getShippingWeight() { return shippingWeight; } public void setShippingWeight(double shippingWeight) { this.shippingWeight = shippingWeight; } public double getListPrice() { return listPrice; } public void setListPrice(double listPrice) { this.listPrice = listPrice; } public double getOurPrice() { return ourPrice; } public void setOurPrice(double ourPrice) { this.ourPrice = ourPrice; } public boolean isActive() { return active; } public void setActive(boolean active) { this.active = active; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getInStockNumber() { return inStockNumber; } public void setInStockNumber(int inStockNumber) { this.inStockNumber = inStockNumber; } public MultipartFile getBookImage() { return bookImage; } public void setBookImage(MultipartFile bookImage) { this.bookImage = bookImage; } } ================================================ FILE: src/main/java/com/eCommerce/domain/BookToCartItem.java ================================================ package com.eCommerce.domain; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; @Entity public class BookToCartItem { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ManyToOne @JoinColumn(name="book_id") private Book book; @ManyToOne @JoinColumn(name="cart_item_id") private CartItem cartItem; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Book getBook() { return book; } public void setBook(Book book) { this.book = book; } public CartItem getCartItem() { return cartItem; } public void setCartItem(CartItem cartItem) { this.cartItem = cartItem; } } ================================================ FILE: src/main/java/com/eCommerce/domain/CartItem.java ================================================ package com.eCommerce.domain; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import java.math.BigDecimal; import java.util.List; @Entity public class CartItem { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private int qty; private BigDecimal subtotal; @OneToOne private Book book; @OneToMany(mappedBy = "cartItem") @JsonIgnore private List bookToCartItemList; @ManyToOne @JoinColumn(name="shopping_cart_id") private ShoppingCart shoppingCart; @ManyToOne @JoinColumn(name="order_id") private Order order; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public int getQty() { return qty; } public void setQty(int qty) { this.qty = qty; } public BigDecimal getSubtotal() { return subtotal; } public void setSubtotal(BigDecimal subtotal) { this.subtotal = subtotal; } public Book getBook() { return book; } public void setBook(Book book) { this.book = book; } public List getBookToCartItemList() { return bookToCartItemList; } public void setBookToCartItemList(List bookToCartItemList) { this.bookToCartItemList = bookToCartItemList; } public ShoppingCart getShoppingCart() { return shoppingCart; } public void setShoppingCart(ShoppingCart shoppingCart) { this.shoppingCart = shoppingCart; } public Order getOrder() { return order; } public void setOrder(Order order) { this.order = order; } } ================================================ FILE: src/main/java/com/eCommerce/domain/Order.java ================================================ package com.eCommerce.domain; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import java.math.BigDecimal; import java.util.Date; import java.util.List; @Entity @Table(name="user_order") public class Order { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private Date orderDate; private Date shippingDate; private String shippingMethod; private String orderStatus; private BigDecimal orderTotal; @OneToMany(mappedBy = "order", cascade = CascadeType.ALL) private List cartItemList; @OneToOne(cascade=CascadeType.ALL) private ShippingAddress shippingAddress; @OneToOne(cascade=CascadeType.ALL) private BillingAddress billingAddress; @OneToOne(cascade=CascadeType.ALL) private Payment payment; @ManyToOne private User user; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Date getOrderDate() { return orderDate; } public void setOrderDate(Date orderDate) { this.orderDate = orderDate; } public Date getShippingDate() { return shippingDate; } public void setShippingDate(Date shippingDate) { this.shippingDate = shippingDate; } public String getShippingMethod() { return shippingMethod; } public void setShippingMethod(String shippingMethod) { this.shippingMethod = shippingMethod; } public String getOrderStatus() { return orderStatus; } public void setOrderStatus(String orderStatus) { this.orderStatus = orderStatus; } public BigDecimal getOrderTotal() { return orderTotal; } public void setOrderTotal(BigDecimal orderTotal) { this.orderTotal = orderTotal; } public List getCartItemList() { return cartItemList; } public void setCartItemList(List cartItemList) { this.cartItemList = cartItemList; } public ShippingAddress getShippingAddress() { return shippingAddress; } public void setShippingAddress(ShippingAddress shippingAddress) { this.shippingAddress = shippingAddress; } public Payment getPayment() { return payment; } public void setPayment(Payment payment) { this.payment = payment; } public BillingAddress getBillingAddress() { return billingAddress; } public void setBillingAddress(BillingAddress billingAddress) { this.billingAddress = billingAddress; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } } ================================================ FILE: src/main/java/com/eCommerce/domain/Payment.java ================================================ package com.eCommerce.domain; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; @Entity public class Payment { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String type; private String cardName; private String cardNumber; private int expiryMonth; private int expiryYear; private int cvc; private String holderName; @OneToOne private Order order; @OneToOne(cascade = CascadeType.ALL, mappedBy = "userPayment") private UserBilling userBilling; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getCardName() { return cardName; } public void setCardName(String cardName) { this.cardName = cardName; } public String getCardNumber() { return cardNumber; } public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } public int getExpiryMonth() { return expiryMonth; } public void setExpiryMonth(int expiryMonth) { this.expiryMonth = expiryMonth; } public int getExpiryYear() { return expiryYear; } public void setExpiryYear(int expiryYear) { this.expiryYear = expiryYear; } public int getCvc() { return cvc; } public void setCvc(int cvc) { this.cvc = cvc; } public String getHolderName() { return holderName; } public void setHolderName(String holderName) { this.holderName = holderName; } public Order getOrder() { return order; } public void setOrder(Order order) { this.order = order; } public UserBilling getUserBilling() { return userBilling; } public void setUserBilling(UserBilling userBilling) { this.userBilling = userBilling; } } ================================================ FILE: src/main/java/com/eCommerce/domain/ShippingAddress.java ================================================ package com.eCommerce.domain; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; @Entity public class ShippingAddress { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String ShippingAddressName; private String ShippingAddressStreet1; private String ShippingAddressStreet2; private String ShippingAddressCity; private String ShippingAddressState; private String ShippingAddressCountry; private String ShippingAddressZipcode; @OneToOne private Order order; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getShippingAddressName() { return ShippingAddressName; } public void setShippingAddressName(String shippingAddressName) { ShippingAddressName = shippingAddressName; } public String getShippingAddressStreet1() { return ShippingAddressStreet1; } public void setShippingAddressStreet1(String shippingAddressStreet1) { ShippingAddressStreet1 = shippingAddressStreet1; } public String getShippingAddressStreet2() { return ShippingAddressStreet2; } public void setShippingAddressStreet2(String shippingAddressStreet2) { ShippingAddressStreet2 = shippingAddressStreet2; } public String getShippingAddressCity() { return ShippingAddressCity; } public void setShippingAddressCity(String shippingAddressCity) { ShippingAddressCity = shippingAddressCity; } public String getShippingAddressState() { return ShippingAddressState; } public void setShippingAddressState(String shippingAddressState) { ShippingAddressState = shippingAddressState; } public String getShippingAddressCountry() { return ShippingAddressCountry; } public void setShippingAddressCountry(String shippingAddressCountry) { ShippingAddressCountry = shippingAddressCountry; } public String getShippingAddressZipcode() { return ShippingAddressZipcode; } public void setShippingAddressZipcode(String shippingAddressZipcode) { ShippingAddressZipcode = shippingAddressZipcode; } public Order getOrder() { return order; } public void setOrder(Order order) { this.order = order; } } ================================================ FILE: src/main/java/com/eCommerce/domain/ShoppingCart.java ================================================ package com.eCommerce.domain; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import java.math.BigDecimal; import java.util.List; @Entity public class ShoppingCart { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private BigDecimal GrandTotal; @OneToMany(mappedBy = "shoppingCart", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JsonIgnore private List cartItemList; @OneToOne(cascade = CascadeType.ALL) private User user; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public BigDecimal getGrandTotal() { return GrandTotal; } public void setGrandTotal(BigDecimal grandTotal) { GrandTotal = grandTotal; } public List getCartItemList() { return cartItemList; } public void setCartItemList(List cartItemList) { this.cartItemList = cartItemList; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } } ================================================ FILE: src/main/java/com/eCommerce/domain/User.java ================================================ package com.eCommerce.domain; import com.eCommerce.domain.security.Authority; import com.eCommerce.domain.security.UserRole; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; @Entity public class User implements UserDetails{ @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="id", nullable = false, updatable = false) private Long id; private String username; private String password; private String firstName; private String lastName; @Column(name="email", nullable = false, updatable = false) private String email; private String phone; private boolean enabled=true; @OneToOne(cascade = CascadeType.ALL, mappedBy = "user") private ShoppingCart shoppingCart; @OneToMany(cascade = CascadeType.ALL, mappedBy = "user") private List userShippingList; @OneToMany(cascade = CascadeType.ALL, mappedBy = "user") private List userPaymentList; @OneToMany(mappedBy = "user") private List orderList; @OneToMany(mappedBy = "user", cascade = CascadeType.MERGE, fetch = FetchType.EAGER) @JsonIgnore private Set userRoles = new HashSet<>(); public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public Set getUserRoles() { return userRoles; } public void setUserRoles(Set userRoles) { this.userRoles = userRoles; } public List getUserShippingList() { return userShippingList; } public void setUserShippingList(List userShippingList) { this.userShippingList = userShippingList; } public List getUserPaymentList() { return userPaymentList; } public void setUserPaymentList(List userPaymentList) { this.userPaymentList = userPaymentList; } public ShoppingCart getShoppingCart() { return shoppingCart; } public void setShoppingCart(ShoppingCart shoppingCart) { this.shoppingCart = shoppingCart; } public List getOrderList() { return orderList; } public void setOrderList(List orderList) { this.orderList = orderList; } @Override public Collection getAuthorities() { Set authorites = new HashSet<>(); userRoles.forEach(ur -> authorites.add(new Authority(ur.getRole().getName()))); return authorites; } @Override public boolean isAccountNonExpired() { // TODO Auto-generated method stub return true; } @Override public boolean isAccountNonLocked() { // TODO Auto-generated method stub return true; } @Override public boolean isCredentialsNonExpired() { // TODO Auto-generated method stub return true; } @Override public boolean isEnabled() { return enabled; } } ================================================ FILE: src/main/java/com/eCommerce/domain/UserBilling.java ================================================ package com.eCommerce.domain; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; @Entity public class UserBilling { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String userBillingName; private String userBillingStreet1; private String userBillingStreet2; private String userBillingCity; private String userBillingState; private String userBillingCountry; private String userBillingZipcode; @OneToOne(cascade = CascadeType.ALL) private UserPayment userPayment; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUserBillingName() { return userBillingName; } public void setUserBillingName(String userBillingName) { this.userBillingName = userBillingName; } public String getUserBillingStreet1() { return userBillingStreet1; } public void setUserBillingStreet1(String userBillingStreet1) { this.userBillingStreet1 = userBillingStreet1; } public String getUserBillingStreet2() { return userBillingStreet2; } public void setUserBillingStreet2(String userBillingStreet2) { this.userBillingStreet2 = userBillingStreet2; } public String getUserBillingCity() { return userBillingCity; } public void setUserBillingCity(String userBillingCity) { this.userBillingCity = userBillingCity; } public String getUserBillingState() { return userBillingState; } public void setUserBillingState(String userBillingState) { this.userBillingState = userBillingState; } public String getUserBillingCountry() { return userBillingCountry; } public void setUserBillingCountry(String userBillingCountry) { this.userBillingCountry = userBillingCountry; } public String getUserBillingZipcode() { return userBillingZipcode; } public void setUserBillingZipcode(String userBillingZipcode) { this.userBillingZipcode = userBillingZipcode; } public UserPayment getUserPayment() { return userPayment; } public void setUserPayment(UserPayment userPayment) { this.userPayment = userPayment; } } ================================================ FILE: src/main/java/com/eCommerce/domain/UserPayment.java ================================================ package com.eCommerce.domain; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToOne; @Entity public class UserPayment { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String type; private String cardName; private String cardNumber; private int expiryMonth; private int expiryYear; private int cvc; private String holderName; private boolean defaultPayment; @ManyToOne @JoinColumn(name="user_id") private User user; @OneToOne(cascade = CascadeType.ALL, mappedBy = "userPayment",orphanRemoval = true) private UserBilling userBilling; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getCardName() { return cardName; } public void setCardName(String cardName) { this.cardName = cardName; } public String getCardNumber() { return cardNumber; } public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } public int getExpiryMonth() { return expiryMonth; } public void setExpiryMonth(int expiryMonth) { this.expiryMonth = expiryMonth; } public int getExpiryYear() { return expiryYear; } public void setExpiryYear(int expiryYear) { this.expiryYear = expiryYear; } public int getCvc() { return cvc; } public void setCvc(int cvc) { this.cvc = cvc; } public String getHolderName() { return holderName; } public void setHolderName(String holderName) { this.holderName = holderName; } public boolean isDefaultPayment() { return defaultPayment; } public void setDefaultPayment(boolean defaultPayment) { this.defaultPayment = defaultPayment; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public UserBilling getUserBilling() { return userBilling; } public void setUserBilling(UserBilling userBilling) { this.userBilling = userBilling; } } ================================================ FILE: src/main/java/com/eCommerce/domain/UserShipping.java ================================================ package com.eCommerce.domain; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; @Entity public class UserShipping { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String userShippingName; private String userShippingStreet1; private String userShippingStreet2; private String userShippingCity; private String userShippingState; private String userShippingCountry; private String userShippingZipcode; private boolean userShippingDefault; @ManyToOne @JoinColumn(name = "user_id") private User user; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUserShippingName() { return userShippingName; } public void setUserShippingName(String userShippingName) { this.userShippingName = userShippingName; } public String getUserShippingStreet1() { return userShippingStreet1; } public void setUserShippingStreet1(String userShippingStreet1) { this.userShippingStreet1 = userShippingStreet1; } public String getUserShippingStreet2() { return userShippingStreet2; } public void setUserShippingStreet2(String userShippingStreet2) { this.userShippingStreet2 = userShippingStreet2; } public String getUserShippingCity() { return userShippingCity; } public void setUserShippingCity(String userShippingCity) { this.userShippingCity = userShippingCity; } public String getUserShippingState() { return userShippingState; } public void setUserShippingState(String userShippingState) { this.userShippingState = userShippingState; } public String getUserShippingCountry() { return userShippingCountry; } public void setUserShippingCountry(String userShippingCountry) { this.userShippingCountry = userShippingCountry; } public String getUserShippingZipcode() { return userShippingZipcode; } public void setUserShippingZipcode(String userShippingZipcode) { this.userShippingZipcode = userShippingZipcode; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public boolean isUserShippingDefault() { return userShippingDefault; } public void setUserShippingDefault(boolean userShippingDefault) { this.userShippingDefault = userShippingDefault; } } ================================================ FILE: src/main/java/com/eCommerce/domain/security/Authority.java ================================================ package com.eCommerce.domain.security; import org.springframework.security.core.GrantedAuthority; public class Authority implements GrantedAuthority{ private final String authority; public Authority(String authority) { this.authority = authority; } @Override public String getAuthority() { return authority; } } ================================================ FILE: src/main/java/com/eCommerce/domain/security/PasswordResetToken.java ================================================ package com.eCommerce.domain.security; import com.eCommerce.domain.User; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; import java.util.Calendar; import java.util.Date; @Entity public class PasswordResetToken { private static final int EXPIRATION = 60 * 24; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String token; @OneToOne(targetEntity = User.class, fetch = FetchType.EAGER) @JoinColumn(nullable=false, name="user_id") private User user; private Date expiryDate; public PasswordResetToken(){} public PasswordResetToken(final String token, final User user) { super (); this.token = token; this.user = user; this.expiryDate = calculateExpiryDate(EXPIRATION); } private Date calculateExpiryDate (final int expiryTimeInMinutes) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(new Date().getTime()); cal.add(Calendar.MINUTE, expiryTimeInMinutes); return new Date(cal.getTime().getTime()); } public void updateToken(final String token) { this.token = token; this.expiryDate = calculateExpiryDate(EXPIRATION); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Date getExpiryDate() { return expiryDate; } public void setExpiryDate(Date expiryDate) { this.expiryDate = expiryDate; } public static int getExpiration() { return EXPIRATION; } @Override public String toString() { return "PasswordResetToken [id=" + id + ", token=" + token + ", user=" + user + ", expiryDate=" + expiryDate + "]"; } } ================================================ FILE: src/main/java/com/eCommerce/domain/security/Role.java ================================================ package com.eCommerce.domain.security; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import java.util.HashSet; import java.util.Set; @Entity public class Role { @Id private int roleId; private String name; @OneToMany(mappedBy = "role", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private Set userRoles = new HashSet<>(); public int getRoleId() { return roleId; } public void setRoleId(int roleId) { this.roleId = roleId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set getUserRoles() { return userRoles; } public void setUserRoles(Set userRoles) { this.userRoles = userRoles; } } ================================================ FILE: src/main/java/com/eCommerce/domain/security/UserRole.java ================================================ package com.eCommerce.domain.security; import com.eCommerce.domain.User; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; @Entity @Table(name="user_role") public class UserRole { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long userRoleId; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name="user_id") private User user; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name="role_id") private Role role; public UserRole(){} public UserRole(User user, Role role) { this.user = user; this.role = role; } public Long getUserRoleId() { return userRoleId; } public void setUserRoleId(Long userRoleId) { this.userRoleId = userRoleId; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Role getRole() { return role; } public void setRole(Role role) { this.role = role; } } ================================================ FILE: src/main/java/com/eCommerce/repository/BookRepository.java ================================================ package com.eCommerce.repository; import java.util.List; import org.springframework.data.repository.CrudRepository; import com.eCommerce.domain.Book; public interface BookRepository extends CrudRepository{ List findByCategory(String category); List findByTitleContaining(String title); } ================================================ FILE: src/main/java/com/eCommerce/repository/BookToCartItemRepository.java ================================================ package com.eCommerce.repository; import org.springframework.data.repository.CrudRepository; import org.springframework.transaction.annotation.Transactional; import com.eCommerce.domain.BookToCartItem; import com.eCommerce.domain.CartItem; @Transactional public interface BookToCartItemRepository extends CrudRepository { void deleteByCartItem(CartItem cartItem); } ================================================ FILE: src/main/java/com/eCommerce/repository/CartItemRepository.java ================================================ package com.eCommerce.repository; import java.util.List; import org.springframework.data.repository.CrudRepository; import com.eCommerce.domain.CartItem; import com.eCommerce.domain.Order; import com.eCommerce.domain.ShoppingCart; public interface CartItemRepository extends CrudRepository{ List findByShoppingCart(ShoppingCart shoppingCart); List findByOrder(Order order); } ================================================ FILE: src/main/java/com/eCommerce/repository/OrderRepository.java ================================================ package com.eCommerce.repository; import org.springframework.data.repository.CrudRepository; import com.eCommerce.domain.Order; public interface OrderRepository extends CrudRepository{ } ================================================ FILE: src/main/java/com/eCommerce/repository/PasswordResetTokenRepository.java ================================================ package com.eCommerce.repository; import java.util.Date; import java.util.stream.Stream; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import com.eCommerce.domain.User; import com.eCommerce.domain.security.PasswordResetToken; public interface PasswordResetTokenRepository extends JpaRepository { PasswordResetToken findByToken(String token); PasswordResetToken findByUser(User user); Stream findAllByExpiryDateLessThan(Date now); @Modifying @Query("delete from PasswordResetToken t where t.expiryDate <= ?1") void deleteAllExpiredSince(Date now); } ================================================ FILE: src/main/java/com/eCommerce/repository/RoleRepository.java ================================================ package com.eCommerce.repository; import org.springframework.data.repository.CrudRepository; import com.eCommerce.domain.security.Role; public interface RoleRepository extends CrudRepository { Role findByname(String name); } ================================================ FILE: src/main/java/com/eCommerce/repository/ShoppingCartRepository.java ================================================ package com.eCommerce.repository; import org.springframework.data.repository.CrudRepository; import com.eCommerce.domain.ShoppingCart; public interface ShoppingCartRepository extends CrudRepository { } ================================================ FILE: src/main/java/com/eCommerce/repository/UserPaymentRepository.java ================================================ package com.eCommerce.repository; import org.springframework.data.repository.CrudRepository; import com.eCommerce.domain.UserPayment; public interface UserPaymentRepository extends CrudRepository{ } ================================================ FILE: src/main/java/com/eCommerce/repository/UserRepository.java ================================================ package com.eCommerce.repository; import org.springframework.data.repository.CrudRepository; import com.eCommerce.domain.User; public interface UserRepository extends CrudRepository { User findByUsername(String username); User findByEmail(String email); } ================================================ FILE: src/main/java/com/eCommerce/repository/UserShippingRepository.java ================================================ package com.eCommerce.repository; import org.springframework.data.repository.CrudRepository; import com.eCommerce.domain.UserShipping; public interface UserShippingRepository extends CrudRepository { } ================================================ FILE: src/main/java/com/eCommerce/service/BillingAddressService.java ================================================ package com.eCommerce.service; import com.eCommerce.domain.BillingAddress; import com.eCommerce.domain.UserBilling; public interface BillingAddressService { BillingAddress setByUserBilling(UserBilling userBilling, BillingAddress billingAddress); } ================================================ FILE: src/main/java/com/eCommerce/service/BookService.java ================================================ package com.eCommerce.service; import java.util.List; import com.eCommerce.domain.Book; public interface BookService { List findAll (); Book findById(Long id); List findByCategory(String category); List blurrySearch(String title); } ================================================ FILE: src/main/java/com/eCommerce/service/CartItemService.java ================================================ package com.eCommerce.service; import java.util.List; import com.eCommerce.domain.Book; import com.eCommerce.domain.CartItem; import com.eCommerce.domain.Order; import com.eCommerce.domain.ShoppingCart; import com.eCommerce.domain.User; public interface CartItemService { List findByShoppingCart(ShoppingCart shoppingCart); CartItem updateCartItem(CartItem cartItem); CartItem addBookToCartItem(Book book, User user, int qty); CartItem findById(Long id); void removeCartItem(CartItem cartItem); CartItem save(CartItem cartItem); List findByOrder(Order order); } ================================================ FILE: src/main/java/com/eCommerce/service/OrderService.java ================================================ package com.eCommerce.service; import com.eCommerce.domain.BillingAddress; import com.eCommerce.domain.Order; import com.eCommerce.domain.Payment; import com.eCommerce.domain.ShippingAddress; import com.eCommerce.domain.ShoppingCart; import com.eCommerce.domain.User; public interface OrderService { Order createOrder(ShoppingCart shoppingCart, ShippingAddress shippingAddress, BillingAddress billingAddress, Payment payment, String shippingMethod, User user); Order findById(Long id); } ================================================ FILE: src/main/java/com/eCommerce/service/PaymentService.java ================================================ package com.eCommerce.service; import com.eCommerce.domain.Payment; import com.eCommerce.domain.UserPayment; public interface PaymentService { Payment setByUserPayment(UserPayment userPayment, Payment payment); } ================================================ FILE: src/main/java/com/eCommerce/service/ShippingAddressService.java ================================================ package com.eCommerce.service; import com.eCommerce.domain.ShippingAddress; import com.eCommerce.domain.UserShipping; public interface ShippingAddressService { ShippingAddress setByUserShipping(UserShipping userShipping, ShippingAddress shippingAddress); } ================================================ FILE: src/main/java/com/eCommerce/service/ShoppingCartService.java ================================================ package com.eCommerce.service; import com.eCommerce.domain.ShoppingCart; public interface ShoppingCartService { ShoppingCart updateShoppingCart(ShoppingCart shoppingCart); void clearShoppingCart(ShoppingCart shoppingCart); } ================================================ FILE: src/main/java/com/eCommerce/service/UserPaymentService.java ================================================ package com.eCommerce.service; import com.eCommerce.domain.UserPayment; public interface UserPaymentService { UserPayment findById(Long id); void deleteById(Long id); } ================================================ FILE: src/main/java/com/eCommerce/service/UserService.java ================================================ package com.eCommerce.service; import java.util.Set; import com.eCommerce.domain.User; import com.eCommerce.domain.UserBilling; import com.eCommerce.domain.UserPayment; import com.eCommerce.domain.UserShipping; import com.eCommerce.domain.security.PasswordResetToken; import com.eCommerce.domain.security.UserRole; public interface UserService { PasswordResetToken getPasswordResetToken(final String token); void createPasswordResetTokenForUser(final User user, final String token); User findByUsername(String username); User findByEmail (String email); User findById(Long id); User createUser(User user, Set userRoles) throws Exception; User save(User user); void updateUserBilling(UserBilling userBilling, UserPayment userPayment, User user); void updateUserShipping(UserShipping userShipping, User user); void setUserDefaultPayment(Long userPaymentId, User user); void setUserDefaultShipping(Long userShippingId, User user); } ================================================ FILE: src/main/java/com/eCommerce/service/UserShippingService.java ================================================ package com.eCommerce.service; import com.eCommerce.domain.UserShipping; public interface UserShippingService { UserShipping findById(Long id); void deleteById(Long id); } ================================================ FILE: src/main/java/com/eCommerce/service/impl/BillingAddressServiceImpl.java ================================================ package com.eCommerce.service.impl; import org.springframework.stereotype.Service; import com.eCommerce.domain.BillingAddress; import com.eCommerce.domain.UserBilling; import com.eCommerce.service.BillingAddressService; @Service public class BillingAddressServiceImpl implements BillingAddressService{ public BillingAddress setByUserBilling(UserBilling userBilling, BillingAddress billingAddress) { billingAddress.setBillingAddressName(userBilling.getUserBillingName()); billingAddress.setBillingAddressStreet1(userBilling.getUserBillingStreet1()); billingAddress.setBillingAddressStreet2(userBilling.getUserBillingStreet2()); billingAddress.setBillingAddressCity(userBilling.getUserBillingCity()); billingAddress.setBillingAddressState(userBilling.getUserBillingState()); billingAddress.setBillingAddressCountry(userBilling.getUserBillingCountry()); billingAddress.setBillingAddressZipcode(userBilling.getUserBillingZipcode()); return billingAddress; } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/BookServiceImpl.java ================================================ package com.eCommerce.service.impl; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.eCommerce.domain.Book; import com.eCommerce.repository.BookRepository; import com.eCommerce.service.BookService; @Service public class BookServiceImpl implements BookService{ @Autowired private BookRepository bookRepository; public List findAll() { List bookList = (List) bookRepository.findAll(); List activeBookList = new ArrayList<>(); for (Book book: bookList) { if(book.isActive()) { activeBookList.add(book); } } return activeBookList; } public Book findById(Long id) { return bookRepository.findById(id).orElse(null); } public List findByCategory(String category){ List bookList = bookRepository.findByCategory(category); List activeBookList = new ArrayList<>(); for (Book book: bookList) { if(book.isActive()) { activeBookList.add(book); } } return activeBookList; } public List blurrySearch(String title) { List bookList = bookRepository.findByTitleContaining(title); List activeBookList = new ArrayList<>(); for (Book book: bookList) { if(book.isActive()) { activeBookList.add(book); } } return activeBookList; } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/CartItemServiceImpl.java ================================================ package com.eCommerce.service.impl; import java.math.BigDecimal; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.eCommerce.domain.Book; import com.eCommerce.domain.BookToCartItem; import com.eCommerce.domain.CartItem; import com.eCommerce.domain.Order; import com.eCommerce.domain.ShoppingCart; import com.eCommerce.domain.User; import com.eCommerce.repository.BookToCartItemRepository; import com.eCommerce.repository.CartItemRepository; import com.eCommerce.service.CartItemService; @Service public class CartItemServiceImpl implements CartItemService{ @Autowired private CartItemRepository cartItemRepository; @Autowired private BookToCartItemRepository bookToCartItemRepository; public List findByShoppingCart(ShoppingCart shoppingCart) { return cartItemRepository.findByShoppingCart(shoppingCart); } public CartItem updateCartItem(CartItem cartItem) { BigDecimal bigDecimal = new BigDecimal(cartItem.getBook().getOurPrice()).multiply(new BigDecimal(cartItem.getQty())); bigDecimal = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP); cartItem.setSubtotal(bigDecimal); cartItemRepository.save(cartItem); return cartItem; } public CartItem addBookToCartItem(Book book, User user, int qty) { List cartItemList = findByShoppingCart(user.getShoppingCart()); for (CartItem cartItem : cartItemList) { if(book.getId() == cartItem.getBook().getId()) { cartItem.setQty(cartItem.getQty()+qty); cartItem.setSubtotal(new BigDecimal(book.getOurPrice()).multiply(new BigDecimal(qty))); cartItemRepository.save(cartItem); return cartItem; } } CartItem cartItem = new CartItem(); cartItem.setShoppingCart(user.getShoppingCart()); cartItem.setBook(book); cartItem.setQty(qty); cartItem.setSubtotal(new BigDecimal(book.getOurPrice()).multiply(new BigDecimal(qty))); cartItem = cartItemRepository.save(cartItem); BookToCartItem bookToCartItem = new BookToCartItem(); bookToCartItem.setBook(book); bookToCartItem.setCartItem(cartItem); bookToCartItemRepository.save(bookToCartItem); return cartItem; } public CartItem findById(Long id) { return cartItemRepository.findById(id).orElse(null); } public void removeCartItem(CartItem cartItem) { bookToCartItemRepository.deleteByCartItem(cartItem); cartItemRepository.delete(cartItem); } public CartItem save(CartItem cartItem) { return cartItemRepository.save(cartItem); } public List findByOrder(Order order) { return cartItemRepository.findByOrder(order); } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/OrderServiceImpl.java ================================================ package com.eCommerce.service.impl; import java.util.Calendar; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.eCommerce.domain.BillingAddress; import com.eCommerce.domain.Book; import com.eCommerce.domain.CartItem; import com.eCommerce.domain.Order; import com.eCommerce.domain.Payment; import com.eCommerce.domain.ShippingAddress; import com.eCommerce.domain.ShoppingCart; import com.eCommerce.domain.User; import com.eCommerce.repository.OrderRepository; import com.eCommerce.service.CartItemService; import com.eCommerce.service.OrderService; @Service public class OrderServiceImpl implements OrderService{ @Autowired private OrderRepository orderRepository; @Autowired private CartItemService cartItemService; public synchronized Order createOrder(ShoppingCart shoppingCart, ShippingAddress shippingAddress, BillingAddress billingAddress, Payment payment, String shippingMethod, User user) { Order order = new Order(); order.setBillingAddress(billingAddress); order.setOrderStatus("created"); order.setPayment(payment); order.setShippingAddress(shippingAddress); order.setShippingMethod(shippingMethod); List cartItemList = cartItemService.findByShoppingCart(shoppingCart); for(CartItem cartItem : cartItemList) { Book book = cartItem.getBook(); cartItem.setOrder(order); book.setInStockNumber(book.getInStockNumber() - cartItem.getQty()); } order.setCartItemList(cartItemList); order.setOrderDate(Calendar.getInstance().getTime()); order.setOrderTotal(shoppingCart.getGrandTotal()); shippingAddress.setOrder(order); billingAddress.setOrder(order); payment.setOrder(order); order.setUser(user); order = orderRepository.save(order); return order; } public Order findById(Long id) { return orderRepository.findById(id).orElse(null); } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/PaymentServiceImpl.java ================================================ package com.eCommerce.service.impl; import org.springframework.stereotype.Service; import com.eCommerce.domain.Payment; import com.eCommerce.domain.UserPayment; import com.eCommerce.service.PaymentService; @Service public class PaymentServiceImpl implements PaymentService{ public Payment setByUserPayment(UserPayment userPayment, Payment payment) { payment.setType(userPayment.getType()); payment.setHolderName(userPayment.getHolderName()); payment.setCardNumber(userPayment.getCardNumber()); payment.setExpiryMonth(userPayment.getExpiryMonth()); payment.setExpiryYear(userPayment.getExpiryYear()); payment.setCvc(userPayment.getCvc()); return payment; } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/ShippingAddressServiceImpl.java ================================================ package com.eCommerce.service.impl; import org.springframework.stereotype.Service; import com.eCommerce.domain.ShippingAddress; import com.eCommerce.domain.UserShipping; import com.eCommerce.service.ShippingAddressService; @Service public class ShippingAddressServiceImpl implements ShippingAddressService { public ShippingAddress setByUserShipping(UserShipping userShipping, ShippingAddress shippingAddress) { shippingAddress.setShippingAddressName(userShipping.getUserShippingName()); shippingAddress.setShippingAddressStreet1(userShipping.getUserShippingStreet1()); shippingAddress.setShippingAddressStreet2(userShipping.getUserShippingStreet2()); shippingAddress.setShippingAddressCity(userShipping.getUserShippingCity()); shippingAddress.setShippingAddressState(userShipping.getUserShippingState()); shippingAddress.setShippingAddressCountry(userShipping.getUserShippingCountry()); shippingAddress.setShippingAddressZipcode(userShipping.getUserShippingZipcode()); return shippingAddress; } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/ShoppingCartServiceImpl.java ================================================ package com.eCommerce.service.impl; import java.math.BigDecimal; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.eCommerce.domain.CartItem; import com.eCommerce.domain.ShoppingCart; import com.eCommerce.repository.ShoppingCartRepository; import com.eCommerce.service.CartItemService; import com.eCommerce.service.ShoppingCartService; @Service public class ShoppingCartServiceImpl implements ShoppingCartService{ @Autowired private CartItemService cartItemService; @Autowired private ShoppingCartRepository shoppingCartRepository; public ShoppingCart updateShoppingCart(ShoppingCart shoppingCart) { BigDecimal cartTotal = new BigDecimal(0); List cartItemList = cartItemService.findByShoppingCart(shoppingCart); for (CartItem cartItem : cartItemList) { if(cartItem.getBook().getInStockNumber() > 0) { cartItemService.updateCartItem(cartItem); cartTotal = cartTotal.add(cartItem.getSubtotal()); } } shoppingCart.setGrandTotal(cartTotal); shoppingCartRepository.save(shoppingCart); return shoppingCart; } public void clearShoppingCart(ShoppingCart shoppingCart) { List cartItemList = cartItemService.findByShoppingCart(shoppingCart); for (CartItem cartItem : cartItemList) { cartItem.setShoppingCart(null); cartItemService.save(cartItem); } shoppingCart.setGrandTotal(new BigDecimal(0)); shoppingCartRepository.save(shoppingCart); } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/UserPaymentServiceImpl.java ================================================ package com.eCommerce.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.eCommerce.domain.UserPayment; import com.eCommerce.repository.UserPaymentRepository; import com.eCommerce.service.UserPaymentService; @Service public class UserPaymentServiceImpl implements UserPaymentService{ @Autowired private UserPaymentRepository userPaymentRepository; public UserPayment findById(Long id) { return userPaymentRepository.findById(id).orElse(null); } public void deleteById(Long id) { userPaymentRepository.deleteById(id); } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/UserSecurityService.java ================================================ package com.eCommerce.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import com.eCommerce.domain.User; import com.eCommerce.repository.UserRepository; @Service public class UserSecurityService implements UserDetailsService{ @Autowired private UserRepository userRepository; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userRepository.findByUsername(username); if(null == user) { throw new UsernameNotFoundException("Username not found"); } return user; } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/UserServiceImpl.java ================================================ package com.eCommerce.service.impl; import java.util.ArrayList; import java.util.List; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.eCommerce.domain.ShoppingCart; import com.eCommerce.domain.User; import com.eCommerce.domain.UserBilling; import com.eCommerce.domain.UserPayment; import com.eCommerce.domain.UserShipping; import com.eCommerce.domain.security.PasswordResetToken; import com.eCommerce.domain.security.UserRole; import com.eCommerce.repository.PasswordResetTokenRepository; import com.eCommerce.repository.RoleRepository; import com.eCommerce.repository.UserPaymentRepository; import com.eCommerce.repository.UserRepository; import com.eCommerce.repository.UserShippingRepository; import com.eCommerce.service.UserService; @Service public class UserServiceImpl implements UserService{ private static final Logger LOG = LoggerFactory.getLogger(UserService.class); @Autowired private UserRepository userRepository; @Autowired private RoleRepository roleRepository; @Autowired private UserPaymentRepository userPaymentRepository; @Autowired private UserShippingRepository userShippingRepository; @Autowired private PasswordResetTokenRepository passwordResetTokenRepository; @Override public PasswordResetToken getPasswordResetToken(final String token) { return passwordResetTokenRepository.findByToken(token); } @Override public void createPasswordResetTokenForUser(final User user, final String token) { final PasswordResetToken myToken = new PasswordResetToken(token, user); passwordResetTokenRepository.save(myToken); } @Override public User findByUsername(String username) { return userRepository.findByUsername(username); } @Override public User findById(Long id){ return userRepository.findById(id).orElse(null); } @Override public User findByEmail (String email) { return userRepository.findByEmail(email); } @Override @Transactional public User createUser(User user, Set userRoles){ User localUser = userRepository.findByUsername(user.getUsername()); if(localUser != null) { LOG.info("user {} already exists. Nothing will be done.", user.getUsername()); } else { for (UserRole ur : userRoles) { roleRepository.save(ur.getRole()); } user.getUserRoles().addAll(userRoles); ShoppingCart shoppingCart = new ShoppingCart(); shoppingCart.setUser(user); user.setShoppingCart(shoppingCart); user.setUserShippingList(new ArrayList()); user.setUserPaymentList(new ArrayList()); localUser = userRepository.save(user); } return localUser; } @Override public User save(User user) { return userRepository.save(user); } @Override public void updateUserBilling(UserBilling userBilling, UserPayment userPayment, User user) { userPayment.setUser(user); userPayment.setUserBilling(userBilling); userPayment.setDefaultPayment(true); userBilling.setUserPayment(userPayment); user.getUserPaymentList().add(userPayment); save(user); } @Override public void updateUserShipping(UserShipping userShipping, User user){ userShipping.setUser(user); userShipping.setUserShippingDefault(true); user.getUserShippingList().add(userShipping); save(user); } @Override public void setUserDefaultPayment(Long userPaymentId, User user) { List userPaymentList = (List) userPaymentRepository.findAll(); for (UserPayment userPayment : userPaymentList) { if(userPayment.getId() == userPaymentId) { userPayment.setDefaultPayment(true); userPaymentRepository.save(userPayment); } else { userPayment.setDefaultPayment(false); userPaymentRepository.save(userPayment); } } } @Override public void setUserDefaultShipping(Long userShippingId, User user) { List userShippingList = (List) userShippingRepository.findAll(); for (UserShipping userShipping : userShippingList) { if(userShipping.getId() == userShippingId) { userShipping.setUserShippingDefault(true); userShippingRepository.save(userShipping); } else { userShipping.setUserShippingDefault(false); userShippingRepository.save(userShipping); } } } } ================================================ FILE: src/main/java/com/eCommerce/service/impl/UserShippingServiceImpl.java ================================================ package com.eCommerce.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.eCommerce.domain.UserShipping; import com.eCommerce.repository.UserShippingRepository; import com.eCommerce.service.UserShippingService; @Service public class UserShippingServiceImpl implements UserShippingService{ @Autowired private UserShippingRepository userShippingRepository; public UserShipping findById(Long id) { return userShippingRepository.findById(id).orElse(null); } public void deleteById(Long id) { userShippingRepository.deleteById(id); } } ================================================ FILE: src/main/java/com/eCommerce/utility/MailConstructor.java ================================================ package com.eCommerce.utility; import com.eCommerce.domain.Order; import com.eCommerce.domain.User; import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.MimeMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.mail.javamail.MimeMessagePreparator; import org.springframework.stereotype.Component; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.Context; import java.util.Locale; @Component public class MailConstructor { @Autowired private TemplateEngine templateEngine; @Autowired private Environment env; public SimpleMailMessage constructResetTokenEmail( String contextPath, Locale locale, String token, User user, String password ) { String url = contextPath + "/newUser?token="+token; String message = "\nPlease click on this link to verify your email and edit your personal information. Your password is: \n"+password; SimpleMailMessage email = new SimpleMailMessage(); email.setTo(user.getEmail()); email.setSubject("E-Commerce - New User"); email.setText(url+message); email.setFrom(env.getProperty("support.email")); return email; } public MimeMessagePreparator constructOrderConfirmationEmail (User user, Order order, Locale locale) { Context context = new Context(); context.setVariable("order", order); context.setVariable("user", user); context.setVariable("cartItemList", order.getCartItemList()); String text = templateEngine.process("orderConfirmationEmailTemplate", context); MimeMessagePreparator messagePreparator = new MimeMessagePreparator() { @Override public void prepare(MimeMessage mimeMessage) throws Exception { MimeMessageHelper email = new MimeMessageHelper(mimeMessage); email.setTo(user.getEmail()); email.setSubject("Order Confirmation - "+order.getId()); email.setText(text, true); email.setFrom(new InternetAddress("foysal.ecommerce@gmail.com")); } }; return messagePreparator; } } ================================================ FILE: src/main/java/com/eCommerce/utility/SecurityUtility.java ================================================ package com.eCommerce.utility; import java.security.SecureRandom; import java.util.Random; import org.springframework.context.annotation.Bean; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Component; @Component public class SecurityUtility { private static final String SALT = "salt"; // Salt should be protected carefully @Bean public static BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(12, new SecureRandom(SALT.getBytes())); } @Bean public static String randomPassword() { String SALTCHARS = "ABCEFGHIJKLMNOPQRSTUVWXYZ1234567890"; StringBuilder salt = new StringBuilder(); Random rnd = new Random(); while (salt.length()<18) { int index= (int) (rnd.nextFloat()*SALTCHARS.length()); salt.append(SALTCHARS.charAt(index)); } String saltStr = salt.toString(); return saltStr; } } ================================================ FILE: src/main/java/com/eCommerce/utility/USConstants.java ================================================ package com.eCommerce.utility; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class USConstants { public final static String US = "US"; public final static Map mapOfUSStates = new HashMap() { { put("Barisal", "Barisal"); put("Dhaka", "Dhaka"); put("Chittagong", "Chittagong"); put("Khulna", "Khulna"); put("Mymensingh", "Mymensingh"); put("Rajshahi", "Rajshahi"); put("Sylhet", "Sylhet"); put("Rangpur", "Rangpur"); } }; public final static List listOfUSStatesCode = new ArrayList<>(mapOfUSStates.keySet()); public final static List listOfUSStatesName = new ArrayList<>(mapOfUSStates.values()); } ================================================ FILE: src/main/resources/application.properties ================================================ spring.thymeleaf.cache=false # =============================== # = DATA SOURCE # =============================== # Set here configurations for the database connection spring.datasource.url=jdbc:mysql://localhost:3306/ecommerceDB?createDatabaseIfNotExist=true&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Jakarta&useSSL=false&allowPublicKeyRetrieval=true # Username and secret spring.datasource.username=root spring.datasource.password=foysal28 # Keep the connection alive if idle for a long time (needed in production) spring.datasource.testWhileIdle = true spring.datasource.validationQuery = SELECT 1 # =============================== # = JPA / HIBERNATE # =============================== # Use spring.jpa.properties.* for Hibernate native properties (the prefix is # stripped before adding them to the entity manager). # Show or not log for each sql query spring.jpa.show-sql=true # Hibernate ddl auto (create, create-drop, update): with "update" the database # schema will be automatically updated accordingly to java entities found in # the project spring.jpa.hibernate.ddl-auto = update # Allows Hibernate to generate SQL optimized for a particular DBMS spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect spring.mail.host=smtp.gmail.com spring.mail.username={Email Address} spring.mail.password={Email Password} spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.socketFactory.port=465 spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory spring.mail.properties.mail.smtp.socketFactory.fallback=false support.email={Email Address} ================================================ FILE: src/main/resources/messages.properties ================================================ adminPath=http://localhost:8081/adminportal ================================================ FILE: src/main/resources/static/css/jquery.dataTables_themeroller.css ================================================ /* * Table styles */ table.dataTable { width: 100%; margin: 0 auto; clear: both; border-collapse: separate; border-spacing: 0; /* * Header and footer styles */ /* * Body styles */ } table.dataTable thead th, table.dataTable thead td, table.dataTable tfoot th, table.dataTable tfoot td { padding: 4px 10px; } table.dataTable thead th, table.dataTable tfoot th { font-weight: bold; } table.dataTable thead th:active, table.dataTable thead td:active { outline: none; } table.dataTable thead .sorting_asc, table.dataTable thead .sorting_desc, table.dataTable thead .sorting { cursor: pointer; *cursor: hand; } table.dataTable thead th div.DataTables_sort_wrapper { position: relative; padding-right: 10px; } table.dataTable thead th div.DataTables_sort_wrapper span { position: absolute; top: 50%; margin-top: -8px; right: -5px; } table.dataTable thead th.ui-state-default { border-right-width: 0; } table.dataTable thead th.ui-state-default:last-child { border-right-width: 1px; } table.dataTable tbody tr { background-color: #ffffff; } table.dataTable tbody tr.selected { background-color: #B0BED9; } table.dataTable tbody th, table.dataTable tbody td { padding: 8px 10px; } table.dataTable th.center, table.dataTable td.center, table.dataTable td.dataTables_empty { text-align: center; } table.dataTable th.right, table.dataTable td.right { text-align: right; } table.dataTable.row-border tbody th, table.dataTable.row-border tbody td, table.dataTable.display tbody th, table.dataTable.display tbody td { border-top: 1px solid #ddd; } table.dataTable.row-border tbody tr:first-child th, table.dataTable.row-border tbody tr:first-child td, table.dataTable.display tbody tr:first-child th, table.dataTable.display tbody tr:first-child td { border-top: none; } table.dataTable.cell-border tbody th, table.dataTable.cell-border tbody td { border-top: 1px solid #ddd; border-right: 1px solid #ddd; } table.dataTable.cell-border tbody tr th:first-child, table.dataTable.cell-border tbody tr td:first-child { border-left: 1px solid #ddd; } table.dataTable.cell-border tbody tr:first-child th, table.dataTable.cell-border tbody tr:first-child td { border-top: none; } table.dataTable.stripe tbody tr.odd, table.dataTable.display tbody tr.odd { background-color: #f9f9f9; } table.dataTable.stripe tbody tr.odd.selected, table.dataTable.display tbody tr.odd.selected { background-color: #abb9d3; } table.dataTable.hover tbody tr:hover, table.dataTable.hover tbody tr.odd:hover, table.dataTable.hover tbody tr.even:hover, table.dataTable.display tbody tr:hover, table.dataTable.display tbody tr.odd:hover, table.dataTable.display tbody tr.even:hover { background-color: whitesmoke; } table.dataTable.hover tbody tr:hover.selected, table.dataTable.hover tbody tr.odd:hover.selected, table.dataTable.hover tbody tr.even:hover.selected, table.dataTable.display tbody tr:hover.selected, table.dataTable.display tbody tr.odd:hover.selected, table.dataTable.display tbody tr.even:hover.selected { background-color: #a9b7d1; } table.dataTable.order-column tbody tr > .sorting_1, table.dataTable.order-column tbody tr > .sorting_2, table.dataTable.order-column tbody tr > .sorting_3, table.dataTable.display tbody tr > .sorting_1, table.dataTable.display tbody tr > .sorting_2, table.dataTable.display tbody tr > .sorting_3 { background-color: #f9f9f9; } table.dataTable.order-column tbody tr.selected > .sorting_1, table.dataTable.order-column tbody tr.selected > .sorting_2, table.dataTable.order-column tbody tr.selected > .sorting_3, table.dataTable.display tbody tr.selected > .sorting_1, table.dataTable.display tbody tr.selected > .sorting_2, table.dataTable.display tbody tr.selected > .sorting_3 { background-color: #acbad4; } table.dataTable.display tbody tr.odd > .sorting_1, table.dataTable.order-column.stripe tbody tr.odd > .sorting_1 { background-color: #f1f1f1; } table.dataTable.display tbody tr.odd > .sorting_2, table.dataTable.order-column.stripe tbody tr.odd > .sorting_2 { background-color: #f3f3f3; } table.dataTable.display tbody tr.odd > .sorting_3, table.dataTable.order-column.stripe tbody tr.odd > .sorting_3 { background-color: whitesmoke; } table.dataTable.display tbody tr.odd.selected > .sorting_1, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_1 { background-color: #a6b3cd; } table.dataTable.display tbody tr.odd.selected > .sorting_2, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_2 { background-color: #a7b5ce; } table.dataTable.display tbody tr.odd.selected > .sorting_3, table.dataTable.order-column.stripe tbody tr.odd.selected > .sorting_3 { background-color: #a9b6d0; } table.dataTable.display tbody tr.even > .sorting_1, table.dataTable.order-column.stripe tbody tr.even > .sorting_1 { background-color: #f9f9f9; } table.dataTable.display tbody tr.even > .sorting_2, table.dataTable.order-column.stripe tbody tr.even > .sorting_2 { background-color: #fbfbfb; } table.dataTable.display tbody tr.even > .sorting_3, table.dataTable.order-column.stripe tbody tr.even > .sorting_3 { background-color: #fdfdfd; } table.dataTable.display tbody tr.even.selected > .sorting_1, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_1 { background-color: #acbad4; } table.dataTable.display tbody tr.even.selected > .sorting_2, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_2 { background-color: #adbbd6; } table.dataTable.display tbody tr.even.selected > .sorting_3, table.dataTable.order-column.stripe tbody tr.even.selected > .sorting_3 { background-color: #afbdd8; } table.dataTable.display tbody tr:hover > .sorting_1, table.dataTable.display tbody tr.odd:hover > .sorting_1, table.dataTable.display tbody tr.even:hover > .sorting_1, table.dataTable.order-column.hover tbody tr:hover > .sorting_1, table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_1, table.dataTable.order-column.hover tbody tr.even:hover > .sorting_1 { background-color: #eaeaea; } table.dataTable.display tbody tr:hover > .sorting_2, table.dataTable.display tbody tr.odd:hover > .sorting_2, table.dataTable.display tbody tr.even:hover > .sorting_2, table.dataTable.order-column.hover tbody tr:hover > .sorting_2, table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_2, table.dataTable.order-column.hover tbody tr.even:hover > .sorting_2 { background-color: #ebebeb; } table.dataTable.display tbody tr:hover > .sorting_3, table.dataTable.display tbody tr.odd:hover > .sorting_3, table.dataTable.display tbody tr.even:hover > .sorting_3, table.dataTable.order-column.hover tbody tr:hover > .sorting_3, table.dataTable.order-column.hover tbody tr.odd:hover > .sorting_3, table.dataTable.order-column.hover tbody tr.even:hover > .sorting_3 { background-color: #eeeeee; } table.dataTable.display tbody tr:hover.selected > .sorting_1, table.dataTable.display tbody tr.odd:hover.selected > .sorting_1, table.dataTable.display tbody tr.even:hover.selected > .sorting_1, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_1, table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_1, table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_1 { background-color: #a1aec7; } table.dataTable.display tbody tr:hover.selected > .sorting_2, table.dataTable.display tbody tr.odd:hover.selected > .sorting_2, table.dataTable.display tbody tr.even:hover.selected > .sorting_2, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_2, table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_2, table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_2 { background-color: #a2afc8; } table.dataTable.display tbody tr:hover.selected > .sorting_3, table.dataTable.display tbody tr.odd:hover.selected > .sorting_3, table.dataTable.display tbody tr.even:hover.selected > .sorting_3, table.dataTable.order-column.hover tbody tr:hover.selected > .sorting_3, table.dataTable.order-column.hover tbody tr.odd:hover.selected > .sorting_3, table.dataTable.order-column.hover tbody tr.even:hover.selected > .sorting_3 { background-color: #a4b2cb; } table.dataTable.nowrap th, table.dataTable.nowrap td { white-space: nowrap; } table.dataTable.compact thead th, table.dataTable.compact thead td { padding: 5px 9px; } table.dataTable.compact tfoot th, table.dataTable.compact tfoot td { padding: 5px 9px 3px 9px; } table.dataTable.compact tbody th, table.dataTable.compact tbody td { padding: 4px 5px; } table.dataTable th.dt-left, table.dataTable td.dt-left { text-align: left; } table.dataTable th.dt-center, table.dataTable td.dt-center, table.dataTable td.dataTables_empty { text-align: center; } table.dataTable th.dt-right, table.dataTable td.dt-right { text-align: right; } table.dataTable th.dt-justify, table.dataTable td.dt-justify { text-align: justify; } table.dataTable th.dt-nowrap, table.dataTable td.dt-nowrap { white-space: nowrap; } table.dataTable thead th.dt-head-left, table.dataTable thead td.dt-head-left, table.dataTable tfoot th.dt-head-left, table.dataTable tfoot td.dt-head-left { text-align: left; } table.dataTable thead th.dt-head-center, table.dataTable thead td.dt-head-center, table.dataTable tfoot th.dt-head-center, table.dataTable tfoot td.dt-head-center { text-align: center; } table.dataTable thead th.dt-head-right, table.dataTable thead td.dt-head-right, table.dataTable tfoot th.dt-head-right, table.dataTable tfoot td.dt-head-right { text-align: right; } table.dataTable thead th.dt-head-justify, table.dataTable thead td.dt-head-justify, table.dataTable tfoot th.dt-head-justify, table.dataTable tfoot td.dt-head-justify { text-align: justify; } table.dataTable thead th.dt-head-nowrap, table.dataTable thead td.dt-head-nowrap, table.dataTable tfoot th.dt-head-nowrap, table.dataTable tfoot td.dt-head-nowrap { white-space: nowrap; } table.dataTable tbody th.dt-body-left, table.dataTable tbody td.dt-body-left { text-align: left; } table.dataTable tbody th.dt-body-center, table.dataTable tbody td.dt-body-center { text-align: center; } table.dataTable tbody th.dt-body-right, table.dataTable tbody td.dt-body-right { text-align: right; } table.dataTable tbody th.dt-body-justify, table.dataTable tbody td.dt-body-justify { text-align: justify; } table.dataTable tbody th.dt-body-nowrap, table.dataTable tbody td.dt-body-nowrap { white-space: nowrap; } table.dataTable, table.dataTable th, table.dataTable td { -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; } /* * Control feature layout */ .dataTables_wrapper { position: relative; clear: both; *zoom: 1; zoom: 1; } .dataTables_wrapper .dataTables_length { float: left; } .dataTables_wrapper .dataTables_filter { float: right; text-align: right; } .dataTables_wrapper .dataTables_filter input { margin-left: 0.5em; } .dataTables_wrapper .dataTables_info { clear: both; float: left; padding-top: 0.55em; } .dataTables_wrapper .dataTables_paginate { float: right; text-align: right; } .dataTables_wrapper .dataTables_paginate .fg-button { box-sizing: border-box; display: inline-block; min-width: 1.5em; padding: 0.5em; margin-left: 2px; text-align: center; text-decoration: none !important; cursor: pointer; *cursor: hand; color: #333 !important; border: 1px solid transparent; } .dataTables_wrapper .dataTables_paginate .fg-button:active { outline: none; } .dataTables_wrapper .dataTables_paginate .fg-button:first-child { border-top-left-radius: 3px; border-bottom-left-radius: 3px; } .dataTables_wrapper .dataTables_paginate .fg-button:last-child { border-top-right-radius: 3px; border-bottom-right-radius: 3px; } .dataTables_wrapper .dataTables_processing { position: absolute; top: 50%; left: 50%; width: 100%; height: 40px; margin-left: -50%; margin-top: -25px; padding-top: 20px; text-align: center; font-size: 1.2em; background-color: white; background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 0)), color-stop(25%, rgba(255, 255, 255, 0.9)), color-stop(75%, rgba(255, 255, 255, 0.9)), color-stop(100%, rgba(255, 255, 255, 0))); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); /* Chrome10+,Safari5.1+ */ background: -moz-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); /* FF3.6+ */ background: -ms-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); /* IE10+ */ background: -o-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); /* Opera 11.10+ */ background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%); /* W3C */ } .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing, .dataTables_wrapper .dataTables_paginate { color: #333; } .dataTables_wrapper .dataTables_scroll { clear: both; } .dataTables_wrapper .dataTables_scrollBody { *margin-top: -1px; -webkit-overflow-scrolling: touch; } .dataTables_wrapper .ui-widget-header { font-weight: normal; } .dataTables_wrapper .ui-toolbar { padding: 8px; } .dataTables_wrapper:after { visibility: hidden; display: block; content: ""; clear: both; height: 0; } @media screen and (max-width: 767px) { .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { float: none; text-align: center; } .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_paginate { margin-top: 0.5em; } } ================================================ FILE: src/main/resources/static/css/non-responsive.css ================================================ /* Template-specific stuff * * Customizations just for the template; these are not necessary for anything * with disabling the responsiveness. */ /* Account for fixed navbar */ body { padding-top: 70px; padding-bottom: 30px; } body, .navbar-fixed-top, .navbar-fixed-bottom { min-width: 970px; } /* Don't let the lead text change font-size. */ .lead { font-size: 16px; } /* Finesse the page header spacing */ .page-header { margin-bottom: 30px; } .page-header .lead { margin-bottom: 10px; } /* Non-responsive overrides * * Utilize the following CSS to disable the responsive-ness of the container, * grid system, and navbar. */ /* Reset the container */ .container { width: 970px; max-width: none !important; } /* Demonstrate the grids */ .col-xs-4 { padding-top: 15px; padding-bottom: 15px; /*background-color: #eee;*/ /*background-color: rgba(86,61,124,.15);*/ /*border: 1px solid #ddd;*/ /*border: 1px solid rgba(86,61,124,.2);*/ } .container .navbar-header, .container .navbar-collapse { margin-right: 0; margin-left: 0; } /* Always float the navbar header */ .navbar-header { float: left; } /* Undo the collapsing navbar */ .navbar-collapse { display: block !important; height: auto !important; padding-bottom: 0; overflow: visible !important; visibility: visible !important; } .navbar-toggle { display: none; } .navbar-collapse { border-top: 0; } .navbar-brand { margin-left: -15px; } /* Always apply the floated nav */ .navbar-nav { float: left; margin: 0; } .navbar-nav > li { float: left; } .navbar-nav > li > a { padding: 15px; } /* Redeclare since we override the float above */ .navbar-nav.navbar-right { float: right; } /* Undo custom dropdowns */ .navbar .navbar-nav .open .dropdown-menu { position: absolute; float: left; background-color: #fff; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, .15); border-width: 0 1px 1px; border-radius: 0 0 4px 4px; -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175); box-shadow: 0 6px 12px rgba(0, 0, 0, .175); } .navbar-default .navbar-nav .open .dropdown-menu > li > a { color: #333; } .navbar .navbar-nav .open .dropdown-menu > li > a:hover, .navbar .navbar-nav .open .dropdown-menu > li > a:focus, .navbar .navbar-nav .open .dropdown-menu > .active > a, .navbar .navbar-nav .open .dropdown-menu > .active > a:hover, .navbar .navbar-nav .open .dropdown-menu > .active > a:focus { color: #fff !important; background-color: #428bca !important; } .navbar .navbar-nav .open .dropdown-menu > .disabled > a, .navbar .navbar-nav .open .dropdown-menu > .disabled > a:hover, .navbar .navbar-nav .open .dropdown-menu > .disabled > a:focus { color: #999 !important; background-color: transparent !important; } /* Undo form expansion */ .navbar-form { float: left; width: auto; padding-top: 0; padding-bottom: 0; margin-right: 0; margin-left: 0; border: 0; -webkit-box-shadow: none; box-shadow: none; } /* Copy-pasted from forms.less since we mixin the .form-inline styles. */ .navbar-form .form-group { display: inline-block; margin-bottom: 0; vertical-align: middle; } .navbar-form .form-control { display: inline-block; width: auto; vertical-align: middle; } .navbar-form .form-control-static { display: inline-block; } .navbar-form .input-group { display: inline-table; vertical-align: middle; } .navbar-form .input-group .input-group-addon, .navbar-form .input-group .input-group-btn, .navbar-form .input-group .form-control { width: auto; } .navbar-form .input-group > .form-control { width: 100%; } .navbar-form .control-label { margin-bottom: 0; vertical-align: middle; } .navbar-form .radio, .navbar-form .checkbox { display: inline-block; margin-top: 0; margin-bottom: 0; vertical-align: middle; } .navbar-form .radio label, .navbar-form .checkbox label { padding-left: 0; } .navbar-form .radio input[type="radio"], .navbar-form .checkbox input[type="checkbox"] { position: relative; margin-left: 0; } .navbar-form .has-feedback .form-control-feedback { top: 0; } /* Undo inline form compaction on small screens */ .form-inline .form-group { display: inline-block; margin-bottom: 0; vertical-align: middle; } .form-inline .form-control { display: inline-block; width: auto; vertical-align: middle; } .form-inline .form-control-static { display: inline-block; } .form-inline .input-group { display: inline-table; vertical-align: middle; } .form-inline .input-group .input-group-addon, .form-inline .input-group .input-group-btn, .form-inline .input-group .form-control { width: auto; } .form-inline .input-group > .form-control { width: 100%; } .form-inline .control-label { margin-bottom: 0; vertical-align: middle; } .form-inline .radio, .form-inline .checkbox { display: inline-block; margin-top: 0; margin-bottom: 0; vertical-align: middle; } .form-inline .radio label, .form-inline .checkbox label { padding-left: 0; } .form-inline .radio input[type="radio"], .form-inline .checkbox input[type="checkbox"] { position: relative; margin-left: 0; } .form-inline .has-feedback .form-control-feedback { top: 0; } ================================================ FILE: src/main/resources/static/css/style.css ================================================ hr { border: none; height: 1px; color: #333; background-color: #333; } .container { width: 90%; } .page-top { margin-top: -70px; } .navbar { margin-bottom: 20px; } .box { border: 1px solid red; } .home-headline{ font-family: 'Times New Roman', Times, serif; font-size:24px; color: #fff; margin: auto; text-align: center; margin-top: -13px; } .home-headline span { background-color: #231F20; padding: 5px 22px; } .section-headline { font-family: 'Times New Roman', Times, serif; font-size:24px; color: #fff; margin: auto; text-align: center; margin-top: 70px; } .section-headline span { background-color: #231F20; padding: 5px 22px; } ================================================ FILE: src/main/resources/static/js/scripts.js ================================================ /** * */ function checkBillingAddress() { if($("#theSameAsShippingAddress").is(":checked")) { $(".billingAddress").prop("disabled", true); } else { $(".billingAddress").prop("disabled", false); } } function checkPasswordMatch() { var password = $("#txtNewPassword").val(); var confirmPassword = $("#txtConfirmPassword").val(); if(password == "" && confirmPassword =="") { $("#checkPasswordMatch").html(""); $("#updateUserInfoButton").prop('disabled', false); } else { if(password != confirmPassword) { $("#checkPasswordMatch").html("Passwords do not match!"); $("#updateUserInfoButton").prop('disabled', true); } else { $("#checkPasswordMatch").html("Passwords match"); $("#updateUserInfoButton").prop('disabled', false); } } } $(document).ready(function(){ $(".cartItemQty").on('change', function(){ var id=this.id; $('#update-item-'+id).css('display', 'inline-block'); }); $("#theSameAsShippingAddress").on('click', checkBillingAddress); $("#txtConfirmPassword").keyup(checkPasswordMatch); $("#txtNewPassword").keyup(checkPasswordMatch); }); ================================================ FILE: src/main/resources/templates/badRequestPage.html ================================================

User Account


Bad request. The request path is invalid. Click here to return to the home page.
================================================ FILE: src/main/resources/templates/bookDetail.html ================================================


Added to cart.

Oops, only In Stock.

Book Title

Author:

Publisher:

Publication Date:

Language:

Category:

: pages

ISBN:

Shipping Weight: ounces

Our Price: $

List Price: $

You save: $

Qty:

In Stock

Only In Stock

Unavailable


Description:



================================================ FILE: src/main/resources/templates/bookshelf.html ================================================


Oops, no result is found. Try something else or try again later.

pages
$ $


================================================ FILE: src/main/resources/templates/checkout.html ================================================

User Account


By placing your order, you agree to Le's Bookstore privacy notice and conditions of use.


Order Summary

Total before tax:
$
Estimated tax:
$

Order Total:

$

There are some fields missing. Field with * is required.
Available Shipping Address Operations
use this address
Next
Available Credit Card Operations
use this payment

Next

Choose your shipping method:

Products

Price

Qty


In Stock

Only In Stock

Product Unavailable

delete
$

Order Total ( items): $



By placing your order, you agree to Le's Bookstore privacy notice and conditions of use.

================================================ FILE: src/main/resources/templates/common/header.html ================================================ E-Books


================================================ FILE: src/main/resources/templates/faq.html ================================================

User Account


Shopping


Q: How do I place an order?

A: First you need to set up an account, once that is created you are ready to place an order.

Q: How do I set up an account? 

A: Click on the login button in the upper right hand corner of the main page and then click on create an account.

Q: How long does it take to process and ship orders?

A: Please allow 1 - 3 business days (Monday-Friday) for order processing regardless of the shipping method chosen. Once shipped you should receive your order within 2 - 10 business days. Please note that 2 day and Overnight services refer to business days (Monday - Friday).

Q: Are all of the items guaranteed in stock?

A: We try to update the website as often as possible to reflect out of stock conditions. However, the ability to order an item does not guarantee that it will be in stock when your order is processed. You will be notified if an order is not available.

Q: Why can't I choose the size and color I want?

A: If you are unable to select a specific size or color, it typically means that the item is out of stock. Try checking back in 2 - 3 weeks to see if your size or color is available.

Q: I can't find a specific item on the website, are there items available that are not listed on the website?

A: The items that are currently shown on our website represent what is currently available to view and order online. There is a wider selection of merchandise available at the UVM Bookstore and the Catamount Store. Please visit our stores when you are in the Burlington area.

Q: How can I check the status of my order?

A: If you have registered for an account at the UVM Bookstore, click on "My Account" and login with your email address and password. You can view the status of any orders that were made while you were signed in. You can also contact us at 1.800.331.7305 with your name, order number, and a request for status of your order. Our office hours are Monday - Friday 8am -4:30pm EST

Q: How can I cancel or change my order?

A: You can cancel your order or make a change to it by contacting us at 1.999.999.9999 as soon as possible after your order is placed with your name, order number, and a request for cancellation or a description of the requested change. Our office hours are Monday Friday 8am 4:30pm. We will do our best to cancel or modify your order, but we will not be able to complete the cancellation if your order has been processed or shipped.

Shipping 


The UVM Bookstore is proud to offer you competitive shipping rates. All of our shipments are professionally packed to ensure the safety of your items in route.

Q: How much is the shipping charge on orders?

A: The shipping charge depends on the total amount of the merchandise ordered as well as the shipping method chosen. There are some items that incur additional charges such as diploma frames $19.99 for an oversized box and maple syrup $1.00 for double-boxing. The rate for chairs and rockers is $35.00 for shipments east of the Mississippi and $45.00 west of the Mississippi.

Q. What is your shipping method?

A: We ship UPS, FedEx or US mail .

Q: When will I receive my order?

A: On average, your order will be received in 7 - 10 working days. During August and January, delivery time may take longer. 

================================================ FILE: src/main/resources/templates/index.html ================================================


Best Seller Books

================================================ FILE: src/main/resources/templates/myAccount.html ================================================

User Account


An email has been sent to the email address you just registered. Please validate your email address and update your password information.
 Username already exists. Choose a different one.

Enter your username here.

Email already exists. Choose a different one.

A valid email address. All emails from the system will be sent to this address. The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain notification.

Incorrect username or password.

Enter your username here.

Enter the password that accompanies your username

Email doesn't exist.
Email sent.

Enter your registered email address here.

================================================ FILE: src/main/resources/templates/myProfile.html ================================================


Incorrect Password! Please enter the correct password for the current user.
Update Successfully!!!
User info updated.

Enter your current password to change the email address or password.

A valid email address. All emails from the system withll be sent to this address. The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain notification.

 

To change the current user password, enter the new password in both fields.

Order Date Order Number Total Status

Order Detail for Purchase #


Billing Details





Payment Information
Card Name
Card Number
Exp Date:/
Shipping Details





Order Summary

Item Name Item Price Item Quantity Total
SubTotal
Tax
Total
Default Credit Card Operations
Edit    Delete
User info updated.
* Give a name for your card:

Billing Address


Credit Card Information



Default Shipping Address Operations
default Edit      Delete
User info updated.

Shipping Address


================================================ FILE: src/main/resources/templates/orderConfirmationEmailTemplate.html ================================================

Dear ,


Thank you for shopping from our site. We hope you had a good time with our service!

Your order number is: #. Here is your order detail:

Order Detail for purchase #


Billing Detail Payment Information Shipping Address















Order Summary

Item Name Item Price Item Quantity Total
Subtotal
Tax
Total

Best,

Foysal Mahmud.

Department of CSE, University of Barisal.

================================================ FILE: src/main/resources/templates/orderSubmittedPage.html ================================================

User Account


Thank you, your order has been placed.

The estimated delivery date is

List of Items


$
================================================ FILE: src/main/resources/templates/shoppingCart.html ================================================



Oops, some of the products don't have enough stock. Please update product quantity.
Oops, your cart is empty. See if you can find what you like in the bookshelf and add them to cart.


Products

Price

Qty


In Stock

Only In Stock

Product Unavailable

Delete
$

Total Price ( items): $

================================================ FILE: src/test/java/com/eCommerce/ECommerceApplicationTests.java ================================================ package com.eCommerce; import com.eCommerce.repository.BookRepository; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.testcontainers.junit.jupiter.Testcontainers; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @Testcontainers @SpringBootTest( properties = { "management.endpoint.health.show-details=always", "spring.datasource.url=jdbc:tc:mysql:8.4.0:///bookShopDB" }, webEnvironment = RANDOM_PORT ) public class ECommerceApplicationTests { @Autowired private BookRepository bookRepository; @BeforeEach void deleteAll() { bookRepository.deleteAll(); } }