Added remember-me auth, fields in User.java, some HTML pages.
Adding forum system, commit 1/2
This commit is contained in:
1 parent
c13f926a56
commit
180db45c8d
17 files changed
+292
-41
No files matched your search
@@ -2,7 +2,14 @@ package site.easystartup.easystartupcore;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class EasyStartupApplication {
|
public class EasyStartupApplication {
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,12 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.permitAll()
|
.permitAll()
|
||||||
.and()
|
.and()
|
||||||
.logout()
|
.logout()
|
||||||
.permitAll();
|
.permitAll()
|
||||||
|
.and()
|
||||||
|
.rememberMe().userDetailsService(this.userDetailsService())
|
||||||
|
.rememberMeServices(null)
|
||||||
|
.tokenValiditySeconds(86400)
|
||||||
|
.useSecureCookie(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,7 +44,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
auth.jdbcAuthentication()
|
auth.jdbcAuthentication()
|
||||||
.dataSource(dataSource)
|
.dataSource(dataSource)
|
||||||
.passwordEncoder(passwordEncoder)
|
.passwordEncoder(passwordEncoder)
|
||||||
.usersByUsernameQuery("SELECT `username`, `password`, `active` FROM usr WHERE `username` = ?;")
|
.usersByUsernameQuery("SELECT username, password, active FROM usr WHERE username = ?;")
|
||||||
.authoritiesByUsernameQuery("SELECT u.username, ur.roles FROM usr u INNER JOIN user_role ur ON u.id = ur.user_id WHERE username = ?;");
|
.authoritiesByUsernameQuery("SELECT u.username, ur.roles FROM usr u INNER JOIN user_role ur ON u.id = ur.user_id WHERE username = ?;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package site.easystartup.easystartupcore.controller;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.val;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import site.easystartup.easystartupcore.repos.forum.TopicRepo;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||||
|
public class ForumController {
|
||||||
|
private final TopicRepo topicRepo;
|
||||||
|
|
||||||
|
@GetMapping("/forum")
|
||||||
|
public String forumMain(Model model) {
|
||||||
|
val topic = topicRepo.findAll();
|
||||||
|
model.addAttribute("topics", topic);
|
||||||
|
return "forum";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package site.easystartup.easystartupcore.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class MainController {
|
||||||
|
@GetMapping("/")
|
||||||
|
public String home() {
|
||||||
|
return "home";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/about")
|
||||||
|
public String about() {
|
||||||
|
return "about";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
package site.easystartup.easystartupcore.domain;
|
package site.easystartup.easystartupcore.domain;
|
||||||
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Data
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@RequiredArgsConstructor
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "usr")
|
@Table(name = "usr")
|
||||||
public class User {
|
public class User {
|
||||||
@@ -15,10 +20,38 @@ public class User {
|
|||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
|
private String full_name;
|
||||||
|
private String status;
|
||||||
|
private String iconPath;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
|
||||||
|
@CollectionTable(name = "user_tag", joinColumns = @JoinColumn(name = "user_id"))
|
||||||
|
private Set<String> tags;
|
||||||
|
|
||||||
|
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
|
||||||
|
@CollectionTable(name = "user_profession", joinColumns = @JoinColumn(name = "user_id"))
|
||||||
|
private Set<String> professions;
|
||||||
|
|
||||||
|
@ElementCollection(targetClass = Long.class, fetch = FetchType.EAGER)
|
||||||
|
@CollectionTable(name = "user_projects", joinColumns = @JoinColumn(name = "user_id"))
|
||||||
|
private Set<Long> projects;
|
||||||
|
|
||||||
@ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER)
|
@ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER)
|
||||||
@CollectionTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"))
|
@CollectionTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"))
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
private Set<Role> roles;
|
private Set<Role> roles;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||||
|
User user = (User) o;
|
||||||
|
return Objects.equals(id, user.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getClass().hashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package site.easystartup.easystartupcore.domain.forum;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Entity
|
||||||
|
public class Discussion {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long id;
|
||||||
|
private String title;
|
||||||
|
private String author;
|
||||||
|
private Date date;
|
||||||
|
private Date last_update;
|
||||||
|
|
||||||
|
@ElementCollection(targetClass = Long.class, fetch = FetchType.EAGER)
|
||||||
|
@CollectionTable(name = "discussion_messages", joinColumns = @JoinColumn(name = "discussion_id"))
|
||||||
|
private List<Long> messages;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||||
|
Discussion that = (Discussion) o;
|
||||||
|
return Objects.equals(id, that.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getClass().hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package site.easystartup.easystartupcore.domain.forum;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Entity
|
||||||
|
public class DiscussionMessage {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long id;
|
||||||
|
@Column(columnDefinition="varchar(1024)")
|
||||||
|
private String text;
|
||||||
|
private String sender;
|
||||||
|
private Date date;
|
||||||
|
private boolean edited;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||||
|
DiscussionMessage that = (DiscussionMessage) o;
|
||||||
|
return Objects.equals(id, that.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getClass().hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package site.easystartup.easystartupcore.domain.forum;
|
||||||
|
|
||||||
|
public enum DiscussionStatus {
|
||||||
|
OPEN, CLOSED;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package site.easystartup.easystartupcore.domain.forum;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Entity
|
||||||
|
public class Topic {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long id;
|
||||||
|
private String title;
|
||||||
|
private int size;
|
||||||
|
private String description;
|
||||||
|
private Date last_update;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||||
|
Topic topic = (Topic) o;
|
||||||
|
return Objects.equals(id, topic.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getClass().hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package site.easystartup.easystartupcore.repos.forum;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import site.easystartup.easystartupcore.domain.forum.Discussion;
|
||||||
|
import site.easystartup.easystartupcore.domain.forum.DiscussionMessage;
|
||||||
|
|
||||||
|
public interface DiscussionMessageRepo extends CrudRepository<DiscussionMessage, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package site.easystartup.easystartupcore.repos.forum;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import site.easystartup.easystartupcore.domain.forum.Discussion;
|
||||||
|
|
||||||
|
public interface DiscussionRepo extends CrudRepository<Discussion, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package site.easystartup.easystartupcore.repos.forum;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import site.easystartup.easystartupcore.domain.forum.Discussion;
|
||||||
|
import site.easystartup.easystartupcore.domain.forum.Topic;
|
||||||
|
|
||||||
|
public interface TopicRepo extends CrudRepository<Topic, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
|
||||||
|
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>О нас</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<p>О нас</p>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
|
||||||
|
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Форум</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<p>Форум</p>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
|
||||||
|
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Главная</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<p>Главня страница</p>
|
||||||
|
<form th:action="@{/logout}" method="post"><button sec:authorize="isAuthenticated()" type="submit">Выйти</button></form>
|
||||||
|
<a sec:authorize="isAnonymous()" href="/login">Вход</a>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="text-center">
|
<body>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" value="remember-me"> Запомнить меня
|
<input type="checkbox" name="remember-me"> Запомнить меня
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,52 +1,29 @@
|
|||||||
package site.easystartup.easystartupcore;
|
package site.easystartup.easystartupcore;
|
||||||
|
|
||||||
import java.io.File;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import site.easystartup.easystartupcore.storage.StorageFileNotFoundException;
|
||||||
|
import site.easystartup.easystartupcore.storage.StorageService;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.aspectj.lang.annotation.After;
|
|
||||||
import org.hamcrest.Matchers;
|
|
||||||
import org.junit.jupiter.api.AfterAll;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.boot.test.context.TestConfiguration;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
|
||||||
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.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
|
||||||
import site.easystartup.easystartupcore.config.WebSecurityConfig;
|
|
||||||
import site.easystartup.easystartupcore.storage.StorageFileNotFoundException;
|
|
||||||
import site.easystartup.easystartupcore.storage.StorageService;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.BDDMockito.then;
|
import static org.mockito.BDDMockito.then;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
|
||||||
@EnableAutoConfiguration(exclude = { SecurityAutoConfiguration.class })
|
|
||||||
@AutoConfigureMockMvc(addFilters = false)
|
@AutoConfigureMockMvc(addFilters = false)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class FileUploadTests {
|
public class FileUploadTests {
|
||||||
|
|||||||
Reference in new issue
Block a user