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.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
|
||||
public class EasyStartupApplication {
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.permitAll()
|
||||
.and()
|
||||
.logout()
|
||||
.permitAll();
|
||||
.permitAll()
|
||||
.and()
|
||||
.rememberMe().userDetailsService(this.userDetailsService())
|
||||
.rememberMeServices(null)
|
||||
.tokenValiditySeconds(86400)
|
||||
.useSecureCookie(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,7 +44,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
auth.jdbcAuthentication()
|
||||
.dataSource(dataSource)
|
||||
.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 = ?;");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import lombok.*;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@RequiredArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "usr")
|
||||
public class User {
|
||||
@@ -15,10 +20,38 @@ public class User {
|
||||
private String username;
|
||||
private String password;
|
||||
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)
|
||||
@CollectionTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"))
|
||||
@Enumerated(EnumType.STRING)
|
||||
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>
|
||||
|
||||
<body class="text-center">
|
||||
<body>
|
||||
|
||||
<main>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
<div>
|
||||
<label>
|
||||
<input type="checkbox" value="remember-me"> Запомнить меня
|
||||
<input type="checkbox" name="remember-me"> Запомнить меня
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user