├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── ecom │ │ ├── ShoppingCartApplication.java │ │ ├── config │ │ ├── AuthFailureHandlerImpl.java │ │ ├── AuthSucessHandlerImpl.java │ │ ├── CustomUser.java │ │ ├── SecurityConfig.java │ │ └── UserDetailsServiceImpl.java │ │ ├── controller │ │ ├── AdminController.java │ │ ├── HomeController.java │ │ └── UserController.java │ │ ├── model │ │ ├── Cart.java │ │ ├── Category.java │ │ ├── OrderAddress.java │ │ ├── OrderRequest.java │ │ ├── Product.java │ │ ├── ProductOrder.java │ │ └── UserDtls.java │ │ ├── repository │ │ ├── CartRepository.java │ │ ├── CategoryRepository.java │ │ ├── ProductOrderRepository.java │ │ ├── ProductRepository.java │ │ └── UserRepository.java │ │ ├── service │ │ ├── CartService.java │ │ ├── CategoryService.java │ │ ├── CommnServiceImpl.java │ │ ├── CommonService.java │ │ ├── OrderService.java │ │ ├── ProductService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── CartServiceImpl.java │ │ │ ├── CategoryServiceImpl.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── ProductServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── util │ │ ├── AppConstant.java │ │ ├── CommonUtil.java │ │ └── OrderStatus.java └── resources │ ├── application.properties │ ├── static │ ├── css │ │ └── style.css │ ├── img │ │ ├── category_img │ │ │ ├── appli.png │ │ │ ├── beuty.png │ │ │ ├── blue shirt.jfif │ │ │ ├── book.jpg │ │ │ ├── canvas.jfif │ │ │ ├── groccery.jpg │ │ │ ├── laptop.jpg │ │ │ ├── mobile.png │ │ │ ├── monitor.jpg │ │ │ └── pant.png │ │ ├── ecom.png │ │ ├── ecom1.png │ │ ├── ecom2.jpg │ │ ├── ecom3.jpg │ │ ├── product_img │ │ │ ├── blue shirt.jfif │ │ │ ├── canvas.jfif │ │ │ ├── cross.jfif │ │ │ ├── fridge.png │ │ │ ├── grinder.jpg │ │ │ ├── hp laptop.jpg │ │ │ ├── iphone 14.jpg │ │ │ ├── jeans blue.jfif │ │ │ ├── kruti.jfif │ │ │ ├── laptop.jpg │ │ │ ├── lehenga.jfif │ │ │ ├── lofer.jfif │ │ │ ├── mobile.jpg │ │ │ ├── monitor.jpg │ │ │ ├── official shoe.jfif │ │ │ ├── oneplus mobile.jpg │ │ │ ├── printed short.jfif │ │ │ ├── washing_machine.png │ │ │ └── white shoe.jfif │ │ └── profile_img │ │ │ ├── ecom.png │ │ │ └── img.txt │ └── js │ │ └── script.js │ └── templates │ ├── admin │ ├── add_admin.html │ ├── add_product.html │ ├── category.html │ ├── edit_category.html │ ├── edit_product.html │ ├── index.html │ ├── orders.html │ ├── products.html │ ├── profile.html │ └── users.html │ ├── base.html │ ├── forgot_password.html │ ├── index.html │ ├── login.html │ ├── message.html │ ├── product.html │ ├── register.html │ ├── reset_password.html │ ├── user │ ├── cart.html │ ├── home.html │ ├── my_orders.html │ ├── order.html │ ├── profile.html │ └── success.html │ └── view_product.html └── test └── java └── com └── ecom └── ShoppingCartApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 3 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.2.0 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | # e.g. to debug Maven itself, use 32 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | # ---------------------------------------------------------------------------- 35 | 36 | if [ -z "$MAVEN_SKIP_RC" ] ; then 37 | 38 | if [ -f /usr/local/etc/mavenrc ] ; then 39 | . /usr/local/etc/mavenrc 40 | fi 41 | 42 | if [ -f /etc/mavenrc ] ; then 43 | . /etc/mavenrc 44 | fi 45 | 46 | if [ -f "$HOME/.mavenrc" ] ; then 47 | . "$HOME/.mavenrc" 48 | fi 49 | 50 | fi 51 | 52 | # OS specific support. $var _must_ be set to either true or false. 53 | cygwin=false; 54 | darwin=false; 55 | mingw=false 56 | case "$(uname)" in 57 | CYGWIN*) cygwin=true ;; 58 | MINGW*) mingw=true;; 59 | Darwin*) darwin=true 60 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 61 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 62 | if [ -z "$JAVA_HOME" ]; then 63 | if [ -x "/usr/libexec/java_home" ]; then 64 | JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME 65 | else 66 | JAVA_HOME="/Library/Java/Home"; export JAVA_HOME 67 | fi 68 | fi 69 | ;; 70 | esac 71 | 72 | if [ -z "$JAVA_HOME" ] ; then 73 | if [ -r /etc/gentoo-release ] ; then 74 | JAVA_HOME=$(java-config --jre-home) 75 | fi 76 | fi 77 | 78 | # For Cygwin, ensure paths are in UNIX format before anything is touched 79 | if $cygwin ; then 80 | [ -n "$JAVA_HOME" ] && 81 | JAVA_HOME=$(cygpath --unix "$JAVA_HOME") 82 | [ -n "$CLASSPATH" ] && 83 | CLASSPATH=$(cygpath --path --unix "$CLASSPATH") 84 | fi 85 | 86 | # For Mingw, ensure paths are in UNIX format before anything is touched 87 | if $mingw ; then 88 | [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && 89 | JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" 90 | fi 91 | 92 | if [ -z "$JAVA_HOME" ]; then 93 | javaExecutable="$(which javac)" 94 | if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then 95 | # readlink(1) is not available as standard on Solaris 10. 96 | readLink=$(which readlink) 97 | if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then 98 | if $darwin ; then 99 | javaHome="$(dirname "\"$javaExecutable\"")" 100 | javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" 101 | else 102 | javaExecutable="$(readlink -f "\"$javaExecutable\"")" 103 | fi 104 | javaHome="$(dirname "\"$javaExecutable\"")" 105 | javaHome=$(expr "$javaHome" : '\(.*\)/bin') 106 | JAVA_HOME="$javaHome" 107 | export JAVA_HOME 108 | fi 109 | fi 110 | fi 111 | 112 | if [ -z "$JAVACMD" ] ; then 113 | if [ -n "$JAVA_HOME" ] ; then 114 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 115 | # IBM's JDK on AIX uses strange locations for the executables 116 | JAVACMD="$JAVA_HOME/jre/sh/java" 117 | else 118 | JAVACMD="$JAVA_HOME/bin/java" 119 | fi 120 | else 121 | JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" 122 | fi 123 | fi 124 | 125 | if [ ! -x "$JAVACMD" ] ; then 126 | echo "Error: JAVA_HOME is not defined correctly." >&2 127 | echo " We cannot execute $JAVACMD" >&2 128 | exit 1 129 | fi 130 | 131 | if [ -z "$JAVA_HOME" ] ; then 132 | echo "Warning: JAVA_HOME environment variable is not set." 133 | fi 134 | 135 | # traverses directory structure from process work directory to filesystem root 136 | # first directory with .mvn subdirectory is considered project base directory 137 | find_maven_basedir() { 138 | if [ -z "$1" ] 139 | then 140 | echo "Path not specified to find_maven_basedir" 141 | return 1 142 | fi 143 | 144 | basedir="$1" 145 | wdir="$1" 146 | while [ "$wdir" != '/' ] ; do 147 | if [ -d "$wdir"/.mvn ] ; then 148 | basedir=$wdir 149 | break 150 | fi 151 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 152 | if [ -d "${wdir}" ]; then 153 | wdir=$(cd "$wdir/.." || exit 1; pwd) 154 | fi 155 | # end of workaround 156 | done 157 | printf '%s' "$(cd "$basedir" || exit 1; pwd)" 158 | } 159 | 160 | # concatenates all lines of a file 161 | concat_lines() { 162 | if [ -f "$1" ]; then 163 | # Remove \r in case we run on Windows within Git Bash 164 | # and check out the repository with auto CRLF management 165 | # enabled. Otherwise, we may read lines that are delimited with 166 | # \r\n and produce $'-Xarg\r' rather than -Xarg due to word 167 | # splitting rules. 168 | tr -s '\r\n' ' ' < "$1" 169 | fi 170 | } 171 | 172 | log() { 173 | if [ "$MVNW_VERBOSE" = true ]; then 174 | printf '%s\n' "$1" 175 | fi 176 | } 177 | 178 | BASE_DIR=$(find_maven_basedir "$(dirname "$0")") 179 | if [ -z "$BASE_DIR" ]; then 180 | exit 1; 181 | fi 182 | 183 | MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR 184 | log "$MAVEN_PROJECTBASEDIR" 185 | 186 | ########################################################################################## 187 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 188 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 189 | ########################################################################################## 190 | wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" 191 | if [ -r "$wrapperJarPath" ]; then 192 | log "Found $wrapperJarPath" 193 | else 194 | log "Couldn't find $wrapperJarPath, downloading it ..." 195 | 196 | if [ -n "$MVNW_REPOURL" ]; then 197 | wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 198 | else 199 | wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 200 | fi 201 | while IFS="=" read -r key value; do 202 | # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) 203 | safeValue=$(echo "$value" | tr -d '\r') 204 | case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; 205 | esac 206 | done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" 207 | log "Downloading from: $wrapperUrl" 208 | 209 | if $cygwin; then 210 | wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") 211 | fi 212 | 213 | if command -v wget > /dev/null; then 214 | log "Found wget ... using wget" 215 | [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" 216 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 217 | wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 218 | else 219 | wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 220 | fi 221 | elif command -v curl > /dev/null; then 222 | log "Found curl ... using curl" 223 | [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" 224 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 225 | curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" 226 | else 227 | curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" 228 | fi 229 | else 230 | log "Falling back to using Java to download" 231 | javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" 232 | javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" 233 | # For Cygwin, switch paths to Windows format before running javac 234 | if $cygwin; then 235 | javaSource=$(cygpath --path --windows "$javaSource") 236 | javaClass=$(cygpath --path --windows "$javaClass") 237 | fi 238 | if [ -e "$javaSource" ]; then 239 | if [ ! -e "$javaClass" ]; then 240 | log " - Compiling MavenWrapperDownloader.java ..." 241 | ("$JAVA_HOME/bin/javac" "$javaSource") 242 | fi 243 | if [ -e "$javaClass" ]; then 244 | log " - Running MavenWrapperDownloader.java ..." 245 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" 246 | fi 247 | fi 248 | fi 249 | fi 250 | ########################################################################################## 251 | # End of extension 252 | ########################################################################################## 253 | 254 | # If specified, validate the SHA-256 sum of the Maven wrapper jar file 255 | wrapperSha256Sum="" 256 | while IFS="=" read -r key value; do 257 | case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; 258 | esac 259 | done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" 260 | if [ -n "$wrapperSha256Sum" ]; then 261 | wrapperSha256Result=false 262 | if command -v sha256sum > /dev/null; then 263 | if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then 264 | wrapperSha256Result=true 265 | fi 266 | elif command -v shasum > /dev/null; then 267 | if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then 268 | wrapperSha256Result=true 269 | fi 270 | else 271 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." 272 | echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." 273 | exit 1 274 | fi 275 | if [ $wrapperSha256Result = false ]; then 276 | echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 277 | echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 278 | echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 279 | exit 1 280 | fi 281 | fi 282 | 283 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 284 | 285 | # For Cygwin, switch paths to Windows format before running java 286 | if $cygwin; then 287 | [ -n "$JAVA_HOME" ] && 288 | JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") 289 | [ -n "$CLASSPATH" ] && 290 | CLASSPATH=$(cygpath --path --windows "$CLASSPATH") 291 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 292 | MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") 293 | fi 294 | 295 | # Provide a "standardized" way to retrieve the CLI args that will 296 | # work with both Windows and non-Windows executions. 297 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" 298 | export MAVEN_CMD_LINE_ARGS 299 | 300 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 301 | 302 | # shellcheck disable=SC2086 # safe args 303 | exec "$JAVACMD" \ 304 | $MAVEN_OPTS \ 305 | $MAVEN_DEBUG_OPTS \ 306 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 307 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 308 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 309 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Apache Maven Wrapper startup batch script, version 3.2.0 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 28 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 29 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 30 | @REM e.g. to debug Maven itself, use 31 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 32 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 33 | @REM ---------------------------------------------------------------------------- 34 | 35 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 36 | @echo off 37 | @REM set title of command window 38 | title %0 39 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 40 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 41 | 42 | @REM set %HOME% to equivalent of $HOME 43 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 44 | 45 | @REM Execute a user defined script before this one 46 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 47 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 48 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 49 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 50 | :skipRcPre 51 | 52 | @setlocal 53 | 54 | set ERROR_CODE=0 55 | 56 | @REM To isolate internal variables from possible post scripts, we use another setlocal 57 | @setlocal 58 | 59 | @REM ==== START VALIDATION ==== 60 | if not "%JAVA_HOME%" == "" goto OkJHome 61 | 62 | echo. 63 | echo Error: JAVA_HOME not found in your environment. >&2 64 | echo Please set the JAVA_HOME variable in your environment to match the >&2 65 | echo location of your Java installation. >&2 66 | echo. 67 | goto error 68 | 69 | :OkJHome 70 | if exist "%JAVA_HOME%\bin\java.exe" goto init 71 | 72 | echo. 73 | echo Error: JAVA_HOME is set to an invalid directory. >&2 74 | echo JAVA_HOME = "%JAVA_HOME%" >&2 75 | echo Please set the JAVA_HOME variable in your environment to match the >&2 76 | echo location of your Java installation. >&2 77 | echo. 78 | goto error 79 | 80 | @REM ==== END VALIDATION ==== 81 | 82 | :init 83 | 84 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 85 | @REM Fallback to current working directory if not found. 86 | 87 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 88 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 89 | 90 | set EXEC_DIR=%CD% 91 | set WDIR=%EXEC_DIR% 92 | :findBaseDir 93 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 94 | cd .. 95 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 96 | set WDIR=%CD% 97 | goto findBaseDir 98 | 99 | :baseDirFound 100 | set MAVEN_PROJECTBASEDIR=%WDIR% 101 | cd "%EXEC_DIR%" 102 | goto endDetectBaseDir 103 | 104 | :baseDirNotFound 105 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 106 | cd "%EXEC_DIR%" 107 | 108 | :endDetectBaseDir 109 | 110 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 111 | 112 | @setlocal EnableExtensions EnableDelayedExpansion 113 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 114 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 115 | 116 | :endReadAdditionalConfig 117 | 118 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 123 | 124 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 125 | IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | if "%MVNW_VERBOSE%" == "true" ( 132 | echo Found %WRAPPER_JAR% 133 | ) 134 | ) else ( 135 | if not "%MVNW_REPOURL%" == "" ( 136 | SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" 137 | ) 138 | if "%MVNW_VERBOSE%" == "true" ( 139 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 140 | echo Downloading from: %WRAPPER_URL% 141 | ) 142 | 143 | powershell -Command "&{"^ 144 | "$webclient = new-object System.Net.WebClient;"^ 145 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 146 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 147 | "}"^ 148 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ 149 | "}" 150 | if "%MVNW_VERBOSE%" == "true" ( 151 | echo Finished downloading %WRAPPER_JAR% 152 | ) 153 | ) 154 | @REM End of extension 155 | 156 | @REM If specified, validate the SHA-256 sum of the Maven wrapper jar file 157 | SET WRAPPER_SHA_256_SUM="" 158 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 159 | IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B 160 | ) 161 | IF NOT %WRAPPER_SHA_256_SUM%=="" ( 162 | powershell -Command "&{"^ 163 | "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ 164 | "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ 165 | " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ 166 | " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ 167 | " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ 168 | " exit 1;"^ 169 | "}"^ 170 | "}" 171 | if ERRORLEVEL 1 goto error 172 | ) 173 | 174 | @REM Provide a "standardized" way to retrieve the CLI args that will 175 | @REM work with both Windows and non-Windows executions. 176 | set MAVEN_CMD_LINE_ARGS=%* 177 | 178 | %MAVEN_JAVA_EXE% ^ 179 | %JVM_CONFIG_MAVEN_PROPS% ^ 180 | %MAVEN_OPTS% ^ 181 | %MAVEN_DEBUG_OPTS% ^ 182 | -classpath %WRAPPER_JAR% ^ 183 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 184 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 185 | if ERRORLEVEL 1 goto error 186 | goto end 187 | 188 | :error 189 | set ERROR_CODE=1 190 | 191 | :end 192 | @endlocal & set ERROR_CODE=%ERROR_CODE% 193 | 194 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 195 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 196 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 197 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 198 | :skipRcPost 199 | 200 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 201 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 202 | 203 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 204 | 205 | cmd /C exit /B %ERROR_CODE% 206 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 3.2.3 10 | 11 | 12 | com.ecom 13 | Shopping_Cart 14 | 0.0.1-SNAPSHOT 15 | Shopping_Cart 16 | Online Shopping Cart Spring boot mvc Project 17 | 18 | 17 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-data-jpa 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-thymeleaf 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | 35 | com.mysql 36 | mysql-connector-j 37 | runtime 38 | 39 | 40 | 42 | 43 | org.springframework.boot 44 | spring-boot-devtools 45 | 46 | 47 | 48 | org.projectlombok 49 | lombok 50 | 1.18.32 51 | provided 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-test 57 | test 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-starter-security 63 | 64 | 66 | 67 | org.springframework.boot 68 | spring-boot-starter-mail 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.springframework.boot 79 | spring-boot-maven-plugin 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/ShoppingCartApplication.java: -------------------------------------------------------------------------------- 1 | package com.ecom; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ShoppingCartApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ShoppingCartApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/config/AuthFailureHandlerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.config; 2 | 3 | import java.io.IOException; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.authentication.LockedException; 7 | import org.springframework.security.core.AuthenticationException; 8 | import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; 9 | import org.springframework.stereotype.Component; 10 | 11 | import com.ecom.model.UserDtls; 12 | import com.ecom.repository.UserRepository; 13 | import com.ecom.service.UserService; 14 | import com.ecom.service.impl.UserServiceImpl; 15 | import com.ecom.util.AppConstant; 16 | 17 | import jakarta.servlet.ServletException; 18 | import jakarta.servlet.http.HttpServletRequest; 19 | import jakarta.servlet.http.HttpServletResponse; 20 | 21 | @Component 22 | public class AuthFailureHandlerImpl extends SimpleUrlAuthenticationFailureHandler { 23 | 24 | @Autowired 25 | private UserRepository userRepository; 26 | 27 | @Autowired 28 | private UserService userService; 29 | 30 | @Override 31 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, 32 | AuthenticationException exception) throws IOException, ServletException { 33 | 34 | String email = request.getParameter("username"); 35 | 36 | UserDtls userDtls = userRepository.findByEmail(email); 37 | 38 | if (userDtls != null) { 39 | 40 | if (userDtls.getIsEnable()) { 41 | 42 | if (userDtls.getAccountNonLocked()) { 43 | 44 | if (userDtls.getFailedAttempt() < AppConstant.ATTEMPT_TIME) { 45 | userService.increaseFailedAttempt(userDtls); 46 | } else { 47 | userService.userAccountLock(userDtls); 48 | exception = new LockedException("Your account is locked !! failed attempt 3"); 49 | } 50 | } else { 51 | 52 | if (userService.unlockAccountTimeExpired(userDtls)) { 53 | exception = new LockedException("Your account is unlocked !! Please try to login"); 54 | } else { 55 | exception = new LockedException("your account is Locked !! Please try after sometimes"); 56 | } 57 | } 58 | 59 | } else { 60 | exception = new LockedException("your account is inactive"); 61 | } 62 | } else { 63 | exception = new LockedException("Email & password invalid"); 64 | } 65 | 66 | super.setDefaultFailureUrl("/signin?error"); 67 | super.onAuthenticationFailure(request, response, exception); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/config/AuthSucessHandlerImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.config; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | import java.util.Set; 6 | 7 | import org.springframework.security.core.Authentication; 8 | import org.springframework.security.core.GrantedAuthority; 9 | import org.springframework.security.core.authority.AuthorityUtils; 10 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 11 | import org.springframework.stereotype.Service; 12 | 13 | import jakarta.servlet.ServletException; 14 | import jakarta.servlet.http.HttpServletRequest; 15 | import jakarta.servlet.http.HttpServletResponse; 16 | 17 | @Service 18 | public class AuthSucessHandlerImpl implements AuthenticationSuccessHandler { 19 | 20 | @Override 21 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, 22 | Authentication authentication) throws IOException, ServletException { 23 | 24 | Collection authorities = authentication.getAuthorities(); 25 | 26 | Set roles = AuthorityUtils.authorityListToSet(authorities); 27 | 28 | if(roles.contains("ROLE_ADMIN")) 29 | { 30 | response.sendRedirect("/admin/"); 31 | }else { 32 | response.sendRedirect("/"); 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/config/CustomUser.java: -------------------------------------------------------------------------------- 1 | package com.ecom.config; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collection; 5 | 6 | import org.springframework.security.core.GrantedAuthority; 7 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | 10 | import com.ecom.model.UserDtls; 11 | 12 | public class CustomUser implements UserDetails { 13 | 14 | private UserDtls user; 15 | 16 | public CustomUser(UserDtls user) { 17 | super(); 18 | this.user = user; 19 | } 20 | 21 | @Override 22 | public Collection getAuthorities() { 23 | SimpleGrantedAuthority authority = new SimpleGrantedAuthority(user.getRole()); 24 | return Arrays.asList(authority); 25 | } 26 | 27 | @Override 28 | public String getPassword() { 29 | return user.getPassword(); 30 | } 31 | 32 | @Override 33 | public String getUsername() { 34 | return user.getEmail(); 35 | } 36 | 37 | @Override 38 | public boolean isAccountNonExpired() { 39 | return true; 40 | } 41 | 42 | @Override 43 | public boolean isAccountNonLocked() { 44 | return user.getAccountNonLocked(); 45 | } 46 | 47 | @Override 48 | public boolean isCredentialsNonExpired() { 49 | return true; 50 | } 51 | 52 | @Override 53 | public boolean isEnabled() { 54 | return user.getIsEnable(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.ecom.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Lazy; 7 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.core.userdetails.UserDetailsService; 10 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 11 | import org.springframework.security.crypto.password.PasswordEncoder; 12 | import org.springframework.security.web.SecurityFilterChain; 13 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 14 | 15 | @Configuration 16 | public class SecurityConfig { 17 | 18 | @Autowired 19 | private AuthenticationSuccessHandler authenticationSuccessHandler; 20 | 21 | @Autowired 22 | @Lazy 23 | private AuthFailureHandlerImpl authenticationFailureHandler; 24 | 25 | @Bean 26 | public PasswordEncoder passwordEncoder() { 27 | return new BCryptPasswordEncoder(); 28 | } 29 | 30 | @Bean 31 | public UserDetailsService userDetailsService() { 32 | return new UserDetailsServiceImpl(); 33 | } 34 | 35 | @Bean 36 | public DaoAuthenticationProvider authenticationProvider() { 37 | DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider(); 38 | authenticationProvider.setUserDetailsService(userDetailsService()); 39 | authenticationProvider.setPasswordEncoder(passwordEncoder()); 40 | return authenticationProvider; 41 | } 42 | 43 | @Bean 44 | public SecurityFilterChain filterChain(HttpSecurity http) throws Exception 45 | { 46 | http.csrf(csrf->csrf.disable()).cors(cors->cors.disable()) 47 | .authorizeHttpRequests(req->req.requestMatchers("/user/**").hasRole("USER") 48 | .requestMatchers("/admin/**").hasRole("ADMIN") 49 | .requestMatchers("/**").permitAll()) 50 | .formLogin(form->form.loginPage("/signin") 51 | .loginProcessingUrl("/login") 52 | // .defaultSuccessUrl("/") 53 | .failureHandler(authenticationFailureHandler) 54 | .successHandler(authenticationSuccessHandler)) 55 | .logout(logout->logout.permitAll()); 56 | 57 | return http.build(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/config/UserDetailsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.security.core.userdetails.UserDetails; 5 | import org.springframework.security.core.userdetails.UserDetailsService; 6 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.ecom.model.UserDtls; 10 | import com.ecom.repository.UserRepository; 11 | 12 | @Service 13 | public class UserDetailsServiceImpl implements UserDetailsService { 14 | 15 | @Autowired 16 | private UserRepository userRepository; 17 | 18 | @Override 19 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 20 | 21 | UserDtls user = userRepository.findByEmail(username); 22 | 23 | if (user == null) { 24 | throw new UsernameNotFoundException("user not found"); 25 | } 26 | return new CustomUser(user); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/controller/AdminController.java: -------------------------------------------------------------------------------- 1 | package com.ecom.controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.nio.file.Paths; 8 | import java.nio.file.StandardCopyOption; 9 | import java.security.Principal; 10 | import java.util.List; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.core.io.ClassPathResource; 14 | import org.springframework.data.domain.Page; 15 | import org.springframework.security.crypto.password.PasswordEncoder; 16 | import org.springframework.stereotype.Controller; 17 | import org.springframework.ui.Model; 18 | import org.springframework.util.ObjectUtils; 19 | import org.springframework.web.bind.annotation.GetMapping; 20 | import org.springframework.web.bind.annotation.ModelAttribute; 21 | import org.springframework.web.bind.annotation.PathVariable; 22 | import org.springframework.web.bind.annotation.PostMapping; 23 | import org.springframework.web.bind.annotation.RequestMapping; 24 | import org.springframework.web.bind.annotation.RequestParam; 25 | import org.springframework.web.multipart.MultipartFile; 26 | 27 | import com.ecom.model.Category; 28 | import com.ecom.model.Product; 29 | import com.ecom.model.ProductOrder; 30 | import com.ecom.model.UserDtls; 31 | import com.ecom.service.CartService; 32 | import com.ecom.service.CategoryService; 33 | import com.ecom.service.OrderService; 34 | import com.ecom.service.ProductService; 35 | import com.ecom.service.UserService; 36 | import com.ecom.util.CommonUtil; 37 | import com.ecom.util.OrderStatus; 38 | 39 | import jakarta.servlet.http.HttpSession; 40 | 41 | @Controller 42 | @RequestMapping("/admin") 43 | public class AdminController { 44 | 45 | @Autowired 46 | private CategoryService categoryService; 47 | 48 | @Autowired 49 | private ProductService productService; 50 | 51 | @Autowired 52 | private UserService userService; 53 | 54 | @Autowired 55 | private CartService cartService; 56 | 57 | @Autowired 58 | private OrderService orderService; 59 | 60 | @Autowired 61 | private CommonUtil commonUtil; 62 | 63 | @Autowired 64 | private PasswordEncoder passwordEncoder; 65 | 66 | @ModelAttribute 67 | public void getUserDetails(Principal p, Model m) { 68 | if (p != null) { 69 | String email = p.getName(); 70 | UserDtls userDtls = userService.getUserByEmail(email); 71 | m.addAttribute("user", userDtls); 72 | Integer countCart = cartService.getCountCart(userDtls.getId()); 73 | m.addAttribute("countCart", countCart); 74 | } 75 | 76 | List allActiveCategory = categoryService.getAllActiveCategory(); 77 | m.addAttribute("categorys", allActiveCategory); 78 | } 79 | 80 | @GetMapping("/") 81 | public String index() { 82 | return "admin/index"; 83 | } 84 | 85 | @GetMapping("/loadAddProduct") 86 | public String loadAddProduct(Model m) { 87 | List categories = categoryService.getAllCategory(); 88 | m.addAttribute("categories", categories); 89 | return "admin/add_product"; 90 | } 91 | 92 | @GetMapping("/category") 93 | public String category(Model m, @RequestParam(name = "pageNo", defaultValue = "0") Integer pageNo, 94 | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { 95 | // m.addAttribute("categorys", categoryService.getAllCategory()); 96 | Page page = categoryService.getAllCategorPagination(pageNo, pageSize); 97 | List categorys = page.getContent(); 98 | m.addAttribute("categorys", categorys); 99 | 100 | m.addAttribute("pageNo", page.getNumber()); 101 | m.addAttribute("pageSize", pageSize); 102 | m.addAttribute("totalElements", page.getTotalElements()); 103 | m.addAttribute("totalPages", page.getTotalPages()); 104 | m.addAttribute("isFirst", page.isFirst()); 105 | m.addAttribute("isLast", page.isLast()); 106 | 107 | return "admin/category"; 108 | } 109 | 110 | @PostMapping("/saveCategory") 111 | public String saveCategory(@ModelAttribute Category category, @RequestParam("file") MultipartFile file, 112 | HttpSession session) throws IOException { 113 | 114 | String imageName = file != null ? file.getOriginalFilename() : "default.jpg"; 115 | category.setImageName(imageName); 116 | 117 | Boolean existCategory = categoryService.existCategory(category.getName()); 118 | 119 | if (existCategory) { 120 | session.setAttribute("errorMsg", "Category Name already exists"); 121 | } else { 122 | 123 | Category saveCategory = categoryService.saveCategory(category); 124 | 125 | if (ObjectUtils.isEmpty(saveCategory)) { 126 | session.setAttribute("errorMsg", "Not saved ! internal server error"); 127 | } else { 128 | 129 | File saveFile = new ClassPathResource("static/img").getFile(); 130 | 131 | Path path = Paths.get(saveFile.getAbsolutePath() + File.separator + "category_img" + File.separator 132 | + file.getOriginalFilename()); 133 | 134 | // System.out.println(path); 135 | Files.copy(file.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); 136 | 137 | session.setAttribute("succMsg", "Saved successfully"); 138 | } 139 | } 140 | 141 | return "redirect:/admin/category"; 142 | } 143 | 144 | @GetMapping("/deleteCategory/{id}") 145 | public String deleteCategory(@PathVariable int id, HttpSession session) { 146 | Boolean deleteCategory = categoryService.deleteCategory(id); 147 | 148 | if (deleteCategory) { 149 | session.setAttribute("succMsg", "category delete success"); 150 | } else { 151 | session.setAttribute("errorMsg", "something wrong on server"); 152 | } 153 | 154 | return "redirect:/admin/category"; 155 | } 156 | 157 | @GetMapping("/loadEditCategory/{id}") 158 | public String loadEditCategory(@PathVariable int id, Model m) { 159 | m.addAttribute("category", categoryService.getCategoryById(id)); 160 | return "admin/edit_category"; 161 | } 162 | 163 | @PostMapping("/updateCategory") 164 | public String updateCategory(@ModelAttribute Category category, @RequestParam("file") MultipartFile file, 165 | HttpSession session) throws IOException { 166 | 167 | Category oldCategory = categoryService.getCategoryById(category.getId()); 168 | String imageName = file.isEmpty() ? oldCategory.getImageName() : file.getOriginalFilename(); 169 | 170 | if (!ObjectUtils.isEmpty(category)) { 171 | 172 | oldCategory.setName(category.getName()); 173 | oldCategory.setIsActive(category.getIsActive()); 174 | oldCategory.setImageName(imageName); 175 | } 176 | 177 | Category updateCategory = categoryService.saveCategory(oldCategory); 178 | 179 | if (!ObjectUtils.isEmpty(updateCategory)) { 180 | 181 | if (!file.isEmpty()) { 182 | File saveFile = new ClassPathResource("static/img").getFile(); 183 | 184 | Path path = Paths.get(saveFile.getAbsolutePath() + File.separator + "category_img" + File.separator 185 | + file.getOriginalFilename()); 186 | 187 | // System.out.println(path); 188 | Files.copy(file.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); 189 | } 190 | 191 | session.setAttribute("succMsg", "Category update success"); 192 | } else { 193 | session.setAttribute("errorMsg", "something wrong on server"); 194 | } 195 | 196 | return "redirect:/admin/loadEditCategory/" + category.getId(); 197 | } 198 | 199 | @PostMapping("/saveProduct") 200 | public String saveProduct(@ModelAttribute Product product, @RequestParam("file") MultipartFile image, 201 | HttpSession session) throws IOException { 202 | 203 | String imageName = image.isEmpty() ? "default.jpg" : image.getOriginalFilename(); 204 | 205 | product.setImage(imageName); 206 | product.setDiscount(0); 207 | product.setDiscountPrice(product.getPrice()); 208 | Product saveProduct = productService.saveProduct(product); 209 | 210 | if (!ObjectUtils.isEmpty(saveProduct)) { 211 | 212 | File saveFile = new ClassPathResource("static/img").getFile(); 213 | 214 | Path path = Paths.get(saveFile.getAbsolutePath() + File.separator + "product_img" + File.separator 215 | + image.getOriginalFilename()); 216 | 217 | // System.out.println(path); 218 | Files.copy(image.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); 219 | 220 | session.setAttribute("succMsg", "Product Saved Success"); 221 | } else { 222 | session.setAttribute("errorMsg", "something wrong on server"); 223 | } 224 | 225 | return "redirect:/admin/loadAddProduct"; 226 | } 227 | 228 | @GetMapping("/products") 229 | public String loadViewProduct(Model m, @RequestParam(defaultValue = "") String ch, 230 | @RequestParam(name = "pageNo", defaultValue = "0") Integer pageNo, 231 | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { 232 | 233 | // List products = null; 234 | // if (ch != null && ch.length() > 0) { 235 | // products = productService.searchProduct(ch); 236 | // } else { 237 | // products = productService.getAllProducts(); 238 | // } 239 | // m.addAttribute("products", products); 240 | 241 | Page page = null; 242 | if (ch != null && ch.length() > 0) { 243 | page = productService.searchProductPagination(pageNo, pageSize, ch); 244 | } else { 245 | page = productService.getAllProductsPagination(pageNo, pageSize); 246 | } 247 | m.addAttribute("products", page.getContent()); 248 | 249 | m.addAttribute("pageNo", page.getNumber()); 250 | m.addAttribute("pageSize", pageSize); 251 | m.addAttribute("totalElements", page.getTotalElements()); 252 | m.addAttribute("totalPages", page.getTotalPages()); 253 | m.addAttribute("isFirst", page.isFirst()); 254 | m.addAttribute("isLast", page.isLast()); 255 | 256 | return "admin/products"; 257 | } 258 | 259 | @GetMapping("/deleteProduct/{id}") 260 | public String deleteProduct(@PathVariable int id, HttpSession session) { 261 | Boolean deleteProduct = productService.deleteProduct(id); 262 | if (deleteProduct) { 263 | session.setAttribute("succMsg", "Product delete success"); 264 | } else { 265 | session.setAttribute("errorMsg", "Something wrong on server"); 266 | } 267 | return "redirect:/admin/products"; 268 | } 269 | 270 | @GetMapping("/editProduct/{id}") 271 | public String editProduct(@PathVariable int id, Model m) { 272 | m.addAttribute("product", productService.getProductById(id)); 273 | m.addAttribute("categories", categoryService.getAllCategory()); 274 | return "admin/edit_product"; 275 | } 276 | 277 | @PostMapping("/updateProduct") 278 | public String updateProduct(@ModelAttribute Product product, @RequestParam("file") MultipartFile image, 279 | HttpSession session, Model m) { 280 | 281 | if (product.getDiscount() < 0 || product.getDiscount() > 100) { 282 | session.setAttribute("errorMsg", "invalid Discount"); 283 | } else { 284 | Product updateProduct = productService.updateProduct(product, image); 285 | if (!ObjectUtils.isEmpty(updateProduct)) { 286 | session.setAttribute("succMsg", "Product update success"); 287 | } else { 288 | session.setAttribute("errorMsg", "Something wrong on server"); 289 | } 290 | } 291 | return "redirect:/admin/editProduct/" + product.getId(); 292 | } 293 | 294 | @GetMapping("/users") 295 | public String getAllUsers(Model m, @RequestParam Integer type) { 296 | List users = null; 297 | if (type == 1) { 298 | users = userService.getUsers("ROLE_USER"); 299 | } else { 300 | users = userService.getUsers("ROLE_ADMIN"); 301 | } 302 | m.addAttribute("userType",type); 303 | m.addAttribute("users", users); 304 | return "/admin/users"; 305 | } 306 | 307 | @GetMapping("/updateSts") 308 | public String updateUserAccountStatus(@RequestParam Boolean status, @RequestParam Integer id,@RequestParam Integer type, HttpSession session) { 309 | Boolean f = userService.updateAccountStatus(id, status); 310 | if (f) { 311 | session.setAttribute("succMsg", "Account Status Updated"); 312 | } else { 313 | session.setAttribute("errorMsg", "Something wrong on server"); 314 | } 315 | return "redirect:/admin/users?type="+type; 316 | } 317 | 318 | @GetMapping("/orders") 319 | public String getAllOrders(Model m, @RequestParam(name = "pageNo", defaultValue = "0") Integer pageNo, 320 | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { 321 | // List allOrders = orderService.getAllOrders(); 322 | // m.addAttribute("orders", allOrders); 323 | // m.addAttribute("srch", false); 324 | 325 | Page page = orderService.getAllOrdersPagination(pageNo, pageSize); 326 | m.addAttribute("orders", page.getContent()); 327 | m.addAttribute("srch", false); 328 | 329 | m.addAttribute("pageNo", page.getNumber()); 330 | m.addAttribute("pageSize", pageSize); 331 | m.addAttribute("totalElements", page.getTotalElements()); 332 | m.addAttribute("totalPages", page.getTotalPages()); 333 | m.addAttribute("isFirst", page.isFirst()); 334 | m.addAttribute("isLast", page.isLast()); 335 | 336 | return "/admin/orders"; 337 | } 338 | 339 | @PostMapping("/update-order-status") 340 | public String updateOrderStatus(@RequestParam Integer id, @RequestParam Integer st, HttpSession session) { 341 | 342 | OrderStatus[] values = OrderStatus.values(); 343 | String status = null; 344 | 345 | for (OrderStatus orderSt : values) { 346 | if (orderSt.getId().equals(st)) { 347 | status = orderSt.getName(); 348 | } 349 | } 350 | 351 | ProductOrder updateOrder = orderService.updateOrderStatus(id, status); 352 | 353 | try { 354 | commonUtil.sendMailForProductOrder(updateOrder, status); 355 | } catch (Exception e) { 356 | e.printStackTrace(); 357 | } 358 | 359 | if (!ObjectUtils.isEmpty(updateOrder)) { 360 | session.setAttribute("succMsg", "Status Updated"); 361 | } else { 362 | session.setAttribute("errorMsg", "status not updated"); 363 | } 364 | return "redirect:/admin/orders"; 365 | } 366 | 367 | @GetMapping("/search-order") 368 | public String searchProduct(@RequestParam String orderId, Model m, HttpSession session, 369 | @RequestParam(name = "pageNo", defaultValue = "0") Integer pageNo, 370 | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { 371 | 372 | if (orderId != null && orderId.length() > 0) { 373 | 374 | ProductOrder order = orderService.getOrdersByOrderId(orderId.trim()); 375 | 376 | if (ObjectUtils.isEmpty(order)) { 377 | session.setAttribute("errorMsg", "Incorrect orderId"); 378 | m.addAttribute("orderDtls", null); 379 | } else { 380 | m.addAttribute("orderDtls", order); 381 | } 382 | 383 | m.addAttribute("srch", true); 384 | } else { 385 | // List allOrders = orderService.getAllOrders(); 386 | // m.addAttribute("orders", allOrders); 387 | // m.addAttribute("srch", false); 388 | 389 | Page page = orderService.getAllOrdersPagination(pageNo, pageSize); 390 | m.addAttribute("orders", page); 391 | m.addAttribute("srch", false); 392 | 393 | m.addAttribute("pageNo", page.getNumber()); 394 | m.addAttribute("pageSize", pageSize); 395 | m.addAttribute("totalElements", page.getTotalElements()); 396 | m.addAttribute("totalPages", page.getTotalPages()); 397 | m.addAttribute("isFirst", page.isFirst()); 398 | m.addAttribute("isLast", page.isLast()); 399 | 400 | } 401 | return "/admin/orders"; 402 | 403 | } 404 | 405 | @GetMapping("/add-admin") 406 | public String loadAdminAdd() { 407 | return "/admin/add_admin"; 408 | } 409 | 410 | @PostMapping("/save-admin") 411 | public String saveAdmin(@ModelAttribute UserDtls user, @RequestParam("img") MultipartFile file, HttpSession session) 412 | throws IOException { 413 | 414 | String imageName = file.isEmpty() ? "default.jpg" : file.getOriginalFilename(); 415 | user.setProfileImage(imageName); 416 | UserDtls saveUser = userService.saveAdmin(user); 417 | 418 | if (!ObjectUtils.isEmpty(saveUser)) { 419 | if (!file.isEmpty()) { 420 | File saveFile = new ClassPathResource("static/img").getFile(); 421 | 422 | Path path = Paths.get(saveFile.getAbsolutePath() + File.separator + "profile_img" + File.separator 423 | + file.getOriginalFilename()); 424 | 425 | // System.out.println(path); 426 | Files.copy(file.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); 427 | } 428 | session.setAttribute("succMsg", "Register successfully"); 429 | } else { 430 | session.setAttribute("errorMsg", "something wrong on server"); 431 | } 432 | 433 | return "redirect:/admin/add-admin"; 434 | } 435 | 436 | @GetMapping("/profile") 437 | public String profile() { 438 | return "/admin/profile"; 439 | } 440 | 441 | @PostMapping("/update-profile") 442 | public String updateProfile(@ModelAttribute UserDtls user, @RequestParam MultipartFile img, HttpSession session) { 443 | UserDtls updateUserProfile = userService.updateUserProfile(user, img); 444 | if (ObjectUtils.isEmpty(updateUserProfile)) { 445 | session.setAttribute("errorMsg", "Profile not updated"); 446 | } else { 447 | session.setAttribute("succMsg", "Profile Updated"); 448 | } 449 | return "redirect:/admin/profile"; 450 | } 451 | 452 | @PostMapping("/change-password") 453 | public String changePassword(@RequestParam String newPassword, @RequestParam String currentPassword, Principal p, 454 | HttpSession session) { 455 | UserDtls loggedInUserDetails = commonUtil.getLoggedInUserDetails(p); 456 | 457 | boolean matches = passwordEncoder.matches(currentPassword, loggedInUserDetails.getPassword()); 458 | 459 | if (matches) { 460 | String encodePassword = passwordEncoder.encode(newPassword); 461 | loggedInUserDetails.setPassword(encodePassword); 462 | UserDtls updateUser = userService.updateUser(loggedInUserDetails); 463 | if (ObjectUtils.isEmpty(updateUser)) { 464 | session.setAttribute("errorMsg", "Password not updated !! Error in server"); 465 | } else { 466 | session.setAttribute("succMsg", "Password Updated sucessfully"); 467 | } 468 | } else { 469 | session.setAttribute("errorMsg", "Current Password incorrect"); 470 | } 471 | 472 | return "redirect:/admin/profile"; 473 | } 474 | 475 | } 476 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.ecom.controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.UnsupportedEncodingException; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | import java.nio.file.Paths; 9 | import java.nio.file.StandardCopyOption; 10 | import java.security.Principal; 11 | import java.util.List; 12 | import java.util.Random; 13 | import java.util.UUID; 14 | import java.util.stream.Collector; 15 | 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.core.io.ClassPathResource; 18 | import org.springframework.data.domain.Page; 19 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 20 | import org.springframework.stereotype.Controller; 21 | import org.springframework.ui.Model; 22 | import org.springframework.util.ObjectUtils; 23 | import org.springframework.web.bind.annotation.GetMapping; 24 | import org.springframework.web.bind.annotation.ModelAttribute; 25 | import org.springframework.web.bind.annotation.PathVariable; 26 | import org.springframework.web.bind.annotation.PostMapping; 27 | import org.springframework.web.bind.annotation.RequestParam; 28 | import org.springframework.web.multipart.MultipartFile; 29 | 30 | import com.ecom.model.Category; 31 | import com.ecom.model.Product; 32 | import com.ecom.model.UserDtls; 33 | import com.ecom.service.CartService; 34 | import com.ecom.service.CategoryService; 35 | import com.ecom.service.ProductService; 36 | import com.ecom.service.UserService; 37 | import com.ecom.util.CommonUtil; 38 | 39 | import io.micrometer.common.util.StringUtils; 40 | import jakarta.mail.MessagingException; 41 | import jakarta.servlet.http.HttpServletRequest; 42 | import jakarta.servlet.http.HttpSession; 43 | 44 | @Controller 45 | public class HomeController { 46 | 47 | @Autowired 48 | private CategoryService categoryService; 49 | 50 | @Autowired 51 | private ProductService productService; 52 | 53 | @Autowired 54 | private UserService userService; 55 | 56 | @Autowired 57 | private CommonUtil commonUtil; 58 | 59 | @Autowired 60 | private BCryptPasswordEncoder passwordEncoder; 61 | 62 | @Autowired 63 | private CartService cartService; 64 | 65 | @ModelAttribute 66 | public void getUserDetails(Principal p, Model m) { 67 | if (p != null) { 68 | String email = p.getName(); 69 | UserDtls userDtls = userService.getUserByEmail(email); 70 | m.addAttribute("user", userDtls); 71 | Integer countCart = cartService.getCountCart(userDtls.getId()); 72 | m.addAttribute("countCart", countCart); 73 | } 74 | 75 | List allActiveCategory = categoryService.getAllActiveCategory(); 76 | m.addAttribute("categorys", allActiveCategory); 77 | } 78 | 79 | @GetMapping("/") 80 | public String index(Model m) { 81 | 82 | List allActiveCategory = categoryService.getAllActiveCategory().stream() 83 | .sorted((c1, c2) -> c2.getId().compareTo(c1.getId())).limit(6).toList(); 84 | List allActiveProducts = productService.getAllActiveProducts("").stream() 85 | .sorted((p1, p2) -> p2.getId().compareTo(p1.getId())).limit(8).toList(); 86 | m.addAttribute("category", allActiveCategory); 87 | m.addAttribute("products", allActiveProducts); 88 | return "index"; 89 | } 90 | 91 | @GetMapping("/signin") 92 | public String login() { 93 | return "login"; 94 | } 95 | 96 | @GetMapping("/register") 97 | public String register() { 98 | return "register"; 99 | } 100 | 101 | @GetMapping("/products") 102 | public String products(Model m, @RequestParam(value = "category", defaultValue = "") String category, 103 | @RequestParam(name = "pageNo", defaultValue = "0") Integer pageNo, 104 | @RequestParam(name = "pageSize", defaultValue = "12") Integer pageSize, 105 | @RequestParam(defaultValue = "") String ch) { 106 | 107 | List categories = categoryService.getAllActiveCategory(); 108 | m.addAttribute("paramValue", category); 109 | m.addAttribute("categories", categories); 110 | 111 | // List products = productService.getAllActiveProducts(category); 112 | // m.addAttribute("products", products); 113 | Page page = null; 114 | if (StringUtils.isEmpty(ch)) { 115 | page = productService.getAllActiveProductPagination(pageNo, pageSize, category); 116 | } else { 117 | page = productService.searchActiveProductPagination(pageNo, pageSize, category, ch); 118 | } 119 | 120 | List products = page.getContent(); 121 | m.addAttribute("products", products); 122 | m.addAttribute("productsSize", products.size()); 123 | 124 | m.addAttribute("pageNo", page.getNumber()); 125 | m.addAttribute("pageSize", pageSize); 126 | m.addAttribute("totalElements", page.getTotalElements()); 127 | m.addAttribute("totalPages", page.getTotalPages()); 128 | m.addAttribute("isFirst", page.isFirst()); 129 | m.addAttribute("isLast", page.isLast()); 130 | 131 | return "product"; 132 | } 133 | 134 | @GetMapping("/product/{id}") 135 | public String product(@PathVariable int id, Model m) { 136 | Product productById = productService.getProductById(id); 137 | m.addAttribute("product", productById); 138 | return "view_product"; 139 | } 140 | 141 | @PostMapping("/saveUser") 142 | public String saveUser(@ModelAttribute UserDtls user, @RequestParam("img") MultipartFile file, HttpSession session) 143 | throws IOException { 144 | 145 | Boolean existsEmail = userService.existsEmail(user.getEmail()); 146 | 147 | if (existsEmail) { 148 | session.setAttribute("errorMsg", "Email already exist"); 149 | } else { 150 | String imageName = file.isEmpty() ? "default.jpg" : file.getOriginalFilename(); 151 | user.setProfileImage(imageName); 152 | UserDtls saveUser = userService.saveUser(user); 153 | 154 | if (!ObjectUtils.isEmpty(saveUser)) { 155 | if (!file.isEmpty()) { 156 | File saveFile = new ClassPathResource("static/img").getFile(); 157 | 158 | Path path = Paths.get(saveFile.getAbsolutePath() + File.separator + "profile_img" + File.separator 159 | + file.getOriginalFilename()); 160 | 161 | // System.out.println(path); 162 | Files.copy(file.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); 163 | } 164 | session.setAttribute("succMsg", "Register successfully"); 165 | } else { 166 | session.setAttribute("errorMsg", "something wrong on server"); 167 | } 168 | } 169 | 170 | return "redirect:/register"; 171 | } 172 | 173 | // Forgot Password Code 174 | 175 | @GetMapping("/forgot-password") 176 | public String showForgotPassword() { 177 | return "forgot_password.html"; 178 | } 179 | 180 | @PostMapping("/forgot-password") 181 | public String processForgotPassword(@RequestParam String email, HttpSession session, HttpServletRequest request) 182 | throws UnsupportedEncodingException, MessagingException { 183 | 184 | UserDtls userByEmail = userService.getUserByEmail(email); 185 | 186 | if (ObjectUtils.isEmpty(userByEmail)) { 187 | session.setAttribute("errorMsg", "Invalid email"); 188 | } else { 189 | 190 | String resetToken = UUID.randomUUID().toString(); 191 | userService.updateUserResetToken(email, resetToken); 192 | 193 | // Generate URL : 194 | // http://localhost:8080/reset-password?token=sfgdbgfswegfbdgfewgvsrg 195 | 196 | String url = CommonUtil.generateUrl(request) + "/reset-password?token=" + resetToken; 197 | 198 | Boolean sendMail = commonUtil.sendMail(url, email); 199 | 200 | if (sendMail) { 201 | session.setAttribute("succMsg", "Please check your email..Password Reset link sent"); 202 | } else { 203 | session.setAttribute("errorMsg", "Somethong wrong on server ! Email not send"); 204 | } 205 | } 206 | 207 | return "redirect:/forgot-password"; 208 | } 209 | 210 | @GetMapping("/reset-password") 211 | public String showResetPassword(@RequestParam String token, HttpSession session, Model m) { 212 | 213 | UserDtls userByToken = userService.getUserByToken(token); 214 | 215 | if (userByToken == null) { 216 | m.addAttribute("msg", "Your link is invalid or expired !!"); 217 | return "message"; 218 | } 219 | m.addAttribute("token", token); 220 | return "reset_password"; 221 | } 222 | 223 | @PostMapping("/reset-password") 224 | public String resetPassword(@RequestParam String token, @RequestParam String password, HttpSession session, 225 | Model m) { 226 | 227 | UserDtls userByToken = userService.getUserByToken(token); 228 | if (userByToken == null) { 229 | m.addAttribute("errorMsg", "Your link is invalid or expired !!"); 230 | return "message"; 231 | } else { 232 | userByToken.setPassword(passwordEncoder.encode(password)); 233 | userByToken.setResetToken(null); 234 | userService.updateUser(userByToken); 235 | // session.setAttribute("succMsg", "Password change successfully"); 236 | m.addAttribute("msg", "Password change successfully"); 237 | 238 | return "message"; 239 | } 240 | 241 | } 242 | 243 | @GetMapping("/search") 244 | public String searchProduct(@RequestParam String ch, Model m) { 245 | List searchProducts = productService.searchProduct(ch); 246 | m.addAttribute("products", searchProducts); 247 | List categories = categoryService.getAllActiveCategory(); 248 | m.addAttribute("categories", categories); 249 | return "product"; 250 | 251 | } 252 | 253 | } 254 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.ecom.controller; 2 | 3 | import java.security.Principal; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.crypto.password.PasswordEncoder; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.ui.Model; 10 | import org.springframework.util.ObjectUtils; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.ModelAttribute; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | import org.springframework.web.multipart.MultipartFile; 17 | 18 | import com.ecom.model.Cart; 19 | import com.ecom.model.Category; 20 | import com.ecom.model.OrderRequest; 21 | import com.ecom.model.ProductOrder; 22 | import com.ecom.model.UserDtls; 23 | import com.ecom.repository.UserRepository; 24 | import com.ecom.service.CartService; 25 | import com.ecom.service.CategoryService; 26 | import com.ecom.service.OrderService; 27 | import com.ecom.service.UserService; 28 | import com.ecom.util.CommonUtil; 29 | import com.ecom.util.OrderStatus; 30 | 31 | import jakarta.servlet.http.HttpSession; 32 | 33 | @Controller 34 | @RequestMapping("/user") 35 | public class UserController { 36 | @Autowired 37 | private UserService userService; 38 | @Autowired 39 | private CategoryService categoryService; 40 | 41 | @Autowired 42 | private CartService cartService; 43 | 44 | @Autowired 45 | private OrderService orderService; 46 | 47 | @Autowired 48 | private CommonUtil commonUtil; 49 | 50 | @Autowired 51 | private PasswordEncoder passwordEncoder; 52 | 53 | 54 | @GetMapping("/") 55 | public String home() { 56 | return "user/home"; 57 | } 58 | 59 | @ModelAttribute 60 | public void getUserDetails(Principal p, Model m) { 61 | if (p != null) { 62 | String email = p.getName(); 63 | UserDtls userDtls = userService.getUserByEmail(email); 64 | m.addAttribute("user", userDtls); 65 | Integer countCart = cartService.getCountCart(userDtls.getId()); 66 | m.addAttribute("countCart", countCart); 67 | } 68 | 69 | List allActiveCategory = categoryService.getAllActiveCategory(); 70 | m.addAttribute("categorys", allActiveCategory); 71 | } 72 | 73 | @GetMapping("/addCart") 74 | public String addToCart(@RequestParam Integer pid, @RequestParam Integer uid, HttpSession session) { 75 | Cart saveCart = cartService.saveCart(pid, uid); 76 | 77 | if (ObjectUtils.isEmpty(saveCart)) { 78 | session.setAttribute("errorMsg", "Product add to cart failed"); 79 | } else { 80 | session.setAttribute("succMsg", "Product added to cart"); 81 | } 82 | return "redirect:/product/" + pid; 83 | } 84 | 85 | @GetMapping("/cart") 86 | public String loadCartPage(Principal p, Model m) { 87 | 88 | UserDtls user = getLoggedInUserDetails(p); 89 | List carts = cartService.getCartsByUser(user.getId()); 90 | m.addAttribute("carts", carts); 91 | if (carts.size() > 0) { 92 | Double totalOrderPrice = carts.get(carts.size() - 1).getTotalOrderPrice(); 93 | m.addAttribute("totalOrderPrice", totalOrderPrice); 94 | } 95 | return "/user/cart"; 96 | } 97 | 98 | @GetMapping("/cartQuantityUpdate") 99 | public String updateCartQuantity(@RequestParam String sy, @RequestParam Integer cid) { 100 | cartService.updateQuantity(sy, cid); 101 | return "redirect:/user/cart"; 102 | } 103 | 104 | private UserDtls getLoggedInUserDetails(Principal p) { 105 | String email = p.getName(); 106 | UserDtls userDtls = userService.getUserByEmail(email); 107 | return userDtls; 108 | } 109 | 110 | @GetMapping("/orders") 111 | public String orderPage(Principal p, Model m) { 112 | UserDtls user = getLoggedInUserDetails(p); 113 | List carts = cartService.getCartsByUser(user.getId()); 114 | m.addAttribute("carts", carts); 115 | if (carts.size() > 0) { 116 | Double orderPrice = carts.get(carts.size() - 1).getTotalOrderPrice(); 117 | Double totalOrderPrice = carts.get(carts.size() - 1).getTotalOrderPrice() + 250 + 100; 118 | m.addAttribute("orderPrice", orderPrice); 119 | m.addAttribute("totalOrderPrice", totalOrderPrice); 120 | } 121 | return "/user/order"; 122 | } 123 | 124 | @PostMapping("/save-order") 125 | public String saveOrder(@ModelAttribute OrderRequest request, Principal p) throws Exception { 126 | // System.out.println(request); 127 | UserDtls user = getLoggedInUserDetails(p); 128 | orderService.saveOrder(user.getId(), request); 129 | 130 | return "redirect:/user/success"; 131 | } 132 | 133 | @GetMapping("/success") 134 | public String loadSuccess() { 135 | return "/user/success"; 136 | } 137 | 138 | @GetMapping("/user-orders") 139 | public String myOrder(Model m, Principal p) { 140 | UserDtls loginUser = getLoggedInUserDetails(p); 141 | List orders = orderService.getOrdersByUser(loginUser.getId()); 142 | m.addAttribute("orders", orders); 143 | return "/user/my_orders"; 144 | } 145 | 146 | @GetMapping("/update-status") 147 | public String updateOrderStatus(@RequestParam Integer id, @RequestParam Integer st, HttpSession session) { 148 | 149 | OrderStatus[] values = OrderStatus.values(); 150 | String status = null; 151 | 152 | for (OrderStatus orderSt : values) { 153 | if (orderSt.getId().equals(st)) { 154 | status = orderSt.getName(); 155 | } 156 | } 157 | 158 | ProductOrder updateOrder = orderService.updateOrderStatus(id, status); 159 | 160 | try { 161 | commonUtil.sendMailForProductOrder(updateOrder, status); 162 | } catch (Exception e) { 163 | e.printStackTrace(); 164 | } 165 | 166 | if (!ObjectUtils.isEmpty(updateOrder)) { 167 | session.setAttribute("succMsg", "Status Updated"); 168 | } else { 169 | session.setAttribute("errorMsg", "status not updated"); 170 | } 171 | return "redirect:/user/user-orders"; 172 | } 173 | 174 | @GetMapping("/profile") 175 | public String profile() { 176 | return "/user/profile"; 177 | } 178 | 179 | @PostMapping("/update-profile") 180 | public String updateProfile(@ModelAttribute UserDtls user, @RequestParam MultipartFile img, HttpSession session) { 181 | UserDtls updateUserProfile = userService.updateUserProfile(user, img); 182 | if (ObjectUtils.isEmpty(updateUserProfile)) { 183 | session.setAttribute("errorMsg", "Profile not updated"); 184 | } else { 185 | session.setAttribute("succMsg", "Profile Updated"); 186 | } 187 | return "redirect:/user/profile"; 188 | } 189 | 190 | @PostMapping("/change-password") 191 | public String changePassword(@RequestParam String newPassword, @RequestParam String currentPassword, Principal p, 192 | HttpSession session) { 193 | UserDtls loggedInUserDetails = getLoggedInUserDetails(p); 194 | 195 | boolean matches = passwordEncoder.matches(currentPassword, loggedInUserDetails.getPassword()); 196 | 197 | if (matches) { 198 | String encodePassword = passwordEncoder.encode(newPassword); 199 | loggedInUserDetails.setPassword(encodePassword); 200 | UserDtls updateUser = userService.updateUser(loggedInUserDetails); 201 | if (ObjectUtils.isEmpty(updateUser)) { 202 | session.setAttribute("errorMsg", "Password not updated !! Error in server"); 203 | } else { 204 | session.setAttribute("succMsg", "Password Updated sucessfully"); 205 | } 206 | } else { 207 | session.setAttribute("errorMsg", "Current Password incorrect"); 208 | } 209 | 210 | return "redirect:/user/profile"; 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/model/Cart.java: -------------------------------------------------------------------------------- 1 | package com.ecom.model; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.ManyToOne; 8 | import jakarta.persistence.Transient; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Getter; 11 | import lombok.NoArgsConstructor; 12 | import lombok.Setter; 13 | 14 | @Entity 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Getter 18 | @Setter 19 | public class Cart { 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private Integer id; 24 | 25 | @ManyToOne 26 | private UserDtls user; 27 | 28 | @ManyToOne 29 | private Product product; 30 | 31 | private Integer quantity; 32 | 33 | @Transient 34 | private Double totalPrice; 35 | 36 | @Transient 37 | private Double totalOrderPrice; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/model/Category.java: -------------------------------------------------------------------------------- 1 | package com.ecom.model; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Getter; 9 | import lombok.NoArgsConstructor; 10 | import lombok.Setter; 11 | 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @Getter 15 | @Setter 16 | @Entity 17 | public class Category { 18 | 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | private Integer id; 22 | 23 | private String name; 24 | 25 | private String imageName; 26 | 27 | private Boolean isActive; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/model/OrderAddress.java: -------------------------------------------------------------------------------- 1 | package com.ecom.model; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import lombok.Data; 8 | 9 | @Data 10 | @Entity 11 | public class OrderAddress { 12 | 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | private Integer id; 16 | 17 | private String firstName; 18 | 19 | private String lastName; 20 | 21 | private String email; 22 | 23 | private String mobileNo; 24 | 25 | private String address; 26 | 27 | private String city; 28 | 29 | private String state; 30 | 31 | private String pincode; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/model/OrderRequest.java: -------------------------------------------------------------------------------- 1 | package com.ecom.model; 2 | 3 | import lombok.Data; 4 | import lombok.ToString; 5 | 6 | @ToString 7 | @Data 8 | public class OrderRequest { 9 | 10 | private String firstName; 11 | 12 | private String lastName; 13 | 14 | private String email; 15 | 16 | private String mobileNo; 17 | 18 | private String address; 19 | 20 | private String city; 21 | 22 | private String state; 23 | 24 | private String pincode; 25 | 26 | private String paymentType; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/model/Product.java: -------------------------------------------------------------------------------- 1 | package com.ecom.model; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.GeneratedValue; 6 | import jakarta.persistence.GenerationType; 7 | import jakarta.persistence.Id; 8 | import lombok.AllArgsConstructor; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @Getter 16 | @Setter 17 | @Entity 18 | public class Product { 19 | 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private Integer id; 23 | 24 | @Column(length = 500) 25 | private String title; 26 | 27 | @Column(length = 5000) 28 | private String description; 29 | 30 | private String category; 31 | 32 | private Double price; 33 | 34 | private int stock; 35 | 36 | private String image; 37 | 38 | private int discount; 39 | 40 | private Double discountPrice; 41 | 42 | private Boolean isActive; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/model/ProductOrder.java: -------------------------------------------------------------------------------- 1 | package com.ecom.model; 2 | 3 | import java.time.LocalDate; 4 | import java.util.Date; 5 | 6 | import jakarta.persistence.CascadeType; 7 | import jakarta.persistence.Entity; 8 | import jakarta.persistence.GeneratedValue; 9 | import jakarta.persistence.GenerationType; 10 | import jakarta.persistence.Id; 11 | import jakarta.persistence.ManyToOne; 12 | import jakarta.persistence.OneToOne; 13 | import lombok.AllArgsConstructor; 14 | import lombok.Getter; 15 | import lombok.NoArgsConstructor; 16 | import lombok.Setter; 17 | 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | @Getter 21 | @Setter 22 | @Entity 23 | public class ProductOrder { 24 | 25 | @Id 26 | @GeneratedValue(strategy = GenerationType.IDENTITY) 27 | private Integer id; 28 | 29 | private String orderId; 30 | 31 | private LocalDate orderDate; 32 | 33 | @ManyToOne 34 | private Product product; 35 | 36 | private Double price; 37 | 38 | private Integer quantity; 39 | 40 | @ManyToOne 41 | private UserDtls user; 42 | 43 | private String status; 44 | 45 | private String paymentType; 46 | 47 | @OneToOne(cascade = CascadeType.ALL) 48 | private OrderAddress orderAddress; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/model/UserDtls.java: -------------------------------------------------------------------------------- 1 | package com.ecom.model; 2 | 3 | import java.util.Date; 4 | 5 | import jakarta.persistence.Entity; 6 | import jakarta.persistence.GeneratedValue; 7 | import jakarta.persistence.GenerationType; 8 | import jakarta.persistence.Id; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Getter; 11 | import lombok.NoArgsConstructor; 12 | import lombok.Setter; 13 | 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | @Getter 17 | @Setter 18 | @Entity 19 | public class UserDtls { 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private Integer id; 24 | 25 | private String name; 26 | 27 | private String mobileNumber; 28 | 29 | private String email; 30 | 31 | private String address; 32 | 33 | private String city; 34 | 35 | private String state; 36 | 37 | private String pincode; 38 | 39 | private String password; 40 | 41 | private String profileImage; 42 | 43 | private String role; 44 | 45 | private Boolean isEnable; 46 | 47 | private Boolean accountNonLocked; 48 | 49 | private Integer failedAttempt; 50 | 51 | private Date lockTime; 52 | 53 | private String resetToken; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/repository/CartRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecom.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.Modifying; 7 | 8 | import com.ecom.model.Cart; 9 | import com.ecom.model.UserDtls; 10 | 11 | import jakarta.transaction.Transactional; 12 | 13 | public interface CartRepository extends JpaRepository { 14 | 15 | public Cart findByProductIdAndUserId(Integer productId, Integer userId); 16 | 17 | public Integer countByUserId(Integer userId); 18 | 19 | public List findByUserId(Integer userId); 20 | 21 | @Transactional 22 | @Modifying 23 | public void deleteByUser(UserDtls user); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/repository/CategoryRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecom.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import com.ecom.model.Category; 8 | 9 | public interface CategoryRepository extends JpaRepository { 10 | 11 | public Boolean existsByName(String name); 12 | 13 | public List findByIsActiveTrue(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/repository/ProductOrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecom.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import com.ecom.model.ProductOrder; 8 | 9 | public interface ProductOrderRepository extends JpaRepository { 10 | 11 | List findByUserId(Integer userId); 12 | 13 | ProductOrder findByOrderId(String orderId); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecom.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.data.jpa.repository.JpaRepository; 8 | 9 | import com.ecom.model.Product; 10 | 11 | public interface ProductRepository extends JpaRepository { 12 | 13 | List findByIsActiveTrue(); 14 | 15 | Page findByIsActiveTrue(Pageable pageable); 16 | 17 | List findByCategory(String category); 18 | 19 | List findByTitleContainingIgnoreCaseOrCategoryContainingIgnoreCase(String ch, String ch2); 20 | 21 | Page findByCategory(Pageable pageable, String category); 22 | 23 | Page findByTitleContainingIgnoreCaseOrCategoryContainingIgnoreCase(String ch, String ch2, 24 | Pageable pageable); 25 | 26 | Page findByisActiveTrueAndTitleContainingIgnoreCaseOrCategoryContainingIgnoreCase(String ch, String ch2, 27 | Pageable pageable); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.ecom.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import com.ecom.model.UserDtls; 8 | 9 | public interface UserRepository extends JpaRepository { 10 | 11 | public UserDtls findByEmail(String email); 12 | 13 | public List findByRole(String role); 14 | 15 | public UserDtls findByResetToken(String token); 16 | 17 | public Boolean existsByEmail(String email); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service; 2 | 3 | import java.util.List; 4 | 5 | import com.ecom.model.Cart; 6 | 7 | public interface CartService { 8 | 9 | public Cart saveCart(Integer productId, Integer userId); 10 | 11 | public List getCartsByUser(Integer userId); 12 | 13 | public Integer getCountCart(Integer userId); 14 | 15 | public void updateQuantity(String sy, Integer cid); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/CategoryService.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | 8 | import com.ecom.model.Category; 9 | 10 | public interface CategoryService { 11 | 12 | public Category saveCategory(Category category); 13 | 14 | public Boolean existCategory(String name); 15 | 16 | public List getAllCategory(); 17 | 18 | public Boolean deleteCategory(int id); 19 | 20 | public Category getCategoryById(int id); 21 | 22 | public List getAllActiveCategory(); 23 | 24 | public Page getAllCategorPagination(Integer pageNo,Integer pageSize); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/CommnServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.web.context.request.RequestContextHolder; 6 | import org.springframework.web.context.request.ServletRequestAttributes; 7 | 8 | import jakarta.servlet.http.HttpServletRequest; 9 | import jakarta.servlet.http.HttpSession; 10 | 11 | @Service 12 | public class CommnServiceImpl implements CommonService { 13 | 14 | @Value("${rupee.sign}") 15 | public String rupeeSign; 16 | 17 | @Override 18 | public void removeSessionMessage() { 19 | HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes())) 20 | .getRequest(); 21 | HttpSession session = request.getSession(); 22 | session.removeAttribute("succMsg"); 23 | session.removeAttribute("errorMsg"); 24 | } 25 | 26 | @Override 27 | public String rupeeSign() 28 | { 29 | return rupeeSign; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/CommonService.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service; 2 | 3 | public interface CommonService { 4 | 5 | public void removeSessionMessage(); 6 | public String rupeeSign(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | 7 | import com.ecom.model.OrderRequest; 8 | import com.ecom.model.ProductOrder; 9 | 10 | public interface OrderService { 11 | 12 | public void saveOrder(Integer userid, OrderRequest orderRequest) throws Exception; 13 | 14 | public List getOrdersByUser(Integer userId); 15 | 16 | public ProductOrder updateOrderStatus(Integer id, String status); 17 | 18 | public List getAllOrders(); 19 | 20 | public ProductOrder getOrdersByOrderId(String orderId); 21 | 22 | public Page getAllOrdersPagination(Integer pageNo,Integer pageSize); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import com.ecom.model.Product; 9 | 10 | public interface ProductService { 11 | 12 | public Product saveProduct(Product product); 13 | 14 | public List getAllProducts(); 15 | 16 | public Boolean deleteProduct(Integer id); 17 | 18 | public Product getProductById(Integer id); 19 | 20 | public Product updateProduct(Product product, MultipartFile file); 21 | 22 | public List getAllActiveProducts(String category); 23 | 24 | public List searchProduct(String ch); 25 | 26 | public Page getAllActiveProductPagination(Integer pageNo, Integer pageSize, String category); 27 | 28 | public Page searchProductPagination(Integer pageNo, Integer pageSize, String ch); 29 | 30 | public Page getAllProductsPagination(Integer pageNo, Integer pageSize); 31 | 32 | public Page searchActiveProductPagination(Integer pageNo, Integer pageSize, String category, String ch); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import com.ecom.model.UserDtls; 8 | 9 | public interface UserService { 10 | 11 | public UserDtls saveUser(UserDtls user); 12 | 13 | public UserDtls getUserByEmail(String email); 14 | 15 | public List getUsers(String role); 16 | 17 | public Boolean updateAccountStatus(Integer id, Boolean status); 18 | 19 | public void increaseFailedAttempt(UserDtls user); 20 | 21 | public void userAccountLock(UserDtls user); 22 | 23 | public boolean unlockAccountTimeExpired(UserDtls user); 24 | 25 | public void resetAttempt(int userId); 26 | 27 | public void updateUserResetToken(String email, String resetToken); 28 | 29 | public UserDtls getUserByToken(String token); 30 | 31 | public UserDtls updateUser(UserDtls user); 32 | 33 | public UserDtls updateUserProfile(UserDtls user, MultipartFile img); 34 | 35 | public UserDtls saveAdmin(UserDtls user); 36 | 37 | public Boolean existsEmail(String email); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/impl/CartServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.util.ObjectUtils; 9 | 10 | import com.ecom.model.Cart; 11 | import com.ecom.model.Product; 12 | import com.ecom.model.UserDtls; 13 | import com.ecom.repository.CartRepository; 14 | import com.ecom.repository.ProductRepository; 15 | import com.ecom.repository.UserRepository; 16 | import com.ecom.service.CartService; 17 | 18 | @Service 19 | public class CartServiceImpl implements CartService { 20 | 21 | @Autowired 22 | private CartRepository cartRepository; 23 | 24 | @Autowired 25 | private UserRepository userRepository; 26 | 27 | @Autowired 28 | private ProductRepository productRepository; 29 | 30 | @Override 31 | public Cart saveCart(Integer productId, Integer userId) { 32 | 33 | UserDtls userDtls = userRepository.findById(userId).get(); 34 | Product product = productRepository.findById(productId).get(); 35 | 36 | Cart cartStatus = cartRepository.findByProductIdAndUserId(productId, userId); 37 | 38 | Cart cart = null; 39 | 40 | if (ObjectUtils.isEmpty(cartStatus)) { 41 | cart = new Cart(); 42 | cart.setProduct(product); 43 | cart.setUser(userDtls); 44 | cart.setQuantity(1); 45 | cart.setTotalPrice(1 * product.getDiscountPrice()); 46 | } else { 47 | cart = cartStatus; 48 | cart.setQuantity(cart.getQuantity() + 1); 49 | cart.setTotalPrice(cart.getQuantity() * cart.getProduct().getDiscountPrice()); 50 | } 51 | Cart saveCart = cartRepository.save(cart); 52 | 53 | return saveCart; 54 | } 55 | 56 | @Override 57 | public List getCartsByUser(Integer userId) { 58 | List carts = cartRepository.findByUserId(userId); 59 | 60 | Double totalOrderPrice = 0.0; 61 | List updateCarts = new ArrayList<>(); 62 | for (Cart c : carts) { 63 | Double totalPrice = (c.getProduct().getDiscountPrice() * c.getQuantity()); 64 | c.setTotalPrice(totalPrice); 65 | totalOrderPrice = totalOrderPrice + totalPrice; 66 | c.setTotalOrderPrice(totalOrderPrice); 67 | updateCarts.add(c); 68 | } 69 | 70 | return updateCarts; 71 | } 72 | 73 | @Override 74 | public Integer getCountCart(Integer userId) { 75 | Integer countByUserId = cartRepository.countByUserId(userId); 76 | return countByUserId; 77 | } 78 | 79 | @Override 80 | public void updateQuantity(String sy, Integer cid) { 81 | 82 | Cart cart = cartRepository.findById(cid).get(); 83 | int updateQuantity; 84 | 85 | if (sy.equalsIgnoreCase("de")) { 86 | updateQuantity = cart.getQuantity() - 1; 87 | 88 | if (updateQuantity <= 0) { 89 | cartRepository.delete(cart); 90 | } else { 91 | cart.setQuantity(updateQuantity); 92 | cartRepository.save(cart); 93 | } 94 | 95 | } else { 96 | updateQuantity = cart.getQuantity() + 1; 97 | cart.setQuantity(updateQuantity); 98 | cartRepository.save(cart); 99 | } 100 | 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/impl/CategoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.PageRequest; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.util.ObjectUtils; 11 | 12 | import com.ecom.model.Category; 13 | import com.ecom.repository.CategoryRepository; 14 | import com.ecom.service.CategoryService; 15 | 16 | @Service 17 | public class CategoryServiceImpl implements CategoryService { 18 | 19 | @Autowired 20 | private CategoryRepository categoryRepository; 21 | 22 | @Override 23 | public Category saveCategory(Category category) { 24 | return categoryRepository.save(category); 25 | } 26 | 27 | @Override 28 | public List getAllCategory() { 29 | return categoryRepository.findAll(); 30 | } 31 | 32 | @Override 33 | public Boolean existCategory(String name) { 34 | return categoryRepository.existsByName(name); 35 | } 36 | 37 | @Override 38 | public Boolean deleteCategory(int id) { 39 | Category category = categoryRepository.findById(id).orElse(null); 40 | 41 | if (!ObjectUtils.isEmpty(category)) { 42 | categoryRepository.delete(category); 43 | return true; 44 | } 45 | return false; 46 | } 47 | 48 | @Override 49 | public Category getCategoryById(int id) { 50 | Category category = categoryRepository.findById(id).orElse(null); 51 | return category; 52 | } 53 | 54 | @Override 55 | public List getAllActiveCategory() { 56 | List categories = categoryRepository.findByIsActiveTrue(); 57 | return categories; 58 | } 59 | 60 | @Override 61 | public Page getAllCategorPagination(Integer pageNo, Integer pageSize) { 62 | Pageable pageable = PageRequest.of(pageNo, pageSize); 63 | return categoryRepository.findAll(pageable); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service.impl; 2 | 3 | import java.time.LocalDate; 4 | import java.util.Date; 5 | import java.util.List; 6 | import java.util.Optional; 7 | import java.util.UUID; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.data.domain.Page; 11 | import org.springframework.data.domain.PageRequest; 12 | import org.springframework.data.domain.Pageable; 13 | import org.springframework.stereotype.Service; 14 | 15 | import com.ecom.model.Cart; 16 | import com.ecom.model.OrderAddress; 17 | import com.ecom.model.OrderRequest; 18 | import com.ecom.model.ProductOrder; 19 | import com.ecom.model.UserDtls; 20 | import com.ecom.repository.CartRepository; 21 | import com.ecom.repository.ProductOrderRepository; 22 | import com.ecom.service.OrderService; 23 | import com.ecom.util.CommonUtil; 24 | import com.ecom.util.OrderStatus; 25 | 26 | @Service 27 | public class OrderServiceImpl implements OrderService { 28 | 29 | @Autowired 30 | private ProductOrderRepository orderRepository; 31 | 32 | @Autowired 33 | private CartRepository cartRepository; 34 | 35 | @Autowired 36 | private CommonUtil commonUtil; 37 | 38 | @Override 39 | public void saveOrder(Integer userid, OrderRequest orderRequest) throws Exception { 40 | 41 | List carts = cartRepository.findByUserId(userid); 42 | 43 | for (Cart cart : carts) { 44 | 45 | ProductOrder order = new ProductOrder(); 46 | 47 | order.setOrderId(UUID.randomUUID().toString()); 48 | order.setOrderDate(LocalDate.now()); 49 | 50 | order.setProduct(cart.getProduct()); 51 | order.setPrice(cart.getProduct().getDiscountPrice()); 52 | 53 | order.setQuantity(cart.getQuantity()); 54 | order.setUser(cart.getUser()); 55 | 56 | order.setStatus(OrderStatus.IN_PROGRESS.getName()); 57 | order.setPaymentType(orderRequest.getPaymentType()); 58 | 59 | OrderAddress address = new OrderAddress(); 60 | address.setFirstName(orderRequest.getFirstName()); 61 | address.setLastName(orderRequest.getLastName()); 62 | address.setEmail(orderRequest.getEmail()); 63 | address.setMobileNo(orderRequest.getMobileNo()); 64 | address.setAddress(orderRequest.getAddress()); 65 | address.setCity(orderRequest.getCity()); 66 | address.setState(orderRequest.getState()); 67 | address.setPincode(orderRequest.getPincode()); 68 | 69 | order.setOrderAddress(address); 70 | 71 | ProductOrder saveOrder = orderRepository.save(order); 72 | resetCart(cart.getUser()); 73 | commonUtil.sendMailForProductOrder(saveOrder, "success"); 74 | } 75 | } 76 | private void resetCart(UserDtls user) { 77 | cartRepository.deleteByUser(user); 78 | } 79 | @Override 80 | public List getOrdersByUser(Integer userId) { 81 | List orders = orderRepository.findByUserId(userId); 82 | return orders; 83 | } 84 | 85 | @Override 86 | public ProductOrder updateOrderStatus(Integer id, String status) { 87 | Optional findById = orderRepository.findById(id); 88 | if (findById.isPresent()) { 89 | ProductOrder productOrder = findById.get(); 90 | productOrder.setStatus(status); 91 | ProductOrder updateOrder = orderRepository.save(productOrder); 92 | return updateOrder; 93 | } 94 | return null; 95 | } 96 | 97 | @Override 98 | public List getAllOrders() { 99 | return orderRepository.findAll(); 100 | } 101 | 102 | @Override 103 | public Page getAllOrdersPagination(Integer pageNo, Integer pageSize) { 104 | Pageable pageable = PageRequest.of(pageNo, pageSize); 105 | return orderRepository.findAll(pageable); 106 | 107 | } 108 | 109 | @Override 110 | public ProductOrder getOrdersByOrderId(String orderId) { 111 | return orderRepository.findByOrderId(orderId); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/impl/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service.impl; 2 | 3 | import java.io.File; 4 | import java.nio.file.Files; 5 | import java.nio.file.Path; 6 | import java.nio.file.Paths; 7 | import java.nio.file.StandardCopyOption; 8 | import java.util.List; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.core.io.ClassPathResource; 12 | import org.springframework.data.domain.Page; 13 | import org.springframework.data.domain.PageRequest; 14 | import org.springframework.data.domain.Pageable; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.util.ObjectUtils; 17 | import org.springframework.web.multipart.MultipartFile; 18 | 19 | import com.ecom.model.Product; 20 | import com.ecom.repository.ProductRepository; 21 | import com.ecom.service.ProductService; 22 | 23 | @Service 24 | public class ProductServiceImpl implements ProductService { 25 | 26 | @Autowired 27 | private ProductRepository productRepository; 28 | 29 | @Override 30 | public Product saveProduct(Product product) { 31 | return productRepository.save(product); 32 | } 33 | 34 | @Override 35 | public List getAllProducts() { 36 | return productRepository.findAll(); 37 | } 38 | 39 | @Override 40 | public Page getAllProductsPagination(Integer pageNo, Integer pageSize) { 41 | Pageable pageable = PageRequest.of(pageNo, pageSize); 42 | return productRepository.findAll(pageable); 43 | } 44 | 45 | @Override 46 | public Boolean deleteProduct(Integer id) { 47 | Product product = productRepository.findById(id).orElse(null); 48 | 49 | if (!ObjectUtils.isEmpty(product)) { 50 | productRepository.delete(product); 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | @Override 57 | public Product getProductById(Integer id) { 58 | Product product = productRepository.findById(id).orElse(null); 59 | return product; 60 | } 61 | 62 | @Override 63 | public Product updateProduct(Product product, MultipartFile image) { 64 | 65 | Product dbProduct = getProductById(product.getId()); 66 | 67 | String imageName = image.isEmpty() ? dbProduct.getImage() : image.getOriginalFilename(); 68 | 69 | dbProduct.setTitle(product.getTitle()); 70 | dbProduct.setDescription(product.getDescription()); 71 | dbProduct.setCategory(product.getCategory()); 72 | dbProduct.setPrice(product.getPrice()); 73 | dbProduct.setStock(product.getStock()); 74 | dbProduct.setImage(imageName); 75 | dbProduct.setIsActive(product.getIsActive()); 76 | dbProduct.setDiscount(product.getDiscount()); 77 | 78 | // 5=100*(5/100); 100-5=95 79 | Double disocunt = product.getPrice() * (product.getDiscount() / 100.0); 80 | Double discountPrice = product.getPrice() - disocunt; 81 | dbProduct.setDiscountPrice(discountPrice); 82 | 83 | Product updateProduct = productRepository.save(dbProduct); 84 | 85 | if (!ObjectUtils.isEmpty(updateProduct)) { 86 | 87 | if (!image.isEmpty()) { 88 | 89 | try { 90 | File saveFile = new ClassPathResource("static/img").getFile(); 91 | 92 | Path path = Paths.get(saveFile.getAbsolutePath() + File.separator + "product_img" + File.separator 93 | + image.getOriginalFilename()); 94 | Files.copy(image.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); 95 | 96 | } catch (Exception e) { 97 | e.printStackTrace(); 98 | } 99 | } 100 | return product; 101 | } 102 | return null; 103 | } 104 | 105 | @Override 106 | public List getAllActiveProducts(String category) { 107 | List products = null; 108 | if (ObjectUtils.isEmpty(category)) { 109 | products = productRepository.findByIsActiveTrue(); 110 | } else { 111 | products = productRepository.findByCategory(category); 112 | } 113 | 114 | return products; 115 | } 116 | 117 | @Override 118 | public List searchProduct(String ch) { 119 | return productRepository.findByTitleContainingIgnoreCaseOrCategoryContainingIgnoreCase(ch, ch); 120 | } 121 | 122 | @Override 123 | public Page searchProductPagination(Integer pageNo, Integer pageSize, String ch) { 124 | Pageable pageable = PageRequest.of(pageNo, pageSize); 125 | return productRepository.findByTitleContainingIgnoreCaseOrCategoryContainingIgnoreCase(ch, ch, pageable); 126 | } 127 | 128 | @Override 129 | public Page getAllActiveProductPagination(Integer pageNo, Integer pageSize, String category) { 130 | 131 | Pageable pageable = PageRequest.of(pageNo, pageSize); 132 | Page pageProduct = null; 133 | 134 | if (ObjectUtils.isEmpty(category)) { 135 | pageProduct = productRepository.findByIsActiveTrue(pageable); 136 | } else { 137 | pageProduct = productRepository.findByCategory(pageable, category); 138 | } 139 | return pageProduct; 140 | } 141 | 142 | @Override 143 | public Page searchActiveProductPagination(Integer pageNo, Integer pageSize, String category, String ch) { 144 | 145 | Page pageProduct = null; 146 | Pageable pageable = PageRequest.of(pageNo, pageSize); 147 | 148 | pageProduct = productRepository.findByisActiveTrueAndTitleContainingIgnoreCaseOrCategoryContainingIgnoreCase(ch, 149 | ch, pageable); 150 | 151 | // if (ObjectUtils.isEmpty(category)) { 152 | // pageProduct = productRepository.findByIsActiveTrue(pageable); 153 | // } else { 154 | // pageProduct = productRepository.findByCategory(pageable, category); 155 | // } 156 | return pageProduct; 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecom.service.impl; 2 | 3 | import java.io.File; 4 | import java.nio.file.Files; 5 | import java.nio.file.Path; 6 | import java.nio.file.Paths; 7 | import java.nio.file.StandardCopyOption; 8 | import java.util.Date; 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.core.io.ClassPathResource; 14 | import org.springframework.security.crypto.password.PasswordEncoder; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.util.ObjectUtils; 17 | import org.springframework.web.multipart.MultipartFile; 18 | 19 | import com.ecom.model.UserDtls; 20 | import com.ecom.repository.UserRepository; 21 | import com.ecom.service.UserService; 22 | import com.ecom.util.AppConstant; 23 | 24 | @Service 25 | public class UserServiceImpl implements UserService { 26 | 27 | @Autowired 28 | private UserRepository userRepository; 29 | 30 | @Autowired 31 | private PasswordEncoder passwordEncoder; 32 | 33 | @Override 34 | public UserDtls saveUser(UserDtls user) { 35 | user.setRole("ROLE_USER"); 36 | user.setIsEnable(true); 37 | user.setAccountNonLocked(true); 38 | user.setFailedAttempt(0); 39 | 40 | String encodePassword = passwordEncoder.encode(user.getPassword()); 41 | user.setPassword(encodePassword); 42 | UserDtls saveUser = userRepository.save(user); 43 | return saveUser; 44 | } 45 | 46 | @Override 47 | public UserDtls getUserByEmail(String email) { 48 | return userRepository.findByEmail(email); 49 | } 50 | 51 | @Override 52 | public List getUsers(String role) { 53 | return userRepository.findByRole(role); 54 | } 55 | 56 | @Override 57 | public Boolean updateAccountStatus(Integer id, Boolean status) { 58 | 59 | Optional findByuser = userRepository.findById(id); 60 | 61 | if (findByuser.isPresent()) { 62 | UserDtls userDtls = findByuser.get(); 63 | userDtls.setIsEnable(status); 64 | userRepository.save(userDtls); 65 | return true; 66 | } 67 | 68 | return false; 69 | } 70 | 71 | @Override 72 | public void increaseFailedAttempt(UserDtls user) { 73 | int attempt = user.getFailedAttempt() + 1; 74 | user.setFailedAttempt(attempt); 75 | userRepository.save(user); 76 | } 77 | 78 | @Override 79 | public void userAccountLock(UserDtls user) { 80 | user.setAccountNonLocked(false); 81 | user.setLockTime(new Date()); 82 | userRepository.save(user); 83 | } 84 | 85 | @Override 86 | public boolean unlockAccountTimeExpired(UserDtls user) { 87 | 88 | long lockTime = user.getLockTime().getTime(); 89 | long unLockTime = lockTime + AppConstant.UNLOCK_DURATION_TIME; 90 | 91 | long currentTime = System.currentTimeMillis(); 92 | 93 | if (unLockTime < currentTime) { 94 | user.setAccountNonLocked(true); 95 | user.setFailedAttempt(0); 96 | user.setLockTime(null); 97 | userRepository.save(user); 98 | return true; 99 | } 100 | 101 | return false; 102 | } 103 | 104 | @Override 105 | public void resetAttempt(int userId) { 106 | 107 | } 108 | 109 | @Override 110 | public void updateUserResetToken(String email, String resetToken) { 111 | UserDtls findByEmail = userRepository.findByEmail(email); 112 | findByEmail.setResetToken(resetToken); 113 | userRepository.save(findByEmail); 114 | } 115 | 116 | @Override 117 | public UserDtls getUserByToken(String token) { 118 | return userRepository.findByResetToken(token); 119 | } 120 | 121 | @Override 122 | public UserDtls updateUser(UserDtls user) { 123 | return userRepository.save(user); 124 | } 125 | 126 | @Override 127 | public UserDtls updateUserProfile(UserDtls user, MultipartFile img) { 128 | 129 | UserDtls dbUser = userRepository.findById(user.getId()).get(); 130 | 131 | if (!img.isEmpty()) { 132 | dbUser.setProfileImage(img.getOriginalFilename()); 133 | } 134 | 135 | if (!ObjectUtils.isEmpty(dbUser)) { 136 | 137 | dbUser.setName(user.getName()); 138 | dbUser.setMobileNumber(user.getMobileNumber()); 139 | dbUser.setAddress(user.getAddress()); 140 | dbUser.setCity(user.getCity()); 141 | dbUser.setState(user.getState()); 142 | dbUser.setPincode(user.getPincode()); 143 | dbUser = userRepository.save(dbUser); 144 | } 145 | 146 | try { 147 | if (!img.isEmpty()) { 148 | File saveFile = new ClassPathResource("static/img").getFile(); 149 | 150 | Path path = Paths.get(saveFile.getAbsolutePath() + File.separator + "profile_img" + File.separator 151 | + img.getOriginalFilename()); 152 | 153 | // System.out.println(path); 154 | Files.copy(img.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); 155 | } 156 | } catch (Exception e) { 157 | e.printStackTrace(); 158 | } 159 | 160 | return dbUser; 161 | } 162 | 163 | @Override 164 | public UserDtls saveAdmin(UserDtls user) { 165 | user.setRole("ROLE_ADMIN"); 166 | user.setIsEnable(true); 167 | user.setAccountNonLocked(true); 168 | user.setFailedAttempt(0); 169 | 170 | String encodePassword = passwordEncoder.encode(user.getPassword()); 171 | user.setPassword(encodePassword); 172 | UserDtls saveUser = userRepository.save(user); 173 | return saveUser; 174 | } 175 | 176 | @Override 177 | public Boolean existsEmail(String email) { 178 | return userRepository.existsByEmail(email); 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/util/AppConstant.java: -------------------------------------------------------------------------------- 1 | package com.ecom.util; 2 | 3 | public class AppConstant { 4 | 5 | public static final long UNLOCK_DURATION_TIME = 3000; 6 | //1 * 60 * 60 * 1000; 7 | 8 | public static final long ATTEMPT_TIME = 3; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/util/CommonUtil.java: -------------------------------------------------------------------------------- 1 | package com.ecom.util; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.security.Principal; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.mail.javamail.JavaMailSender; 8 | import org.springframework.mail.javamail.MimeMessageHelper; 9 | import org.springframework.stereotype.Component; 10 | 11 | import com.ecom.model.ProductOrder; 12 | import com.ecom.model.UserDtls; 13 | import com.ecom.service.UserService; 14 | 15 | import jakarta.mail.MessagingException; 16 | import jakarta.mail.internet.MimeMessage; 17 | import jakarta.servlet.http.HttpServletRequest; 18 | 19 | @Component 20 | public class CommonUtil { 21 | 22 | @Autowired 23 | private JavaMailSender mailSender; 24 | 25 | @Autowired 26 | private UserService userService; 27 | 28 | public Boolean sendMail(String url, String reciepentEmail) throws UnsupportedEncodingException, MessagingException { 29 | 30 | MimeMessage message = mailSender.createMimeMessage(); 31 | MimeMessageHelper helper = new MimeMessageHelper(message); 32 | 33 | helper.setFrom("daspabitra55@gmail.com", "Shooping Cart"); 34 | helper.setTo(reciepentEmail); 35 | 36 | String content = "

Hello,

" + "

You have requested to reset your password.

" 37 | + "

Click the link below to change your password:

" + "

Change my password

"; 39 | helper.setSubject("Password Reset"); 40 | helper.setText(content, true); 41 | mailSender.send(message); 42 | return true; 43 | } 44 | 45 | public static String generateUrl(HttpServletRequest request) { 46 | 47 | // http://localhost:8080/forgot-password 48 | String siteUrl = request.getRequestURL().toString(); 49 | 50 | return siteUrl.replace(request.getServletPath(), ""); 51 | } 52 | 53 | String msg=null;; 54 | 55 | public Boolean sendMailForProductOrder(ProductOrder order,String status) throws Exception 56 | { 57 | 58 | msg="

Hello [[name]],

" 59 | + "

Thank you order [[orderStatus]].

" 60 | + "

Product Details:

" 61 | + "

Name : [[productName]]

" 62 | + "

Category : [[category]]

" 63 | + "

Quantity : [[quantity]]

" 64 | + "

Price : [[price]]

" 65 | + "

Payment Type : [[paymentType]]

"; 66 | 67 | MimeMessage message = mailSender.createMimeMessage(); 68 | MimeMessageHelper helper = new MimeMessageHelper(message); 69 | 70 | helper.setFrom("daspabitra55@gmail.com", "Shooping Cart"); 71 | helper.setTo(order.getOrderAddress().getEmail()); 72 | 73 | msg=msg.replace("[[name]]",order.getOrderAddress().getFirstName()); 74 | msg=msg.replace("[[orderStatus]]",status); 75 | msg=msg.replace("[[productName]]", order.getProduct().getTitle()); 76 | msg=msg.replace("[[category]]", order.getProduct().getCategory()); 77 | msg=msg.replace("[[quantity]]", order.getQuantity().toString()); 78 | msg=msg.replace("[[price]]", order.getPrice().toString()); 79 | msg=msg.replace("[[paymentType]]", order.getPaymentType()); 80 | 81 | helper.setSubject("Product Order Status"); 82 | helper.setText(msg, true); 83 | mailSender.send(message); 84 | return true; 85 | } 86 | 87 | public UserDtls getLoggedInUserDetails(Principal p) { 88 | String email = p.getName(); 89 | UserDtls userDtls = userService.getUserByEmail(email); 90 | return userDtls; 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/ecom/util/OrderStatus.java: -------------------------------------------------------------------------------- 1 | package com.ecom.util; 2 | 3 | public enum OrderStatus { 4 | 5 | IN_PROGRESS(1, "In Progress"), ORDER_RECEIVED(2, "Order Received"), PRODUCT_PACKED(3, "Product Packed"), 6 | OUT_FOR_DELIVERY(4, "Out for Delivery"), DELIVERED(5, "Delivered"),CANCEL(6,"Cancelled"),SUCCESS(7,"Success"); 7 | 8 | private Integer id; 9 | 10 | private String name; 11 | 12 | private OrderStatus(Integer id, String name) { 13 | this.id = id; 14 | this.name = name; 15 | } 16 | 17 | public Integer getId() { 18 | return id; 19 | } 20 | 21 | public void setId(Integer id) { 22 | this.id = id; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce_db 2 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 3 | spring.datasource.username=root 4 | spring.datasource.password=root 5 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect 6 | spring.jpa.hibernate.ddl-auto=update 7 | 8 | #spring.main.allow-circular-references=true 9 | 10 | spring.mail.host=smtp.gmail.com 11 | spring.mail.username=yourmail@gmail.com 12 | spring.mail.password=*********** 13 | spring.mail.port=587 14 | spring.mail.properties.mail.smtp.auth=true 15 | spring.mail.properties.mail.smtp.starttls.enable=true 16 | 17 | spring.servlet.multipart.max-file-size=50MB 18 | spring.servlet.multipart.max-request-size=50MB 19 | 20 | rupee.sign=${RUPEE_SIGN:€} 21 | -------------------------------------------------------------------------------- /src/main/resources/static/css/style.css: -------------------------------------------------------------------------------- 1 | @charset "ISO-8859-1"; 2 | 3 | .card-sh { 4 | box-shadow: 0 0 3px 0 rgba(0, 0, 0, 0.3); 5 | } 6 | 7 | .cat-div { 8 | box-shadow: 0 0 10px rgba(0, 0, 0, .1); 9 | } 10 | 11 | .error { 12 | color: red; 13 | } -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/appli.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/appli.png -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/beuty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/beuty.png -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/blue shirt.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/blue shirt.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/book.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/book.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/canvas.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/canvas.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/groccery.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/groccery.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/laptop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/laptop.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/mobile.png -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/monitor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/monitor.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/category_img/pant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/category_img/pant.png -------------------------------------------------------------------------------- /src/main/resources/static/img/ecom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/ecom.png -------------------------------------------------------------------------------- /src/main/resources/static/img/ecom1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/ecom1.png -------------------------------------------------------------------------------- /src/main/resources/static/img/ecom2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/ecom2.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/ecom3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/ecom3.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/blue shirt.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/blue shirt.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/canvas.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/canvas.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/cross.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/cross.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/fridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/fridge.png -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/grinder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/grinder.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/hp laptop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/hp laptop.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/iphone 14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/iphone 14.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/jeans blue.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/jeans blue.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/kruti.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/kruti.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/laptop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/laptop.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/lehenga.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/lehenga.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/lofer.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/lofer.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/mobile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/mobile.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/monitor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/monitor.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/official shoe.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/official shoe.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/oneplus mobile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/oneplus mobile.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/printed short.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/printed short.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/washing_machine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/washing_machine.png -------------------------------------------------------------------------------- /src/main/resources/static/img/product_img/white shoe.jfif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/product_img/white shoe.jfif -------------------------------------------------------------------------------- /src/main/resources/static/img/profile_img/ecom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/profile_img/ecom.png -------------------------------------------------------------------------------- /src/main/resources/static/img/profile_img/img.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/becoderpavy/shopping-cart-spring-boot/2c0f0c3bbafc3dd92e9e01f56beeadf5c162046b/src/main/resources/static/img/profile_img/img.txt -------------------------------------------------------------------------------- /src/main/resources/static/js/script.js: -------------------------------------------------------------------------------- 1 | $(function(){ 2 | 3 | // User Register validation 4 | 5 | var $userRegister=$("#userRegister"); 6 | 7 | $userRegister.validate({ 8 | 9 | rules:{ 10 | name:{ 11 | required:true, 12 | lettersonly:true 13 | } 14 | , 15 | email: { 16 | required: true, 17 | space: true, 18 | email: true 19 | }, 20 | mobileNumber: { 21 | required: true, 22 | space: true, 23 | numericOnly: true, 24 | minlength: 10, 25 | maxlength: 12 26 | 27 | }, 28 | password: { 29 | required: true, 30 | space: true 31 | 32 | }, 33 | confirmpassword: { 34 | required: true, 35 | space: true, 36 | equalTo: '#pass' 37 | 38 | }, 39 | address: { 40 | required: true, 41 | all: true 42 | 43 | }, 44 | 45 | city: { 46 | required: true, 47 | space: true 48 | 49 | }, 50 | state: { 51 | required: true, 52 | 53 | 54 | }, 55 | pincode: { 56 | required: true, 57 | space: true, 58 | numericOnly: true 59 | 60 | }, img: { 61 | required: true, 62 | } 63 | 64 | }, 65 | messages:{ 66 | name:{ 67 | required:'name required', 68 | lettersonly:'invalid name' 69 | }, 70 | email: { 71 | required: 'email name must be required', 72 | space: 'space not allowed', 73 | email: 'Invalid email' 74 | }, 75 | mobileNumber: { 76 | required: 'mob no must be required', 77 | space: 'space not allowed', 78 | numericOnly: 'invalid mob no', 79 | minlength: 'min 10 digit', 80 | maxlength: 'max 12 digit' 81 | }, 82 | 83 | password: { 84 | required: 'password must be required', 85 | space: 'space not allowed' 86 | 87 | }, 88 | confirmpassword: { 89 | required: 'confirm password must be required', 90 | space: 'space not allowed', 91 | equalTo: 'password mismatch' 92 | 93 | }, 94 | address: { 95 | required: 'address must be required', 96 | all: 'invalid' 97 | 98 | }, 99 | 100 | city: { 101 | required: 'city must be required', 102 | space: 'space not allowed' 103 | 104 | }, 105 | state: { 106 | required: 'state must be required', 107 | space: 'space not allowed' 108 | 109 | }, 110 | pincode: { 111 | required: 'pincode must be required', 112 | space: 'space not allowed', 113 | numericOnly: 'invalid pincode' 114 | 115 | }, 116 | img: { 117 | required: 'image required', 118 | } 119 | } 120 | }) 121 | 122 | 123 | // Orders Validation 124 | 125 | var $orders=$("#orders"); 126 | 127 | $orders.validate({ 128 | rules:{ 129 | firstName:{ 130 | required:true, 131 | lettersonly:true 132 | }, 133 | lastName:{ 134 | required:true, 135 | lettersonly:true 136 | } 137 | , 138 | email: { 139 | required: true, 140 | space: true, 141 | email: true 142 | }, 143 | mobileNo: { 144 | required: true, 145 | space: true, 146 | numericOnly: true, 147 | minlength: 10, 148 | maxlength: 12 149 | 150 | }, 151 | address: { 152 | required: true, 153 | all: true 154 | 155 | }, 156 | 157 | city: { 158 | required: true, 159 | all: true 160 | }, 161 | state: { 162 | required: true, 163 | all: true 164 | }, 165 | pincode: { 166 | required: true, 167 | space: true, 168 | numericOnly: true 169 | }, 170 | paymentType:{ 171 | required: true 172 | } 173 | }, 174 | messages:{ 175 | firstName:{ 176 | required:'first required', 177 | lettersonly:'invalid name' 178 | }, 179 | lastName:{ 180 | required:'last name required', 181 | lettersonly:'invalid name' 182 | }, 183 | email: { 184 | required: 'email name must be required', 185 | space: 'space not allowed', 186 | email: 'Invalid email' 187 | }, 188 | mobileNo: { 189 | required: 'mob no must be required', 190 | space: 'space not allowed', 191 | numericOnly: 'invalid mob no', 192 | minlength: 'min 10 digit', 193 | maxlength: 'max 12 digit' 194 | } 195 | , 196 | address: { 197 | required: 'address must be required', 198 | all: 'invalid' 199 | }, 200 | 201 | city: { 202 | required: 'city must be required', 203 | all: 'invalid' 204 | }, 205 | state: { 206 | required: 'state must be required', 207 | all: 'invalid' 208 | }, 209 | pincode: { 210 | required: 'pincode must be required', 211 | space: 'space not allowed', 212 | numericOnly: 'invalid pincode' 213 | }, 214 | paymentType:{ 215 | required: 'select payment type' 216 | } 217 | } 218 | }) 219 | 220 | // Reset Password Validation 221 | 222 | var $resetPassword=$("#resetPassword"); 223 | 224 | $resetPassword.validate({ 225 | 226 | rules:{ 227 | password: { 228 | required: true, 229 | space: true 230 | 231 | }, 232 | confirmPassword: { 233 | required: true, 234 | space: true, 235 | equalTo: '#pass' 236 | 237 | } 238 | }, 239 | messages:{ 240 | password: { 241 | required: 'password must be required', 242 | space: 'space not allowed' 243 | 244 | }, 245 | confirmpassword: { 246 | required: 'confirm password must be required', 247 | space: 'space not allowed', 248 | equalTo: 'password mismatch' 249 | 250 | } 251 | } 252 | }) 253 | }) 254 | 255 | 256 | 257 | jQuery.validator.addMethod('lettersonly', function(value, element) { 258 | return /^[^-\s][a-zA-Z_\s-]+$/.test(value); 259 | }); 260 | 261 | jQuery.validator.addMethod('space', function(value, element) { 262 | return /^[^-\s]+$/.test(value); 263 | }); 264 | 265 | jQuery.validator.addMethod('all', function(value, element) { 266 | return /^[^-\s][a-zA-Z0-9_,.\s-]+$/.test(value); 267 | }); 268 | 269 | 270 | jQuery.validator.addMethod('numericOnly', function(value, element) { 271 | return /^[0-9]+$/.test(value); 272 | }); 273 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/add_admin.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 |

Add Admin

17 | 18 |

[[${session.succMsg}]]

19 | 20 |
21 | 22 | 23 |

[[${session.errorMsg}]]

24 | 25 |
26 |
27 |
28 |
30 |
31 |
32 | 34 |
35 | 36 |
37 | 40 |
41 | 42 |
43 | 44 |
45 | 47 |
48 | 49 | 50 |
51 |
52 | 54 |
55 | 56 |
57 | 59 |
60 | 61 |
62 | 63 |
64 |
65 | 67 |
68 | 69 |
70 | 72 |
73 | 74 |
75 | 76 |
77 |
78 | 80 |
81 |
82 | 85 |
86 |
87 |
88 | 90 |
91 | 93 |
94 |
95 | 96 | 97 |
98 |
99 |
100 |
101 | 102 |
103 | 104 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/add_product.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 |
14 |
15 |

Add Product

16 | 17 | 18 |

[[${session.succMsg}]]

19 | 20 |
21 | 22 | 23 |

[[${session.errorMsg}]]

24 | 25 |
26 | 27 |
28 |
29 |
31 |
32 | 34 |
35 | 36 |
37 | 38 | 40 |
41 | 42 |
43 | 48 |
49 | 50 |
51 | 53 |
54 |
55 | 56 | 57 |
58 | 60 | 62 |
63 |
64 | 68 |
69 | 70 |
71 |
72 | 73 |
74 | 76 |
77 | 78 |
79 | 81 |
82 |
83 | 84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 | 92 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/category.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 |
14 |
15 |

Add Category

16 | 17 |

[[${session.succMsg}]]

18 | 19 |
20 | 21 | 22 |

[[${session.errorMsg}]]

23 | 24 |
25 | 26 |
27 |
28 |
30 |
31 | 33 |
34 | 35 |
36 | 37 | 38 |
39 | 41 | 43 |
44 |
45 | 49 |
50 | 51 |
52 | 53 |
54 | 56 |
57 | 58 |
59 |
60 |
61 |
62 | 63 |
64 |
65 |
Category Details
66 |
67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 85 | 91 | 92 | 93 | 94 |
Sl NoCategoryStatusImageAction
[[${c.count}]][[${cat.name}]][[${cat.isActive}]] Edit Delete
95 | 96 |
97 |
Total Category : 98 | [[${totalElements}]]
99 |
100 | 101 | 124 |
125 | 126 |
127 |
128 |
129 | 130 |
131 | 132 |
133 |
134 |
135 | 136 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/edit_category.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 |
14 |
15 |

Edit Category

16 | 17 |

[[${session.succMsg}]]

18 | 19 |
20 | 21 | 22 |

[[${session.errorMsg}]]

23 | 24 |
25 | 26 |
27 |
28 |
30 | 31 |
32 | 34 |
35 | 36 |
37 | 38 | 39 |
40 | 45 |
46 |
47 | 52 |
53 | 54 |
55 | 56 |
57 | 59 |
60 | 62 | 63 |
64 |
65 |
66 |
67 | 68 | 69 | 70 |
71 |
72 |
73 | 74 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/edit_product.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 |
14 |
15 |

Edit Product

16 | 17 | 18 |

[[${session.succMsg}]]

19 | 20 |
21 | 22 | 23 |

[[${session.errorMsg}]]

24 | 25 |
26 | 27 |
28 |
29 |
31 | 32 |
33 | 35 |
36 | 37 |
38 | 39 | 41 |
42 |
43 |
44 | 49 |
50 |
51 | 53 |
54 |
55 | 56 |
57 |
58 | 60 |
61 |
62 | 64 |
65 |
66 | 67 |
68 | 69 | 70 |
71 | 73 | 75 |
76 |
77 | 81 |
82 | 83 |
84 | 85 |
86 | 87 |
88 | 90 |
91 | 92 |
93 | 95 |
96 | 97 |
98 | 100 |
101 | 102 |
103 | 104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | 112 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 | 98 |
99 | 100 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/orders.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |

All Orders

13 |
14 | Back 16 | 17 |

[[${session.succMsg}]]

18 | 19 |
20 | 21 | 22 |

[[${session.errorMsg}]]

23 | 24 |
25 |
26 | 27 |
28 |
29 |
30 | 32 |
33 |
34 | 35 |
36 |
37 |
38 | 39 |
40 |
41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 72 | 73 | 74 | 78 | 79 | 109 | 110 | 111 | 112 |

[[${errorMsg}]]

113 |
114 | 115 | 116 | 117 | 118 | 119 | 120 | 131 | 132 | 133 | 137 | 138 | 166 | 167 | 168 | 169 |
Order IdDeliver DetailsDateProduct DetailsPriceStatusAction
[[${orderDtls.orderId}]]Name : [[${orderDtls.orderAddress.firstName+' 61 | '+orderDtls.orderAddress.lastName}]]
Email : 62 | [[${orderDtls.orderAddress.email}]]
Mobno: 63 | [[${orderDtls.orderAddress.mobileNo}]]
Address : 64 | [[${orderDtls.orderAddress.address}]]
City : 65 | [[${orderDtls.orderAddress.city}]]
State : 66 | [[${orderDtls.orderAddress.state}]], 67 | [[${orderDtls.orderAddress.pincode}]] 68 | 69 | 70 | 71 |
[[${orderDtls.orderDate}]][[${orderDtls.product.title}]]Quantity : [[${orderDtls.quantity}]]
Price : 75 | [[${orderDtls.price}]]
Total Price 76 | :[[${orderDtls.quantity * orderDtls.price}]] 77 |
[[${orderDtls.status}]] 80 |
81 |
82 |
83 | 92 |
93 | 94 |
95 | 97 | 98 | 99 | 101 | 102 | 103 | 104 | 105 |
106 |
107 |
108 |
[[${o.orderId}]]Name : [[${o.orderAddress.firstName+' 121 | '+o.orderAddress.lastName}]]
Email : 122 | [[${o.orderAddress.email}]]
Mobno: 123 | [[${o.orderAddress.mobileNo}]]
Address : 124 | [[${o.orderAddress.address}]]
City : 125 | [[${o.orderAddress.city}]]
State : 126 | [[${o.orderAddress.state}]], [[${o.orderAddress.pincode}]] 127 | 128 | 129 | 130 |
[[${o.orderDate}]][[${o.product.title}]]Quantity : [[${o.quantity}]]
Price : 134 | [[${o.price}]]
Total Price :[[${o.quantity * 135 | o.price}]] 136 |
[[${o.status}]] 139 |
140 |
141 |
142 | 151 |
152 | 153 |
154 | 156 | 157 | 158 | 160 | 161 | 162 |
163 |
164 |
165 |
170 | 171 |
172 |
Total Orders : [[${totalElements}]]
173 |
174 | 175 | 197 |
198 | 199 |
200 |
201 |
202 |
203 | 204 |
205 |
206 | 207 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/products.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |

All Products

13 |
14 | Back 16 | 17 |

[[${session.succMsg}]]

18 | 19 |
20 | 21 | 22 |

[[${session.errorMsg}]]

23 | 24 |
25 | 26 | 27 |

[[${session.errorMsg}]]

28 | 29 |
30 |
31 | 32 |
33 |
34 |
35 | 36 |
37 |
38 | 39 |
40 |
41 |
42 | 43 |
44 | 45 | 46 | 47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 81 | 82 | 83 | 84 |
Sl NoImageTitleCategoryPriceDiscountDiscount PriceStatusStockAction
[[${c.count}]][[${p.title}]][[${p.category}]][[${p.price}]][[${p.discount}]][[${p.discountPrice}]][[${p.isActive}]][[${p.stock}]]Edit 80 | Delete
85 | 86 |
87 |
Total Product : [[${totalElements}]]
88 |
89 | 90 | 112 |
113 | 114 |
115 |
116 |
117 |
118 | 119 |
120 | 121 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/profile.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 | 14 |

My Profile

15 | 16 |

[[${session.succMsg}]]

17 | 18 |
19 | 20 | 21 |

[[${session.errorMsg}]]

22 | 23 |
24 |
25 |
26 | 29 |
30 |
31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 62 | 63 | 65 | 66 | 67 | 68 | 69 | 71 | 72 | 73 | 74 | 75 | 77 | 78 | 79 | 80 | 81 | 83 | 84 | 85 | 86 | 87 | 89 | 90 | 91 | 92 | 93 | 96 | 97 | 98 | 99 | 100 | 103 | 104 | 105 | 106 |
Name:
Mobile Number:
Email:
Address:
City:
State:
Pincode:
Image:
Role:
Account Status:
101 | 102 |
107 | 108 |
109 | 110 |
111 |
112 |
113 |
114 |

Change Password

115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 142 | 143 | 144 | 145 | 146 |
Current Password
New Password
Confirm Password
140 | 141 |
147 |
148 |
149 |
150 | 151 |
152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 |
161 | 162 | -------------------------------------------------------------------------------- /src/main/resources/templates/admin/users.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 | 12 |
13 |
14 |

Users

15 |

Admin

16 | 17 |

[[${session.succMsg}]]

18 | 19 |
20 | 21 | 22 |

[[${session.errorMsg}]]

23 | 24 |
25 |
26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 45 | 46 | 47 | 48 | 49 | 50 | 57 | 58 | 59 | 60 |
Sl NoProfileNameEmailMobile NoAddressStatusAction
[[${c.count}]][[${u.name}]][[${u.email}]][[${u.mobileNumber}]][[${u.address+','+u.city+','+u.state+','+u.pincode}]][[${u.isEnable}]]Active 52 | 53 | 56 | Inactive
61 |
62 |
63 |
64 | 65 |
66 | 67 | -------------------------------------------------------------------------------- /src/main/resources/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 113 | 114 | 115 |
116 | 117 | 118 |
120 |

ecom.com

121 |
122 | 123 | 124 | 125 | 127 | 129 | 130 | 131 | 132 | 136 | 137 | -------------------------------------------------------------------------------- /src/main/resources/templates/forgot_password.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 | 11 |
12 |
13 |
14 | 15 |
16 |
17 |
18 |
19 |

Forgot Password

20 | 21 | 22 |

[[${session.succMsg}]]

23 | 24 |
25 | 26 | 27 |

[[${session.errorMsg}]]

28 | 29 |
30 | 31 |
32 |
33 |
34 |
35 | 38 |
39 |
40 | 41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 49 |
50 | 51 | -------------------------------------------------------------------------------- /src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 | 11 | 12 | 38 | 39 | 40 | 41 | 42 |
43 |
44 |

Category

45 |
46 |
48 |
49 |
50 | [[${c.name}]] 51 |
52 |
53 |
54 | 55 | 64 | 65 | 66 | 76 | 85 | 86 | 87 | 96 | 97 | 107 | 108 | 109 |
110 |
111 | 112 | 113 | 114 | 115 | 116 |
117 |
118 |

Latest Product

119 | 120 |
121 |
122 |
123 | 125 |

[[${p.title}]]

126 |
127 |
128 |
129 | 130 | 131 | 160 | 161 |
162 |
163 | 164 | 165 | 166 |
167 | 168 | -------------------------------------------------------------------------------- /src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 | 14 |
15 |
16 |
17 |
18 |

Login

19 |
21 | 22 | 24 | [[${session.SPRING_SECURITY_LAST_EXCEPTION.message}]] 25 | 26 |
27 |
28 | Logout Success
29 |
30 |
31 |
32 |
33 | 35 |
36 | 37 |
38 | 40 |
41 | 43 |
44 |
45 | 46 | 51 |
52 |
53 |
54 |
55 | 56 |
57 | 58 | -------------------------------------------------------------------------------- /src/main/resources/templates/message.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 | 11 |
12 |
13 |
14 |

[[${msg}]]

15 |
16 | 17 |
18 |
19 | 20 |
21 | 22 | -------------------------------------------------------------------------------- /src/main/resources/templates/product.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 | 11 |
12 |
13 |
14 |
15 |
16 | 17 | 20 |
21 |
22 |
23 |
24 | 25 |
26 | 27 | 28 |
29 |
30 | 31 |
32 | 33 |
34 |
35 |
36 |

Category

37 | All [[${c.name}]] 44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |

Products

52 |
53 | 54 | 55 |
56 |
57 |
58 | 60 |

[[${p.title}]]

61 |
62 |

63 | [[${p.discountPrice}]]
65 | [[${p.price}]] [[${p.discount}]]% 66 | off 67 |

68 | View 70 | Details 71 |
72 |
73 |
74 |
75 |
76 | 77 |

Product not 78 | available

79 |
80 |
81 | 82 |
83 |
84 | 85 |
86 |
Total Products : [[${totalElements}]]
87 |
88 | 89 | 111 |
112 | 113 |
114 | 115 |
116 |
117 |
118 | 119 |
120 | 121 | -------------------------------------------------------------------------------- /src/main/resources/templates/register.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 | 14 |
15 |
16 |
17 |
18 |

Register

19 | 20 |

[[${session.succMsg}]]

21 | 22 |
23 | 24 | 25 |

[[${session.errorMsg}]]

26 | 27 |
28 |
29 |
30 |
32 |
33 |
34 | 36 |
37 | 38 |
39 | 42 |
43 | 44 |
45 | 46 |
47 | 49 |
50 | 51 | 52 |
53 |
54 | 56 |
57 | 58 |
59 | 61 |
62 | 63 |
64 | 65 |
66 |
67 | 69 |
70 | 71 |
72 | 74 |
75 | 76 |
77 | 78 | 79 |
80 |
81 | 83 |
84 | 85 |
86 | 89 |
90 | 91 |
92 | 93 | 94 | 95 |
96 | 98 |
99 | 100 | 101 | 102 | 103 | 104 | 105 | 107 |
108 |
109 | 110 | 115 |
116 |
117 |
118 |
119 | 120 |
121 | 122 | -------------------------------------------------------------------------------- /src/main/resources/templates/reset_password.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 | 11 |
12 |
13 |
14 | 15 |
16 |
17 |
18 |
19 |

Reset Password

20 | 21 |

[[${session.succMsg}]]

22 | 23 |
24 | 25 | 26 |

[[${session.errorMsg}]]

27 | 28 |
29 |
30 |
31 |
32 |
33 | 35 |
36 | 37 |
38 | 40 |
41 | 42 | 45 |
46 |
47 |
48 |
49 |
50 |
51 | 52 |
53 | 54 | -------------------------------------------------------------------------------- /src/main/resources/templates/user/cart.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 | 12 |
13 |
14 |

Cart Page

15 | 16 |

[[${session.succMsg}]]

17 | 18 |
19 | 20 | 21 |

[[${session.errorMsg}]]

22 | 23 |
24 |
25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
Sl NoImageProduct NamePriceQuantityTotal Price
[[${c.count}]][[${cart.product.title}]][[${cart.product.discountPrice}]] 47 | 48 | [ [[${cart.quantity}]] ] 50 | 51 | [[${cart.totalPrice}]]
Total Price [[${totalOrderPrice}]]
62 |
63 | Proceed Payment 64 |
65 |
66 |
67 |
68 | 69 |
70 | 71 | -------------------------------------------------------------------------------- /src/main/resources/templates/user/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 |

User Home Page

9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/templates/user/my_orders.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |

My Orders

13 | 14 |

[[${session.succMsg}]]

15 | 16 |
17 | 18 | 19 |

[[${session.errorMsg}]]

20 | 21 |
22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 44 | 45 | 51 | 52 | 53 |
Order IdDateProduct DetailsPriceStatusAction
[[${o.orderId}]][[${o.orderDate}]][[${o.product.title}]]Quantity : [[${o.quantity}]]
Price : 41 | [[${o.price}]]
Total Price :[[${o.quantity * 42 | o.price}]] 43 |
[[${o.status}]] 46 | Cancel 48 | 49 | Cancel 50 |
54 |
55 |
56 | 57 |
58 |
59 | 60 | -------------------------------------------------------------------------------- /src/main/resources/templates/user/order.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 | 11 |
12 |
13 |
14 | 15 |
16 | 17 | 18 |
19 |

Billing Address

20 |
21 |
22 | 24 |
25 |
26 | 28 |
29 |
30 | 31 |
32 |
33 | 35 |
36 |
37 | 39 |
40 |
41 | 42 |
43 |
44 | 46 |
47 |
48 | 50 |
51 |
52 |
53 |
54 | 56 |
57 |
58 | 60 |
61 |
62 | 63 | 64 |
65 |
66 |

Payment Type

67 |
68 |
69 |
70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
Total price: [[${orderPrice}]]
Delivery Fee: 250
Tax: 100
Total Price: [[${totalOrderPrice}]]
96 |
97 |
98 | 99 |
100 | 101 |
102 | 103 |
104 | 110 | 111 |
112 | 113 | 115 | 116 |
117 |
118 |
119 | 120 |
121 |
122 |
123 | 124 |
125 | 126 | -------------------------------------------------------------------------------- /src/main/resources/templates/user/profile.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 | 14 |

My Profile

15 | 16 |

[[${session.succMsg}]]

17 | 18 |
19 | 20 | 21 |

[[${session.errorMsg}]]

22 | 23 |
24 |
25 |
26 | 29 |
30 |
31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 62 | 63 | 65 | 66 | 67 | 68 | 69 | 71 | 72 | 73 | 74 | 75 | 77 | 78 | 79 | 80 | 81 | 83 | 84 | 85 | 86 | 87 | 89 | 90 | 91 | 92 | 93 | 96 | 97 | 98 | 99 | 100 | 103 | 104 | 105 | 106 |
Name:
Mobile Number:
Email:
Address:
City:
State:
Pincode:
Image:
Role:
Account Status:
101 | 102 |
107 | 108 |
109 | 110 |
111 |
112 |
113 |
114 |

Change Password

115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 142 | 143 | 144 | 145 | 146 |
Current Password
New Password
Confirm Password
140 | 141 |
147 |
148 |
149 |
150 | 151 |
152 | 153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 |
161 | 162 | -------------------------------------------------------------------------------- /src/main/resources/templates/user/success.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
11 |
12 |
13 | 14 |

Product Ordered Successfully

15 |

Product will be delivered with in 7 days

16 |
17 | Home Your Order 19 |
20 |
21 |
22 | 23 |
24 |
25 | 26 | -------------------------------------------------------------------------------- /src/main/resources/templates/view_product.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Insert title here 7 | 8 | 9 |
10 |
12 | 13 |
14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |

[[${session.errorMsg}]]

22 | 23 | 24 |
25 |
26 | 28 |
29 | 30 |
31 | 32 |

[[${product.title}]]

33 |

34 | Description :
[[${product.description}]] 35 |

36 |

37 | Product Details:
Status 38 | : 39 | 40 | Available 41 | 42 | 43 | 44 | out of stock 45 | 46 | 47 | 48 |
Category: [[${product.category}]]
Policy : 7 49 | Days Replacement & Return 50 |

51 |

52 | Price :        53 | [[${product.discountPrice}]] [[${product.price}]] 55 | [[${product.discount}]]% 56 | off 57 |

58 | 59 |
60 |
61 | 62 |

Cash On Delivery

63 |
64 |
65 | 66 |

Return Available

67 |
68 |
69 | 70 |

Free Shipping

71 |
72 |
73 | 74 | 75 | 76 | Add To 77 | Cart 78 | 79 | 80 | 81 | Add To Cart 84 | 85 | 86 | 87 | 88 | 89 | Out 90 | of Stock 91 | 92 | 93 |
94 |
95 |
96 |
97 | 98 | 99 |
100 | 101 | -------------------------------------------------------------------------------- /src/test/java/com/ecom/ShoppingCartApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.ecom; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ShoppingCartApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------