회원등급 모델 추가
회원강퇴 날짜 프로퍼티 추
This commit is contained in:
parent
e0c2d9736e
commit
c96d693d2d
|
@ -51,8 +51,11 @@ public class AuthController {
|
||||||
@Autowired
|
@Autowired
|
||||||
JwtTokenProvider tokenProvider;
|
JwtTokenProvider tokenProvider;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
HttpServletRequest request;
|
||||||
|
|
||||||
@PostMapping("/signin")
|
@PostMapping("/signin")
|
||||||
public ResponseEntity<?> authenticateUser(@Valid @RequestBody SigninRequest signinRequest, HttpServletRequest request) {
|
public ResponseEntity<?> authenticateUser(@Valid @RequestBody SigninRequest signinRequest) {
|
||||||
|
|
||||||
String ipAddr = request.getRemoteAddr();
|
String ipAddr = request.getRemoteAddr();
|
||||||
System.out.println("ipAddr = " + ipAddr);
|
System.out.println("ipAddr = " + ipAddr);
|
||||||
|
|
|
@ -52,14 +52,32 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.cors().and().csrf().disable().exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and()
|
http
|
||||||
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
|
.cors()
|
||||||
.antMatchers("/", "/favicon.ico", "/**/*.png", "/**/*.gif", "/**/*.svg", "/**/*.jpg", "/**/*.html", "/**/*.css",
|
.and()
|
||||||
|
.csrf()
|
||||||
|
.disable()
|
||||||
|
.exceptionHandling()
|
||||||
|
.authenticationEntryPoint(jwtAuthenticationEntryPoint)
|
||||||
|
.and()
|
||||||
|
.sessionManagement()
|
||||||
|
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
|
// .maximumSessions(1)
|
||||||
|
// .sessionRegistry(sessionRegistry());
|
||||||
|
.and()
|
||||||
|
.authorizeRequests()
|
||||||
|
.antMatchers("/", "/favicon.ico", "/**/*.png", "/**/*.gif", "/**/*.svg", "/**/*.jpg", "/**/*.html", "/**/*.css",
|
||||||
"/**/*.js")
|
"/**/*.js")
|
||||||
.permitAll().antMatchers("/auth/**").permitAll().antMatchers("/users/**").permitAll().anyRequest()
|
.permitAll()
|
||||||
|
.antMatchers("/auth/**")
|
||||||
|
.permitAll()
|
||||||
|
.antMatchers("/users/**")
|
||||||
|
.permitAll()
|
||||||
|
.anyRequest()
|
||||||
.authenticated();
|
.authenticated();
|
||||||
|
|
||||||
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
|
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,9 @@ import java.io.IOException;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
|
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
|
||||||
AuthenticationException e) throws IOException, ServletException {
|
AuthenticationException e) throws IOException, ServletException {
|
||||||
|
|
||||||
log.error("Responding with unauthorized error. Message - {}", e.getMessage());
|
log.error("Responding with unauthorized error. Message - {}", e.getMessage());
|
||||||
httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
|
httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package com.totopia.server.init;
|
package com.totopia.server.init;
|
||||||
|
|
||||||
import com.totopia.server.modules.dashboard.repository.DashboardRepository;
|
import com.totopia.server.modules.dashboard.repository.DashboardRepository;
|
||||||
|
import com.totopia.server.modules.user.entity.GradeEntity;
|
||||||
import com.totopia.server.modules.user.entity.RoleEntity;
|
import com.totopia.server.modules.user.entity.RoleEntity;
|
||||||
import com.totopia.server.modules.user.entity.UserEntity;
|
import com.totopia.server.modules.user.entity.UserEntity;
|
||||||
|
import com.totopia.server.modules.user.repository.GradeRepository;
|
||||||
import com.totopia.server.modules.user.repository.RoleRepository;
|
import com.totopia.server.modules.user.repository.RoleRepository;
|
||||||
import com.totopia.server.modules.user.repository.UserRepository;
|
import com.totopia.server.modules.user.repository.UserRepository;
|
||||||
|
import com.totopia.server.modules.user.type.GradeName;
|
||||||
import com.totopia.server.modules.user.type.RoleName;
|
import com.totopia.server.modules.user.type.RoleName;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
@ -18,6 +22,7 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnProperty(name = "app.db-init", havingValue = "true")
|
@ConditionalOnProperty(name = "app.db-init", havingValue = "true")
|
||||||
|
@Slf4j
|
||||||
public class DbInitializer implements CommandLineRunner {
|
public class DbInitializer implements CommandLineRunner {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -32,18 +37,41 @@ public class DbInitializer implements CommandLineRunner {
|
||||||
@Autowired
|
@Autowired
|
||||||
DashboardRepository dashboardRepository;
|
DashboardRepository dashboardRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
GradeRepository gradeRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... strings) throws Exception {
|
public void run(String... strings) throws Exception {
|
||||||
if (0 == roleRepository.count()) {
|
if (0 == roleRepository.count()) {
|
||||||
RoleEntity role = null;
|
RoleEntity role;
|
||||||
|
role = RoleEntity.builder().name(RoleName.ROLE_USER).build();
|
||||||
|
roleRepository.save(role);
|
||||||
|
role = RoleEntity.builder().name(RoleName.ROLE_TEAM).build();
|
||||||
|
roleRepository.save(role);
|
||||||
|
role = RoleEntity.builder().name(RoleName.ROLE_AGENCY).build();
|
||||||
|
roleRepository.save(role);
|
||||||
role = RoleEntity.builder().name(RoleName.ROLE_ADMIN).build();
|
role = RoleEntity.builder().name(RoleName.ROLE_ADMIN).build();
|
||||||
roleRepository.save(role);
|
roleRepository.save(role);
|
||||||
role = RoleEntity.builder().name(RoleName.ROLE_USER).build();
|
role = RoleEntity.builder().name(RoleName.ROLE_SUPER_ADMIN).build();
|
||||||
roleRepository.save(role);
|
roleRepository.save(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 == gradeRepository.count()) {
|
||||||
|
GradeEntity grade;
|
||||||
|
grade = GradeEntity.builder().name(GradeName.BAD_USER).build();
|
||||||
|
gradeRepository.save(grade);
|
||||||
|
grade = GradeEntity.builder().name(GradeName.NORMAL_USER).build();
|
||||||
|
gradeRepository.save(grade);
|
||||||
|
grade = GradeEntity.builder().name(GradeName.REGULAR_USER).build();
|
||||||
|
gradeRepository.save(grade);
|
||||||
|
grade = GradeEntity.builder().name(GradeName.VIP_USER).build();
|
||||||
|
gradeRepository.save(grade);
|
||||||
|
grade = GradeEntity.builder().name(GradeName.PLATINUM_USER).build();
|
||||||
|
gradeRepository.save(grade);
|
||||||
|
}
|
||||||
|
|
||||||
if (0 == userRepository.count()) {
|
if (0 == userRepository.count()) {
|
||||||
UserEntity user = null;
|
UserEntity user;
|
||||||
user = UserEntity.builder().username("admin").password(passwordEncoder.encode("admin")).nickname("admin")
|
user = UserEntity.builder().username("admin").password(passwordEncoder.encode("admin")).nickname("admin")
|
||||||
.email("admin@example.com").block(false).resetCount(0L).sendEmail(true).roles(Stream.of(RoleEntity.builder().id(Short.valueOf((short) 1)).build())
|
.email("admin@example.com").block(false).resetCount(0L).sendEmail(true).roles(Stream.of(RoleEntity.builder().id(Short.valueOf((short) 1)).build())
|
||||||
.collect(Collectors.toCollection(HashSet::new)))
|
.collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
@ -64,6 +92,6 @@ public class DbInitializer implements CommandLineRunner {
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(" -- Database has been initialized");
|
log.debug("-- Database has been initialized");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,25 @@ import com.totopia.server.commons.exception.ResourceNotFoundException;
|
||||||
import com.totopia.server.modules.user.entity.UserEntity;
|
import com.totopia.server.modules.user.entity.UserEntity;
|
||||||
import com.totopia.server.modules.user.repository.UserRepository;
|
import com.totopia.server.modules.user.repository.UserRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.*;
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.web.PageableDefault;
|
|
||||||
import org.springframework.data.web.SortDefault;
|
import org.springframework.data.web.SortDefault;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.core.session.SessionRegistry;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class UserController {
|
public class UserController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
// @Autowired
|
||||||
|
// private SessionRegistry sessionRegistry;
|
||||||
|
|
||||||
@PostMapping(value = "/users")
|
@PostMapping(value = "/users")
|
||||||
@ResponseStatus(code = HttpStatus.CREATED)
|
@ResponseStatus(code = HttpStatus.CREATED)
|
||||||
public UserEntity save(@RequestBody UserEntity user) {
|
public UserEntity save(@RequestBody UserEntity user) {
|
||||||
|
@ -26,7 +31,7 @@ public class UserController {
|
||||||
|
|
||||||
@GetMapping(value = "/users")
|
@GetMapping(value = "/users")
|
||||||
public Page<UserEntity> all(@RequestParam(value = "username", required = false) String username,
|
public Page<UserEntity> all(@RequestParam(value = "username", required = false) String username,
|
||||||
@SortDefault.SortDefaults({ @SortDefault(sort = "createdDate", direction = Sort.Direction.DESC) }) Pageable pageable) {
|
@SortDefault.SortDefaults({ @SortDefault(sort = "createdAt", direction = Sort.Direction.DESC) }) Pageable pageable) {
|
||||||
|
|
||||||
if (null == username) {
|
if (null == username) {
|
||||||
return userRepository.findAll(pageable);
|
return userRepository.findAll(pageable);
|
||||||
|
@ -35,7 +40,29 @@ public class UserController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/users/{userId}")
|
@GetMapping(value = "/connect-users")
|
||||||
|
public Page<UserEntity> connectUsers(@RequestParam(value = "username", required = false) String username,
|
||||||
|
@SortDefault.SortDefaults({ @SortDefault(sort = "createdAt", direction = Sort.Direction.DESC) }) Pageable pageable) {
|
||||||
|
// final List<String> curUsers = sessionRegistry.getAllPrincipals().stream()
|
||||||
|
// .filter(u -> !sessionRegistry.getAllSessions(u, false).isEmpty())
|
||||||
|
// .map(Object::toString)
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
//
|
||||||
|
// long start = pageable.getOffset();
|
||||||
|
// long end = (start + pageable.getPageSize()) > curUsers.size() ? curUsers.size() : (start + pageable.getPageSize());
|
||||||
|
// List<String> tempUsers = curUsers.subList((int)start, (int)end);
|
||||||
|
// List<UserEntity> users = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (String conUser : tempUsers) {
|
||||||
|
// UserEntity tempUser = this.userRepository.findByUsername(conUser).orElse(null);
|
||||||
|
// if(tempUser != null) {
|
||||||
|
// users.add(tempUser);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return new PageImpl<UserEntity>(users, new PageRequest(pageable.getPageNumber(), pageable.getPageSize()), users.size());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@GetMapping(value = "/users/{userId}")
|
||||||
public UserEntity findByUserId(@PathVariable Long userId) {
|
public UserEntity findByUserId(@PathVariable Long userId) {
|
||||||
return userRepository.findById(userId).orElseThrow(() -> new ResourceNotFoundException("User", "userId", userId));
|
return userRepository.findById(userId).orElseThrow(() -> new ResourceNotFoundException("User", "userId", userId));
|
||||||
}
|
}
|
||||||
|
@ -60,4 +87,6 @@ public class UserController {
|
||||||
}).orElseThrow(() -> new ResourceNotFoundException("User", "userId", userId));
|
}).orElseThrow(() -> new ResourceNotFoundException("User", "userId", userId));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.totopia.server.modules.user.entity;
|
||||||
|
|
||||||
|
import com.totopia.server.modules.user.type.GradeName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Entity(name = "grade")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class GradeEntity implements Serializable {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(generator = "grade_generator")
|
||||||
|
@SequenceGenerator(name = "grade_generator", sequenceName = "grade_sequence", initialValue = 1)
|
||||||
|
private Short id;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "name", length = 60)
|
||||||
|
private GradeName name;
|
||||||
|
}
|
|
@ -1,11 +1,19 @@
|
||||||
package com.totopia.server.modules.user.entity;
|
package com.totopia.server.modules.user.entity;
|
||||||
|
|
||||||
import com.totopia.server.modules.user.type.RoleName;
|
import com.totopia.server.modules.user.type.RoleName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Entity(name = "roles")
|
@Entity(name = "roles")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
public class RoleEntity implements Serializable {
|
public class RoleEntity implements Serializable {
|
||||||
private static final long serialVersionUID = 5100719044067326295L;
|
private static final long serialVersionUID = 5100719044067326295L;
|
||||||
|
|
||||||
|
@ -18,89 +26,4 @@ public class RoleEntity implements Serializable {
|
||||||
@Column(name = "name", length = 60)
|
@Column(name = "name", length = 60)
|
||||||
private RoleName name;
|
private RoleName name;
|
||||||
|
|
||||||
public RoleEntity(Short id, RoleName name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleEntity() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RoleEntityBuilder builder() {
|
|
||||||
return new RoleEntityBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getId() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleName getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Short id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(RoleName name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(final Object o) {
|
|
||||||
if (o == this) return true;
|
|
||||||
if (!(o instanceof RoleEntity)) return false;
|
|
||||||
final RoleEntity other = (RoleEntity) o;
|
|
||||||
if (!other.canEqual((Object) this)) return false;
|
|
||||||
final Object this$id = this.getId();
|
|
||||||
final Object other$id = other.getId();
|
|
||||||
if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false;
|
|
||||||
final Object this$name = this.getName();
|
|
||||||
final Object other$name = other.getName();
|
|
||||||
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean canEqual(final Object other) {
|
|
||||||
return other instanceof RoleEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
final int PRIME = 59;
|
|
||||||
int result = 1;
|
|
||||||
final Object $id = this.getId();
|
|
||||||
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
|
|
||||||
final Object $name = this.getName();
|
|
||||||
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "RoleEntity(id=" + this.getId() + ", name=" + this.getName() + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class RoleEntityBuilder {
|
|
||||||
private Short id;
|
|
||||||
private RoleName name;
|
|
||||||
|
|
||||||
RoleEntityBuilder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleEntity.RoleEntityBuilder id(Short id) {
|
|
||||||
this.id = id;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleEntity.RoleEntityBuilder name(RoleName name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleEntity build() {
|
|
||||||
return new RoleEntity(id, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "RoleEntity.RoleEntityBuilder(id=" + this.id + ", name=" + this.name + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,10 @@ package com.totopia.server.modules.user.entity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.totopia.server.commons.data.entity.DateAuditEntity;
|
import com.totopia.server.commons.data.entity.DateAuditEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -10,7 +14,11 @@ import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
|
@Data
|
||||||
@SuperBuilder
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class UserEntity extends DateAuditEntity {
|
public class UserEntity extends DateAuditEntity {
|
||||||
private static final long serialVersionUID = 8891163223262220481L;
|
private static final long serialVersionUID = 8891163223262220481L;
|
||||||
|
|
||||||
|
@ -52,6 +60,11 @@ public class UserEntity extends DateAuditEntity {
|
||||||
@Column(name = "last_reset_time", nullable = true)
|
@Column(name = "last_reset_time", nullable = true)
|
||||||
private Date lastResetTime;
|
private Date lastResetTime;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(name = "block_created_at", nullable = true)
|
||||||
|
private Date blockCreatedAt;
|
||||||
|
|
||||||
@Basic
|
@Basic
|
||||||
@Column(name = "reset_count", nullable = false)
|
@Column(name = "reset_count", nullable = false)
|
||||||
private Long resetCount = 0L;
|
private Long resetCount = 0L;
|
||||||
|
@ -72,236 +85,9 @@ public class UserEntity extends DateAuditEntity {
|
||||||
@JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
|
@JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
|
||||||
private Set<RoleEntity> roles;
|
private Set<RoleEntity> roles;
|
||||||
|
|
||||||
public UserEntity(String username, String password, String nickname, String email, Boolean block, Boolean sendEmail, String activation, Date lastResetTime, Long resetCount, String otpKey, String otep, Boolean requireReset, Set<RoleEntity> roles) {
|
@Basic
|
||||||
this.username = username;
|
@Column(name = "grade", nullable = true)
|
||||||
this.password = password;
|
private Short grade;
|
||||||
this.nickname = nickname;
|
|
||||||
this.email = email;
|
|
||||||
this.block = block;
|
|
||||||
this.sendEmail = sendEmail;
|
|
||||||
this.activation = activation;
|
|
||||||
this.lastResetTime = lastResetTime;
|
|
||||||
this.resetCount = resetCount;
|
|
||||||
this.otpKey = otpKey;
|
|
||||||
this.otep = otep;
|
|
||||||
this.requireReset = requireReset;
|
|
||||||
this.roles = roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserEntity() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return this.username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return this.password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNickname() {
|
|
||||||
return this.nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return this.email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getBlock() {
|
|
||||||
return this.block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getSendEmail() {
|
|
||||||
return this.sendEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getActivation() {
|
|
||||||
return this.activation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLastResetTime() {
|
|
||||||
return this.lastResetTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getResetCount() {
|
|
||||||
return this.resetCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOtpKey() {
|
|
||||||
return this.otpKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOtep() {
|
|
||||||
return this.otep;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getRequireReset() {
|
|
||||||
return this.requireReset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<RoleEntity> getRoles() {
|
|
||||||
return this.roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNickname(String nickname) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlock(Boolean block) {
|
|
||||||
this.block = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSendEmail(Boolean sendEmail) {
|
|
||||||
this.sendEmail = sendEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActivation(String activation) {
|
|
||||||
this.activation = activation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastResetTime(Date lastResetTime) {
|
|
||||||
this.lastResetTime = lastResetTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResetCount(Long resetCount) {
|
|
||||||
this.resetCount = resetCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOtpKey(String otpKey) {
|
|
||||||
this.otpKey = otpKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOtep(String otep) {
|
|
||||||
this.otep = otep;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRequireReset(Boolean requireReset) {
|
|
||||||
this.requireReset = requireReset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoles(Set<RoleEntity> roles) {
|
|
||||||
this.roles = roles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "UserEntity(username=" + this.getUsername() + ", password=" + this.getPassword() + ", nickname=" + this.getNickname() + ", email=" + this.getEmail() + ", block=" + this.getBlock() + ", sendEmail=" + this.getSendEmail() + ", activation=" + this.getActivation() + ", lastResetTime=" + this.getLastResetTime() + ", resetCount=" + this.getResetCount() + ", otpKey=" + this.getOtpKey() + ", otep=" + this.getOtep() + ", requireReset=" + this.getRequireReset() + ", roles=" + this.getRoles() + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(final Object o) {
|
|
||||||
if (o == this) return true;
|
|
||||||
if (!(o instanceof UserEntity)) return false;
|
|
||||||
final UserEntity other = (UserEntity) o;
|
|
||||||
if (!other.canEqual((Object) this)) return false;
|
|
||||||
final Object this$username = this.getUsername();
|
|
||||||
final Object other$username = other.getUsername();
|
|
||||||
if (this$username == null ? other$username != null : !this$username.equals(other$username)) return false;
|
|
||||||
final Object this$password = this.getPassword();
|
|
||||||
final Object other$password = other.getPassword();
|
|
||||||
if (this$password == null ? other$password != null : !this$password.equals(other$password)) return false;
|
|
||||||
final Object this$nickname = this.getNickname();
|
|
||||||
final Object other$nickname = other.getNickname();
|
|
||||||
if (this$nickname == null ? other$nickname != null : !this$nickname.equals(other$nickname)) return false;
|
|
||||||
final Object this$email = this.getEmail();
|
|
||||||
final Object other$email = other.getEmail();
|
|
||||||
if (this$email == null ? other$email != null : !this$email.equals(other$email)) return false;
|
|
||||||
final Object this$block = this.getBlock();
|
|
||||||
final Object other$block = other.getBlock();
|
|
||||||
if (this$block == null ? other$block != null : !this$block.equals(other$block)) return false;
|
|
||||||
final Object this$sendEmail = this.getSendEmail();
|
|
||||||
final Object other$sendEmail = other.getSendEmail();
|
|
||||||
if (this$sendEmail == null ? other$sendEmail != null : !this$sendEmail.equals(other$sendEmail)) return false;
|
|
||||||
final Object this$activation = this.getActivation();
|
|
||||||
final Object other$activation = other.getActivation();
|
|
||||||
if (this$activation == null ? other$activation != null : !this$activation.equals(other$activation))
|
|
||||||
return false;
|
|
||||||
final Object this$lastResetTime = this.getLastResetTime();
|
|
||||||
final Object other$lastResetTime = other.getLastResetTime();
|
|
||||||
if (this$lastResetTime == null ? other$lastResetTime != null : !this$lastResetTime.equals(other$lastResetTime))
|
|
||||||
return false;
|
|
||||||
final Object this$resetCount = this.getResetCount();
|
|
||||||
final Object other$resetCount = other.getResetCount();
|
|
||||||
if (this$resetCount == null ? other$resetCount != null : !this$resetCount.equals(other$resetCount))
|
|
||||||
return false;
|
|
||||||
final Object this$otpKey = this.getOtpKey();
|
|
||||||
final Object other$otpKey = other.getOtpKey();
|
|
||||||
if (this$otpKey == null ? other$otpKey != null : !this$otpKey.equals(other$otpKey)) return false;
|
|
||||||
final Object this$otep = this.getOtep();
|
|
||||||
final Object other$otep = other.getOtep();
|
|
||||||
if (this$otep == null ? other$otep != null : !this$otep.equals(other$otep)) return false;
|
|
||||||
final Object this$requireReset = this.getRequireReset();
|
|
||||||
final Object other$requireReset = other.getRequireReset();
|
|
||||||
if (this$requireReset == null ? other$requireReset != null : !this$requireReset.equals(other$requireReset))
|
|
||||||
return false;
|
|
||||||
final Object this$roles = this.getRoles();
|
|
||||||
final Object other$roles = other.getRoles();
|
|
||||||
if (this$roles == null ? other$roles != null : !this$roles.equals(other$roles)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean canEqual(final Object other) {
|
|
||||||
return other instanceof UserEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
final int PRIME = 59;
|
|
||||||
int result = 1;
|
|
||||||
final Object $username = this.getUsername();
|
|
||||||
result = result * PRIME + ($username == null ? 43 : $username.hashCode());
|
|
||||||
final Object $password = this.getPassword();
|
|
||||||
result = result * PRIME + ($password == null ? 43 : $password.hashCode());
|
|
||||||
final Object $nickname = this.getNickname();
|
|
||||||
result = result * PRIME + ($nickname == null ? 43 : $nickname.hashCode());
|
|
||||||
final Object $email = this.getEmail();
|
|
||||||
result = result * PRIME + ($email == null ? 43 : $email.hashCode());
|
|
||||||
final Object $block = this.getBlock();
|
|
||||||
result = result * PRIME + ($block == null ? 43 : $block.hashCode());
|
|
||||||
final Object $sendEmail = this.getSendEmail();
|
|
||||||
result = result * PRIME + ($sendEmail == null ? 43 : $sendEmail.hashCode());
|
|
||||||
final Object $activation = this.getActivation();
|
|
||||||
result = result * PRIME + ($activation == null ? 43 : $activation.hashCode());
|
|
||||||
final Object $lastResetTime = this.getLastResetTime();
|
|
||||||
result = result * PRIME + ($lastResetTime == null ? 43 : $lastResetTime.hashCode());
|
|
||||||
final Object $resetCount = this.getResetCount();
|
|
||||||
result = result * PRIME + ($resetCount == null ? 43 : $resetCount.hashCode());
|
|
||||||
final Object $otpKey = this.getOtpKey();
|
|
||||||
result = result * PRIME + ($otpKey == null ? 43 : $otpKey.hashCode());
|
|
||||||
final Object $otep = this.getOtep();
|
|
||||||
result = result * PRIME + ($otep == null ? 43 : $otep.hashCode());
|
|
||||||
final Object $requireReset = this.getRequireReset();
|
|
||||||
result = result * PRIME + ($requireReset == null ? 43 : $requireReset.hashCode());
|
|
||||||
final Object $roles = this.getRoles();
|
|
||||||
result = result * PRIME + ($roles == null ? 43 : $roles.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Builder
|
|
||||||
// public UserEntity(String username, String password, String nickname, String email, Date createAt, Date updateAt) {
|
|
||||||
// super(createAt, updateAt);
|
|
||||||
// this.username = username;
|
|
||||||
// this.password = password;
|
|
||||||
// this.nickname = nickname;
|
|
||||||
// this.email = email;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 아이디
|
// 아이디
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.totopia.server.modules.user.repository;
|
||||||
|
|
||||||
|
import com.totopia.server.modules.user.entity.GradeEntity;
|
||||||
|
import com.totopia.server.modules.user.type.GradeName;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface GradeRepository extends JpaRepository<GradeEntity, Long> {
|
||||||
|
Optional<GradeEntity> findByName(GradeName name);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.totopia.server.modules.user.type;
|
||||||
|
|
||||||
|
public enum GradeName {
|
||||||
|
BAD_USER, // 불량유저 등급
|
||||||
|
NORMAL_USER, // 일반유저 등급
|
||||||
|
REGULAR_USER, // 정회원 등급
|
||||||
|
VIP_USER, // VIP 등급
|
||||||
|
PLATINUM_USER // 플레티넘 등급
|
||||||
|
}
|
|
@ -1,5 +1,10 @@
|
||||||
package com.totopia.server.modules.user.type;
|
package com.totopia.server.modules.user.type;
|
||||||
|
|
||||||
public enum RoleName {
|
public enum RoleName {
|
||||||
ROLE_USER, ROLE_ADMIN, ROLE_SUPER_ADMIN,
|
ROLE_USER, // 일반 유저
|
||||||
|
ROLE_TEAM, // 팀 단위 유저
|
||||||
|
ROLE_AGENCY, // 총판
|
||||||
|
ROLE_DISTRIBUTOR, // 부본사
|
||||||
|
ROLE_ADMIN, // 사이트 관리자
|
||||||
|
ROLE_SUPER_ADMIN, // 본사 관리자 & 최고관리자
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user