회원가입, 로그인 기능 구현

강석 최 2022-08-19 11:04:38 +09:00
parent 4a09177800
commit f6ed78269b
6 changed files with 38 additions and 21 deletions

View File

@ -5,6 +5,7 @@ import com.dbnt.faisp.service.CommonCodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@ -22,8 +23,6 @@ public class BaseController {
if(loginUser == null){
mav = new ModelAndView("redirect:/login");
}else{
session.setAttribute("positionList", commonCodeService.selectCommonCodeValue("POSITION"));
session.setAttribute("departmentList", commonCodeService.selectCommonCodeValue("DEPARTMENT"));
if(loginUser.getUserRole().indexOf("ADMIN")>0){
mav = new ModelAndView("redirect:/admin/main");
}else{

View File

@ -0,0 +1,24 @@
package com.dbnt.faisp.controller;
import com.dbnt.faisp.model.UserInfo;
import com.dbnt.faisp.service.CommonCodeService;
import com.dbnt.faisp.service.UserInfoService;
import lombok.RequiredArgsConstructor;
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.RestController;
import org.springframework.web.servlet.ModelAndView;
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserInfoController {
private final UserInfoService userInfoService;
@PostMapping("/insertUserInfo")
public String insertUserInfo(UserInfo insertReqInfo) {
return userInfoService.insertUserInfo(insertReqInfo);
}
}

View File

@ -21,27 +21,21 @@ import java.util.Set;
@NoArgsConstructor
@DynamicInsert
@DynamicUpdate
@Table(name = "USER_INFO")
@Table(name = "user_info")
public class UserInfo extends BaseModel implements UserDetails{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "USER_SEQ")
@Column(name = "user_seq")
private Integer userSeq;
@Column(name = "USER_ID")
@Column(name = "user_id")
private String userId;
@Column(name = "PASSWORD")
@Column(name = "passwd")
private String password;
@Column(name = "NAME")
@Column(name = "name")
private String name;
@Column(name = "POSITION")
private Integer position;
@Column(name = "DEPARTMENT")
private Integer department;
@Column(name = "USER_ROLE")
@Column(name = "user_role")
private String userRole;
@Column(name = "CREATE_DATE", updatable = false)
private LocalDateTime createDate;
@Column(name = "USER_STATUS")
@Column(name = "user_status")
private String userStatus;
@Transient
@ -82,6 +76,6 @@ public class UserInfo extends BaseModel implements UserDetails{
@Override
public boolean isEnabled() {
return userStatus.equals("T");
return userStatus.equals("ST002");
}
}

View File

@ -1,5 +1,6 @@
package com.dbnt.faisp.service;
import com.dbnt.faisp.config.Role;
import com.dbnt.faisp.mapper.UserInfoMapper;
import com.dbnt.faisp.model.UserInfo;
import com.dbnt.faisp.repository.UserInfoRepository;
@ -25,6 +26,8 @@ public class UserInfoService implements UserDetailsService {
if(userInfoRepository.findByUserId(userInfo.getUserId()).orElse(null) != null){
return "userIdDuplication";
}
userInfo.setUserRole(Role.USER.getValue());
userInfo.setUserStatus("ST001");
userInfo.setPassword(convertPassword(userInfo.getPassword()));
return userInfoRepository.save(userInfo).getUserId();
}
@ -35,8 +38,6 @@ public class UserInfoService implements UserDetailsService {
targetUserInfo.setPassword(convertPassword(userInfo.getPassword()));
}
targetUserInfo.setName(userInfo.getName());
targetUserInfo.setPosition(userInfo.getPosition());
targetUserInfo.setDepartment(userInfo.getDepartment());
targetUserInfo.setUserRole(userInfo.getUserRole());
targetUserInfo.setUserStatus(userInfo.getUserStatus());
return targetUserInfo.getUserId();

View File

@ -5,11 +5,10 @@ $(document).on('click', '#saveBtn', function (){
if(confirm("저장하시겠습니까?")){
contentFade("in");
const formData = new FormData($("#userInfoInsert")[0]);
debugger
$.ajax({
type : 'POST',
data : formData,
url : "/admin/insertUserInfo",
url : "/user/insertUserInfo",
processData: false,
contentType: false,
success : function(result) {

View File

@ -16,7 +16,7 @@
<h2>반갑습니다</h2>
<p>이곳은 외사정보시스템입니다</p>
</div>
<form action="/user/login" method="post">
<form action="/login" method="post">
<!-- Spring Security가 적용되면 POST 방식으로 보내는 모든 데이터는 csrf 토큰 값이 필요 -->
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>