Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 31 additions & 0 deletions admin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/

### VS Code ###
.vscode/
File renamed without changes.
581 changes: 581 additions & 0 deletions admin/log/wdf.log

Large diffs are not rendered by default.

Binary file added admin/log/wdf.log.2020-01-29.0.gz
Binary file not shown.
Binary file added admin/log/wdf.log.2020-01-30.0.gz
Binary file not shown.
File renamed without changes.
File renamed without changes.
79 changes: 79 additions & 0 deletions admin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>wdf</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.example</groupId>
<artifactId>admin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>admin</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.junit.vintage</groupId>-->
<!-- <artifactId>junit-vintage-engine</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->

<dependency>
<groupId>com.example</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
20 changes: 20 additions & 0 deletions admin/src/main/java/com/example/admin/AdminApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.admin;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EnableJpaRepositories(basePackages = "com.example.common.repository")
@ComponentScan(basePackages = {"com.example.admin.*", "com.example.common.*"})
@EntityScan("com.example.common.model")
//@CrossOrigin("*")
public class AdminApplication {

public static void main(String[] args) {
SpringApplication.run(AdminApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

private final UserDetailsService userDetailService;

public WebSecurityConfig(UserDetailsService userDetailService) {
this.userDetailService = userDetailService;
}


@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailService)
.passwordEncoder(passwordEncoder());
}



@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/admin").hasAnyRole("ADMIN")
.and()
.formLogin().loginPage("/admin/login.html")
// .defaultSuccessUrl("/boxed-layout.html", true)
.and()
.logout()
.logoutSuccessUrl("/admin/login.html");
}

@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.admin.controller;

import com.example.common.model.Category;
import com.example.common.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/admin/categories")
public class CategoryController {

private final CategoryService categoryService;

public CategoryController(CategoryService categoryService) {
this.categoryService = categoryService;
}


@PostMapping(value = "/addCategory")
public String addCategory(Category category) {
categoryService.addCategory(category);
return "redirect:/boxed-layout";
}

@DeleteMapping("/deleteById")
public String deleteById(@RequestParam("id") long id){
categoryService.deleteById(id);
return "redirect:/boxed-layout";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.example.admin.controller;

import com.example.common.model.Image;
import com.example.common.service.ImageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Controller
@Slf4j
@RequestMapping("/admin/images")
public class ImageController {

@Value("${image.upload.dir}")
private String imageUploadDir;

private final ImageService imageService;

public ImageController(ImageService imageService) {
this.imageService = imageService;
}

//getImage method
@GetMapping(value = "/getImage", produces = MediaType.IMAGE_JPEG_VALUE)
public @ResponseBody
byte[] getImage(@RequestParam("picUrl") String picUrl) throws IOException {
return imageService.getImage(picUrl);
}

//find all products
@GetMapping("/allImages")
public String getAll(ModelMap modelMap) {
List<Image> all = imageService.findAll();
modelMap.addAttribute("all", all);
return "photo-gallery";
}

@DeleteMapping("/deleteById")
public String deleteById(@RequestParam("id") long id){
imageService.deleteById(id);
return "redirect:/photo_gallery";
}

@PostMapping("/addImages")
public String addImages(@RequestParam(value = "images") MultipartFile[] file) {
try {
imageService.addImages(file);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:/boxed-layout";
}

@PostMapping("/addImage")
public String addImage(@RequestParam(value = "image") MultipartFile file) {
try {
imageService.addImage(file);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:/boxed-layout";
}

@GetMapping("/single/image")
public String single(@RequestParam("id") int id, ModelMap modelMap) {
Image image = imageService.findById(id);
if (image != null) {
modelMap.addAttribute("image", image);
} else {
log.error("Image with {} id does not exists", id);
}
return "singleImage";
}
}
Loading