[C-3-3] 회원가입
2020. 1. 21. 23:00ㆍProject C (SBMS)/Project C 파트3
반응형
회원가입(Sign Up) 버튼을 클릭 시 회원가입 페이지로 이동해서 사용자 아이디, 비밀번호, 사용자 명을 입력해서 회원가입 처리를 할 수 있다.
회원가입 페이지
views
customSignup.jsp
더보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ include file="includes/header.jsp"%>
<div style="margin : 200px 600px 100px 600px;">
<form role="form" method='post' action="/sbms/customSignup">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="사용자 아이디" id="user_id" name="userid" type="text" autofocus="autofocus" required="required" >
</div>
<div class="form-group">
<input class="form-control" placeholder="비밀번호"
name="userpw" id="userpw" type="password" value="" required="required">
</div>
<div class="form-group">
<input class="form-control" placeholder="사용자 명" name="userName" id="user_name" type="text" value="" required="required">
</div>
<!-- Change this to a button or input when using this as a form -->
<a href="#" class="btn btn-lg btn-primary btn-block" id="sign-up-btn">Set Up Your Account</a>
</fieldset>
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
</div>
<!-- jQuery -->
<script src="/sbms/resources/vendor/jquery/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="/sbms/resources/vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="/sbms/resources/vendor/metisMenu/metisMenu.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="/sbms/resources/dist/js/sb-admin-2.js"></script>
<script>
$("#sign-up-btn").on("click", function(e){
/* 폼 유효성 검사 */
if($("#user_id").val() === ""){
alert("아이디를 입력해주세요.");
$("#user_id").focus();
return;
}else if($("#userpw").val() === ""){
alert("패스워드를 입력해주세요.");
$("#userpw").focus();
return;
}else if($("#user_name").val() === ""){
alert("사용자 명을 입력해주세요.");
$("#user_name").focus();
return;
}
e.preventDefault();
$("form").submit();
alert("회원가입을 축하드립니다.");
});
</script>
</body>
</html>
src/main/java
com.sbms.controller
CommonController.java
더보기
package com.sbms.controller;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.sbms.domain.MemberVO;
import com.sbms.service.CommonService;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j;
@Controller
@Log4j
@AllArgsConstructor
public class CommonController {
private CommonService commonService;
@GetMapping("/accessError")
public void accessDenied(Authentication auth, Model model) {
log.info("access Denied : " + auth);
model.addAttribute("msg", "Access Denied");
}
@GetMapping("/customLogin")
public void loginInput(String error, String logout, Model model) {
log.info("error: " + error);
log.info("logout: " + logout);
if (error != null) {
model.addAttribute("error", "Login Error Check Your Account");
}
if (logout != null) {
model.addAttribute("logout", "Logout!!");
}
}
@GetMapping("/customLogout")
public void logoutGET() {
log.info("custom logout");
}
@PostMapping("/customLogout")
public void logoutPost() {
log.info("post custom logout");
}
@GetMapping("/customSignup")
public void signupGET() {
log.info("회원가입 폼");
}
@PostMapping("/customSignup")
public String signupPOST(MemberVO member, RedirectAttributes rttr) {
log.info("[ MEMBER ] 1 : " + member);
commonService.customSignup(member);
rttr.addFlashAttribute("result", member.getUserName());
return "redirect:/board/list";
}
}
src/main/java
com.sbms.service
CommonService.java 인터페이스
더보기
package com.sbms.service;
import com.sbms.domain.MemberVO;
public interface CommonService {
public void customSignup(MemberVO member);
}
src/main/java
com.sbms.service
CommonServiceImpl.java
더보기
package com.sbms.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sbms.domain.MemberVO;
import com.sbms.mapper.MemberMapper;
import lombok.AllArgsConstructor;
import lombok.Setter;
import lombok.extern.log4j.Log4j;
@Log4j
@Service
@AllArgsConstructor
public class CommonServiceImpl implements CommonService {
@Setter(onMethod_ = @Autowired)
private PasswordEncoder pwEncoder;
private MemberMapper memberMapper;
@Transactional
@Override
public void customSignup(MemberVO member) {
member.setUserpw(pwEncoder.encode(member.getUserpw()));
log.info("User Sec PW" + member.getUserpw());
memberMapper.createMember(member);
memberMapper.createMemberAuth(member);
}
}
src/main/java
com.sbms.mapper
MemberMapper.java
더보기
package com.sbms.mapper;
import com.sbms.domain.MemberVO;
public interface MemberMapper {
public MemberVO read(String userid);
public void createMember(MemberVO member);
public void createMemberAuth(MemberVO member);
}
src/main/resources
com
sbms
mapper
MemberMapper.java
더보기
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sbms.mapper.MemberMapper">
<resultMap type="com.sbms.domain.MemberVO" id="memberMap">
<id property="userid" column="userid"/>
<result property="userid" column="userid"/>
<result property="userpw" column="userpw"/>
<result property="userName" column="username"/>
<result property="regDate" column="regdate"/>
<result property="updateDate" column="updatedate"/>
<collection property="authList" resultMap="authMap">
</collection>
</resultMap>
<resultMap type="com.sbms.domain.AuthVO" id="authMap">
<result property="userid" column="userid"/>
<result property="auth" column="auth"/>
</resultMap>
<select id="read" resultMap="memberMap">
SELECT
mem.userid, userpw, username, enabled, regdate, updatedate, auth
FROM
tbl_member mem LEFT OUTER JOIN tbl_member_auth auth on mem.userid = auth.userid
WHERE mem.userid = #{userid}
</select>
<!-- 등록 (회원) -->
<insert id="createMember">
insert into tbl_member (
USERID, USERPW, USERNAME, REGDATE, UPDATEDATE, ENABLED
)
values (
#{userid}, #{userpw}, #{userName}, SYSDATE, SYSDATE, '1'
)
</insert>
<!-- 등록 (회원 권한) -->
<insert id="createMemberAuth">
insert into TBL_MEMBER_AUTH (
USERID, AUTH
) values (
#{userid}, 'ROLE_USER'
)
</insert>
</mapper>
회원가입 페이지
회원가입 처리 후의 화면
가입 후의 데이터베이스에 저장된 계정
비밀번호는 암호화되기때문에, 알 수가 없다.
반응형
'Project C (SBMS) > Project C 파트3' 카테고리의 다른 글
[C-3-5] 게시물 작성 시 스프링 시큐리티 처리 (0) | 2020.01.22 |
---|---|
[C-3-4] 로그아웃 (0) | 2020.01.21 |
[C-3-2] 스프링 웹 시큐리티를 이용한 로그인 처리 2 (0) | 2020.01.21 |
[C-3-1] 스프링 웹 시큐리티를 이용한 로그인 처리 (0) | 2020.01.21 |