Repository navigation
Fix issues #129, #130, #94, #106, #105, #126 #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,4 +39,5 @@ target | |
| .flattened-pom.xml | ||
| secrets.yml | ||
| .gradletasknamecache | ||
| .sts4-cache | ||
| .sts4-cache | ||
| cookies.txt | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| target/ | ||
| .git | ||
| .gitignore | ||
| *.iml | ||
| .idea | ||
| *.md |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Build stage | ||
| FROM maven:3.8-eclipse-temurin-11 AS build | ||
| WORKDIR /app | ||
|
|
||
| # Copy pom.xml and download dependencies | ||
| COPY pom.xml . | ||
| RUN mvn dependency:go-offline -B | ||
|
|
||
| # Copy source code and build | ||
| COPY src ./src | ||
| RUN mvn clean package -DskipTests -B | ||
|
|
||
| # Run stage | ||
| FROM eclipse-temurin:11-jre-alpine | ||
| WORKDIR /app | ||
|
|
||
| # Create non-root user | ||
| RUN addgroup -S spring && adduser -S spring -G spring | ||
| USER spring:spring | ||
|
|
||
| # Copy jar from build stage | ||
| COPY --from=build /app/target/*.jar app.jar | ||
|
|
||
| # Expose port | ||
| EXPOSE 8080 | ||
|
|
||
| # Run the application | ||
| ENTRYPOINT ["java", "-jar", "app.jar"] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,8 @@ | |||||||||||||||||||||
| SET SQL_MODE ='IGNORE_SPACE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # create database and use it | ||||||||||||||||||||||
| CREATE DATABASE IF NOT EXISTS ecommjava; | ||||||||||||||||||||||
| USE ecommjava; | ||||||||||||||||||||||
| CREATE DATABASE IF NOT EXISTS ecomjava; | ||||||||||||||||||||||
| USE ecomjava; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # create the category table | ||||||||||||||||||||||
| CREATE TABLE IF NOT EXISTS CATEGORY( | ||||||||||||||||||||||
|
|
@@ -30,13 +30,15 @@ email varchar(255) null, | |||||||||||||||||||||
| password varchar(255) null, | ||||||||||||||||||||||
| role varchar(255) null, | ||||||||||||||||||||||
| username varchar(255) null, | ||||||||||||||||||||||
| is_active tinyint(1) not null default 1, | ||||||||||||||||||||||
| UNIQUE (username) | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # insert default customers | ||||||||||||||||||||||
| INSERT INTO CUSTOMER(address, email, password, role, username) VALUES | ||||||||||||||||||||||
| ('123, Albany Street', 'admin@nyan.cat', '123', 'ROLE_ADMIN', 'admin'), | ||||||||||||||||||||||
| ('765, 5th Avenue', 'lisa@gmail.com', '765', 'ROLE_NORMAL', 'lisa'); | ||||||||||||||||||||||
| # insert default customers (BCrypt: admin=123) | ||||||||||||||||||||||
| # For lisa=765, register via /register or update password in DB with BCrypt hash | ||||||||||||||||||||||
| INSERT INTO CUSTOMER(address, email, password, role, username, is_active) VALUES | ||||||||||||||||||||||
| ('123, Albany Street', 'admin@nyan.cat', '$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG', 'ROLE_ADMIN', 'admin', 1), | ||||||||||||||||||||||
| ('765, 5th Avenue', 'lisa@gmail.com', '765', 'ROLE_NORMAL', 'lisa', 1); | ||||||||||||||||||||||
|
Comment on lines
+37
to
+41
|
||||||||||||||||||||||
| # insert default customers (BCrypt: admin=123) | |
| # For lisa=765, register via /register or update password in DB with BCrypt hash | |
| INSERT INTO CUSTOMER(address, email, password, role, username, is_active) VALUES | |
| ('123, Albany Street', 'admin@nyan.cat', '$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG', 'ROLE_ADMIN', 'admin', 1), | |
| ('765, 5th Avenue', 'lisa@gmail.com', '765', 'ROLE_NORMAL', 'lisa', 1); | |
| # insert default customers (BCrypt: admin=123, lisa=765) | |
| # Both default customer passwords are stored as BCrypt hashes for compatibility with BCryptPasswordEncoder | |
| INSERT INTO CUSTOMER(address, email, password, role, username, is_active) VALUES | |
| ('123, Albany Street', 'admin@nyan.cat', '$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG', 'ROLE_ADMIN', 'admin', 1), | |
| ('765, 5th Avenue', 'lisa@gmail.com', '$2a$10$7EqJtq98hPqEX7fNZaFWoOHiWqD3oB8LE6wS6vKrrf5wM9vY7Gk8W', 'ROLE_NORMAL', 'lisa', 1); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -- Fix admin password for BCrypt authentication | ||
| -- Run this in your ecomjava database if admin/123 login fails | ||
| -- This updates the admin user's password to BCrypt hash of "123" | ||
|
|
||
| USE ecomjava; | ||
|
|
||
| UPDATE CUSTOMER | ||
| SET password = '$2a$10$Gqo6QT80w8V9jOd0hUlA2uj2lDe3bwNgz.eMP8UwnsB6zMVJ2hYh6', | ||
| is_active = 1 | ||
| WHERE username = 'admin'; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,4 @@ | ||||||
| USE ecomjava; | ||||||
|
|
||||||
| INSERT INTO customer (address, email, password, role, username, is_active) VALUES | ||||||
|
||||||
| INSERT INTO customer (address, email, password, role, username, is_active) VALUES | |
| INSERT INTO CUSTOMER (address, email, password, role, username, is_active) VALUES |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -3,13 +3,16 @@ | |||
| import java.util.Properties; | ||||
|
|
||||
| import javax.sql.DataSource; | ||||
| import javax.persistence.EntityManagerFactory; | ||||
|
||||
| import javax.persistence.EntityManagerFactory; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.jtspringproject.JtSpringProject.config; | ||
|
|
||
| import org.springframework.boot.CommandLineRunner; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.jtspringproject.JtSpringProject.models.User; | ||
| import com.jtspringproject.JtSpringProject.services.userService; | ||
|
|
||
| @Component | ||
| public class AdminDataLoader implements CommandLineRunner { | ||
|
|
||
| private final userService userService; | ||
| private final PasswordEncoder passwordEncoder; | ||
|
|
||
| public AdminDataLoader(userService userService, PasswordEncoder passwordEncoder) { | ||
| this.userService = userService; | ||
| this.passwordEncoder = passwordEncoder; | ||
| } | ||
|
|
||
| @Override | ||
| public void run(String... args) { | ||
| try { | ||
| User admin = userService.getUserByUsername("admin"); | ||
| if (admin != null && !passwordEncoder.matches("123", admin.getPassword())) { | ||
| admin.setPassword(passwordEncoder.encode("123")); | ||
| admin.setActive(true); | ||
|
Comment on lines
+24
to
+27
|
||
| userService.updateUser(admin); | ||
| System.out.println(">>> Admin password updated."); | ||
| } | ||
| } catch (Exception e) { | ||
| System.err.println("AdminDataLoader: " + e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.jtspringproject.JtSpringProject.controller; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.servlet.ModelAndView; | ||
|
|
||
| import com.jtspringproject.JtSpringProject.models.Category; | ||
| import com.jtspringproject.JtSpringProject.services.categoryService; | ||
|
|
||
| @Controller | ||
| @RequestMapping("/admin") | ||
| public class AdminCategoryController { | ||
|
|
||
| private final categoryService categoryService; | ||
|
|
||
| @Autowired | ||
| public AdminCategoryController(categoryService categoryService) { | ||
| this.categoryService = categoryService; | ||
| } | ||
|
|
||
| @GetMapping("categories") | ||
| public ModelAndView getCategories() { | ||
| ModelAndView mView = new ModelAndView("categories"); | ||
| List<Category> categories = this.categoryService.getCategories(); | ||
| mView.addObject("categories", categories); | ||
| return mView; | ||
| } | ||
|
|
||
| @PostMapping("/categories") | ||
| public String addCategory(@RequestParam("categoryname") String categoryName) { | ||
| this.categoryService.addCategory(categoryName); | ||
| return "redirect:categories"; | ||
| } | ||
|
|
||
| @GetMapping("categories/delete") | ||
| public String removeCategory(@RequestParam("id") int id) { | ||
| this.categoryService.deleteCategory(id); | ||
| return "redirect:/admin/categories"; | ||
| } | ||
|
|
||
| @GetMapping("categories/update") | ||
| public String updateCategory(@RequestParam("categoryid") int id, @RequestParam("categoryname") String categoryName) { | ||
| this.categoryService.updateCategory(id, categoryName); | ||
| return "redirect:/admin/categories"; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script creates/uses
ecomjava, but Docker Compose and the README still referenceecommjava. Standardize the database name across all configs/scripts so setup instructions and Docker runs target the same schema.