hyeonga_code

reProject_07_로그인 기능 구현 본문

Project_WEATHERWEAR

reProject_07_로그인 기능 구현

hyeonga 2023. 12. 23. 06:59
반응형

2023.12.23 - [Project] - reProject_08_회원 정보 찾기 기능 구현(아이디 찾기, 비밀번호 찾기)

2023.12.21 - 2023.12.22

 

 

 

reProject_06_회원 가입 기능 구현

reProject_05_마이페이지 구현 2023-12-16 ~ 2023-12-20 커뮤니티 페이지에 구현한 방식과 동일하게 마이페이지에 적용해서 구현하려고 한다. 1. ClientGetController.java 에 페이지 호출을 위한 코드를 작성 1 2 3

hyeonga493.tistory.com

 

- 로그인 기능 구현

1. client_login.jsp 파일도 <table> 태그를 <div>, <ul> 태그로 변경

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>WEATHERWEAR</title>
    <link rel="stylesheet" href="/w2/resources/client/client_css/client_base_style.css">
    <link rel="stylesheet" href="/w2/resources/client/client_css/client_login_style.css">
</head>
<body>        
    <c:if test="${result == 1}">
        <script>
            alert("가입이 완료되었습니다. 로그인페이지로 이동합니다.");
            location.href="clientLogin.do";
        </script>
    </c:if>
    <div class="container">
        <%@ include file="/WEB-INF/views/client/base/client_header.jspf" %>
        <div class="body">
            <div class="client">
                <h2>Login</h2>
                <form action="clientLogin.do" method="post">
                    <div class="client_table">
                        <ul class="client_table_ul">
                            <li class="client_table_th">아이디 : </li>
                            <li class="client_table_td"><input type="text" name="clientId" placeholder="아이디"></li>
                        </ul>
                        <ul class="client_table_ul">
                            <li class="client_table_th">비밀번호 : </li>
                            <li class="client_table_td"><input type="password" name="clientPwd" placeholder="비밀번호"></li>
                        </ul>
                        <ul class="client_table_ul">
                            <li class="client_table_li login_btn"><input type="submit" class="btn_form" value="로 그 인"></li>
                        </ul>
                        <ul class="client_table_ul">
                            <li class="client_table_li"><input type="button" value="아이디/비밀번호 찾기" onclick="location.href='clientFindInfo.do'"></li>
                            <li class="client_table_li"><input type="button" value="회 원 가 입" onclick="location.href='clientSignup.do'"></li>
                        </ul>
                    </div>
                </form>
            </div>
        </div>
        <%@ include file="/WEB-INF/views/client/base/client_footer.jspf" %>
    </div>
</body>
</html>

 

 

2. ClientPostController.java 파일 작성

-- 아이디만 가지고 회원이 존재하면 VO에 담아 회원의 정보를 가져옴

-- 회원 정보의 비밀번호와 입력한 비밀번호가 동일한 경우 로그인 처리 > 세션으로 설정

-- 세션에 회원 정보를 모두 저장하지 않고 아이디만 저장해 보안상 문제를 처리하려고 함

/** 로그인 */
    @PostMapping("clientLogin.do")
    public String clientLogin(HttpServletRequest request) {
        System.out.println("1. [ Client Post Controller ] clientLogin");
        
        HttpSession session = request.getSession(false);
        
        String id = request.getParameter("clientId");
        String pwd = request.getParameter("clientPwd");
        System.out.println("id : " + id + ", pwd : " + pwd);
        
        ClientVO result = clientService.getClient(id);
        
        if(result != null) {
            System.out.println("4. [ Controller ] 아이디 존재");
            
            if(pwden.matches(pwd, result.getClientPwd())) {
                System.out.println("5. [ Controller ] 비밀번호 일치");
                
                session.setAttribute("session", id);
                System.out.println("6. [ Controller ] 세션 설정");
                
                /** 세션 값 확인 방법
                 * session.getAttribute("session");
                 * session.getValue("session");
                 */
               
                return "redirect:/clientMain.do";
            }
            System.out.println("5. [ Controller ] 비밀번호 불일치");
        } else {
            System.out.println("4. [ Controller ] 아이디 없음");
        }
        return "redirect:/clientLogin.do";
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.w2.client.controller;
 
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
 
import com.w2.client.ClientService;
import com.w2.client.ClientVO;
 
@Controller
public class ClientPostController {
    
    @Autowired
    private ClientService clientService;
    
    @Autowired // 비밀번호 암호화
    private BCryptPasswordEncoder pwden;
    
    /** 로그인 */
    @PostMapping("clientLogin.do")
    public String clientLogin(HttpServletRequest request) {
        System.out.println("1. [ Client Post Controller ] clientLogin");
        
        HttpSession session = request.getSession(false);
        
        String id = request.getParameter("clientId");
        String pwd = request.getParameter("clientPwd");
        System.out.println("id : " + id + ", pwd : " + pwd);
        
        ClientVO result = clientService.getClient(id);
        
        if(result != null) {
            System.out.println("4. [ Controller ] 아이디 존재");
            
            if(pwden.matches(pwd, result.getClientPwd())) {
                System.out.println("5. [ Controller ] 비밀번호 일치");
                
                session.setAttribute("session", id);
                System.out.println("6. [ Controller ] 세션 설정");
                
                /** 세션 값 확인 방법
                 * session.getAttribute("session");
                 * session.getValue("session");
                */
                
                return "redirect:/clientMain.do";
            }
            System.out.println("5. [ Controller ] 비밀번호 불일치");
        } else {
            System.out.println("4. [ Controller ] 아이디 없음");
        }
        return "redirect:/clientLogin.do";
    }
    
    /** 중복 체크 */
    @PostMapping("clientCheck.do")
    public void clientCheck(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("1. [ Client Post Controller ] clientCheck");
        
        String comp = request.getParameter("comp");
        String with = request.getParameter("checkWith");
        
        System.err.println("comp : " + comp + ", with : " + with);
        
        int check = clientService.clientCheckService(comp, with);
        
        System.out.println("5. [ Controller ] 결과 : " + check);
        
        response.setContentType("application/json");
        response.getWriter().write(String.valueOf(check));
    }
    
    /** 회원 가입 */
    @PostMapping("clientSignup.do")
    public String clientSignup(HttpServletRequest request, ClientVO client, Model model) {
        System.out.println("1. [ Client Post Controller ] clientSignup");
        System.out.println("EmailCheck : " + request.getParameter("clientEmailCheck"));
        
        // 신규 회원 기본 설정
        client.setGradeId("S");
        client.setClientPoint(3000);
        
        if(request.getParameter("clientEmailCheck"!= null) {
            client.setClientEmailCheck("Y");
        } else {
            client.setClientEmailCheck("N");
        }
        
        // 비밀번호 암호화
        client.setClientPwd(pwden.encode(client.getClientPwd()));
        
        int result = clientService.clientSignup(client);
        model.addAttribute("result", result);
        
        if(result == 1 ) {
            System.out.println("4. [ Controller ] 가입 성공");
            return "client_login";
        }
        
        System.out.println("4. [ Controller ] 가입 실패");
        return "client_signup";
    }
}

 

 

3. ClientService.java 인터페이스 작성

    // 회원정보 가져오기
    public ClientVO getClient(String id);
1
2
3
4
5
6
7
8
9
10
11
12
13
package com.w2.client;
public interface ClientService {
    
    // 중복 체크(아이디, 닉네임)
    public int clientCheckService(String comp, String with);
 
    // 회원 가입
    public int clientSignup(ClientVO client);
 
    // 회원정보 가져오기
    public ClientVO getClient(String id);
}
 

 

 

4. ClientServiceImpl.java 클래스 작성

	// 회원 정보 가져오기
	@Override
	public ClientVO getClient(String id) {
		System.out.println("2. [ Impl ] : getClient : id : " + id);

		return clientdao.getClient(id);
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.w2.client.impl;
 
import java.util.HashMap;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.w2.client.ClientDAO;
import com.w2.client.ClientService;
import com.w2.client.ClientVO;
 
@Service
public class ClientServiceImpl implements ClientService {
 
    @Autowired
    private ClientDAO clientdao;
 
    // 중복 체크(아이디, 닉네임)
    @Override
    public int clientCheckService(String comp, String with) {
        System.out.println("2. [ Impl ] : clientCheckService : " + comp + " with : " + with);
        
        HashMap<StringString> check = new HashMap<StringString>();
        check.put("comp", comp);
        check.put("with", with);
    
        int result = clientdao.clientCheck(check);
        
        if (result == 1) {
            System.out.println("4. >> clientCheck 중복 : " + result);
        } else {
            System.out.println("4. >> clientCheck 가능 : " + result);
        }
        return result;
    }
 
    // 회원 가입
    @Override
    public int clientSignup(ClientVO client) {
        System.out.println("2. [ Impl ] : clientSignup : " + client.toString());
        
        return clientdao.clientSignup(client);
        
        // 약관 동의
        
    }
 
    // 회원 정보 가져오기
    @Override
    public ClientVO getClient(String id) {
        System.out.println("2. [ Impl ] : getClient : id : " + id);
 
        return clientdao.getClient(id);
    }
}
 

 

 

5. ClientDAO.java 클래스 작성

	// 회원 정보 가져오기
	public ClientVO getClient(String clientId) {
		System.out.println("3. [ Client DAO ] getClient : " + clientId);
		
		return sqlSessionTemplate.selectOne("ClientDAO.getClient", clientId);
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.w2.client;
 
import java.util.HashMap;
 
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
import lombok.extern.slf4j.Slf4j;
 
@Repository
public class ClientDAO {
    
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    
    // 중복 확인
    public int clientCheck(HashMap<StringString> check) {
        System.out.println("3. [ Client DAO ] clientCheck : " + check.toString());
        
        return sqlSessionTemplate.selectOne("ClientDAO.checkService", check);
    }
 
    // 회원 가입
    public int clientSignup(ClientVO client) {
        System.out.println("3. [ Client DAO ] clientSignup : " + client.toString());
        
        return sqlSessionTemplate.insert("ClientDAO.clientSignup", client);
    }
 
    // 회원 정보 가져오기
    public ClientVO getClient(String clientId) {
        System.out.println("3. [ Client DAO ] getClient : " + clientId);
        
        return sqlSessionTemplate.selectOne("ClientDAO.getClient", clientId);
    }
}
 

 

 

6. client-mapping.xml 파일 작성

	<!-- 회원 정보 조회 -->
	<select id="getClient" parameterType="String" resultMap="client">
		SELECT * FROM client WHERE cId=#{ clientId }
	</select>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?xml version="1.0" encoding="UTF-8"?>
 
<!-- MyBatis 다운 파일 PDF 에서 붙여넣은 내용입니다. -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
                 
<mapper namespace="ClientDAO">
    <resultMap type="com.w2.client.ClientVO" id="client">
        <id property="clientId" column="cId" />
        <result property="clientPwd" column="cPwd" />
        <result property="clientName" column="cName" />
        <result property="clientNum" column="cNum" />
        <result property="clientEmail" column="cEmail" />
        <result property="clientEmailCheck" column="cEmailCheck" />
        <result property="clientBirth" column="cBirth" />
        <result property="clientNickName" column="cNickName" />
        <result property="gradeId" column="grId" />
        <result property="clientPoint" column="cPoint" />
        <result property="clientLogDate" column="cLogDate" />
        <result property="chPwdDate" column="chPwdDate" />
    </resultMap>
    
    <!-- 사용 가능 
    <sql id="미리 지정가능">지정하고 싶은 값 입력 가능</sql>
    <include refid="미리 지정가능"/>
    -->
    
    <!-- 정보 중복 확인 -->
    <select id="checkService" resultType="int" parameterType="Map">
        SELECT COUNT(*) FROM client
        <choose>
            <when test="#{ comp eq 'cId' }">
                WHERE cId = #{ with }
            </when>
            <when test="#{ comp eq 'cNickName' }">
                WHERE cNickName = #{ with }
            </when>
            <when test="#{ comp eq 'cEmail' }">
                WHERE cEmail = #{ with }
            </when>
        </choose>
    </select>
    
    <!-- 회원 가입 -->
    <insert id="clientSignup" parameterType="client">
        INSERT INTO client (cId, cPwd, cName, cNum, cEmail, cEmailCheck, cBirth, cNickName, grId, cPoint)
        VALUES (#{ clientId }, #{ clientPwd }, #{ clientName }, #{ clientNum }, #{ clientEmail }, #{ clientEmailCheck }, 
                #{ clientBirth }, #{ clientNickName }, #{ gradeId }, #{ clientPoint });
    </insert>
    
    <!-- 회원 정보 조회 -->
    <select id="getClient" parameterType="String" resultMap="client">
        SELECT * FROM client WHERE cId=#{ clientId }
    </select>    
</mapper>

 

 

>> 실행

 

>>> 로그인 성공 시

현재 날짜 관련 API는 연결하지 않아 날씨 정보는 출력되지 않음

 

 

-- 로그인 한 후 세션을 저장하고 최근 로그인 날짜를 사용하기 위해 세션에 정보를 저장한 후 로그인 날짜를 업데이트 하려고 함

1) ClientPostController.java

				// 최근 로그인 날짜 변경 >>> 추가
				clientService.setLogDate(id);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.w2.client.controller;
 
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
 
import com.w2.client.ClientService;
import com.w2.client.ClientVO;
 
@Controller
public class ClientPostController {
    
    @Autowired
    private ClientService clientService;
    
    @Autowired // 비밀번호 암호화
    private BCryptPasswordEncoder pwden;
    
    /** 로그인 */
    @PostMapping("clientLogin.do")
    public String clientLogin(HttpServletRequest request) {
        System.out.println("1. [ Client Post Controller ] clientLogin");
        
        HttpSession session = request.getSession(false);
        
        String id = request.getParameter("clientId");
        String pwd = request.getParameter("clientPwd");
        System.out.println("id : " + id + ", pwd : " + pwd);
        
        ClientVO result = clientService.getClient(id);
        
        if(result != null) {
            System.out.println("4. [ Controller ] 아이디 존재");
            
            if(pwden.matches(pwd, result.getClientPwd())) {
                System.out.println("5. [ Controller ] 비밀번호 일치");
                
                session.setAttribute("session", id);
                System.out.println("6. [ Controller ] 세션 설정");
                
                /** 세션 값 확인 방법
                 * session.getAttribute("session");
                 * session.getValue("session");
                 */
                
                // 최근 로그인 날짜 변경
                clientService.setLogDate(id);
                
                return "redirect:/clientMain.do";
            }
            System.out.println("5. [ Controller ] 비밀번호 불일치");
        } else {
            System.out.println("4. [ Controller ] 아이디 없음");
        }
        return "redirect:/clientLogin.do";
    }
    
    /** 중복 체크 */
    @PostMapping("clientCheck.do")
    public void clientCheck(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("1. [ Client Post Controller ] clientCheck");
        
        String comp = request.getParameter("comp");
        String with = request.getParameter("checkWith");
        
        System.err.println("comp : " + comp + ", with : " + with);
        
        int check = clientService.clientCheckService(comp, with);
        
        System.out.println("5. [ Controller ] 결과 : " + check);
        
        response.setContentType("application/json");
        response.getWriter().write(String.valueOf(check));
    }
    
    /** 회원 가입 */
    @PostMapping("clientSignup.do")
    public String clientSignup(HttpServletRequest request, ClientVO client, Model model) {
        System.out.println("1. [ Client Post Controller ] clientSignup");
        System.out.println("EmailCheck : " + request.getParameter("clientEmailCheck"));
        
        // 신규 회원 기본 설정
        client.setGradeId("S");
        client.setClientPoint(3000);
        
        if(request.getParameter("clientEmailCheck"!= null) {
            client.setClientEmailCheck("Y");
        } else {
            client.setClientEmailCheck("N");
        }
        
        // 비밀번호 암호화
        client.setClientPwd(pwden.encode(client.getClientPwd()));
        
        int result = clientService.clientSignup(client);
        model.addAttribute("result", result);
        
        if(result == 1 ) {
            System.out.println("4. [ Controller ] 가입 성공");
            return "client_login";
        }
        
        System.out.println("4. [ Controller ] 가입 실패");
        return "client_signup";
    }
}

 

 

2) ClientService.java

	// 최근 로그인 일자 저장
	public void setLogDate(String id);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package com.w2.client;
 
public interface ClientService {
    
    // 중복 체크(아이디, 닉네임)
    public int clientCheckService(String comp, String with);
 
    // 회원 가입
    public int clientSignup(ClientVO client);
 
    // 회원정보 가져오기
    public ClientVO getClient(String id);
 
    // 최근 로그인 일자 저장
    public void setLogDate(String id);
}

 

 

 

3) ClientServiceImpl.java

	// 최근 로그인 일자 저장
	@Override
	public void setLogDate(String id) {
		System.out.println("7. [ Impl ] : setLogDate");
		clientdao.setLogDate(id);
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.w2.client.impl;
 
import java.util.HashMap;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.w2.client.ClientDAO;
import com.w2.client.ClientService;
import com.w2.client.ClientVO;
 
@Service
public class ClientServiceImpl implements ClientService {
 
    @Autowired
    private ClientDAO clientdao;
 
    // 중복 체크(아이디, 닉네임)
    @Override
    public int clientCheckService(String comp, String with) {
        System.out.println("2. [ Impl ] : clientCheckService : " + comp + " with : " + with);
        
        HashMap<StringString> check = new HashMap<StringString>();
        check.put("comp", comp);
        check.put("with", with);
    
        int result = clientdao.clientCheck(check);
        
        if (result == 1) {
            System.out.println("4. >> clientCheck 중복 : " + result);
        } else {
            System.out.println("4. >> clientCheck 가능 : " + result);
        }
        return result;
    }
 
    // 회원 가입
    @Override
    public int clientSignup(ClientVO client) {
        System.out.println("2. [ Impl ] : clientSignup : " + client.toString());
        
        return clientdao.clientSignup(client);
        
        // 약관 동의
        
    }
 
    // 회원 정보 가져오기
    @Override
    public ClientVO getClient(String id) {
        System.out.println("2. [ Impl ] : getClient : id : " + id);
 
        return clientdao.getClient(id);
    }
 
    // 최근 로그인 일자 저장
    @Override
    public void setLogDate(String id) {
        System.out.println("7. [ Impl ] : setLogDate");
        clientdao.setLogDate(id);
    }
}
 

 

 

 

 

4) ClientDAO.java

	// 최근 로그인 일자 저장
	public void setLogDate(String clientId) {
		System.out.println("8. [ Client DAO ] setLogDate");
		sqlSessionTemplate.update("ClientDAO.setLogDate", clientId);
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.w2.client;
 
import java.util.HashMap;
 
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
import lombok.extern.slf4j.Slf4j;
 
@Repository
public class ClientDAO {
    
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    
    // 중복 확인
    public int clientCheck(HashMap<StringString> check) {
        System.out.println("3. [ Client DAO ] clientCheck : " + check.toString());
        
        return sqlSessionTemplate.selectOne("ClientDAO.checkService", check);
    }
 
    // 회원 가입
    public int clientSignup(ClientVO client) {
        System.out.println("3. [ Client DAO ] clientSignup : " + client.toString());
        
        return sqlSessionTemplate.insert("ClientDAO.clientSignup", client);
    }
 
    // 회원 정보 가져오기
    public ClientVO getClient(String clientId) {
        System.out.println("3. [ Client DAO ] getClient : " + clientId);
        
        return sqlSessionTemplate.selectOne("ClientDAO.getClient", clientId);
    }
 
    // 최근 로그인 일자 저장
    public void setLogDate(String clientId) {
        System.out.println("8. [ Client DAO ] setLogDate");
        sqlSessionTemplate.update("ClientDAO.setLogDate", clientId);
    }
}
 

 

 

 

 

5) client-mapping.xml

	<!-- 마지막 로그인 일자 업데이트 -->
	<update id="setLogDate" parameterType="String">
		UPDATE client SET cLogDate = CURRENT_TIMESTAMP WHERE cId = #{ clientId }
	</update>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0" encoding="UTF-8"?>
 
<!-- MyBatis 다운 파일 PDF 에서 붙여넣은 내용입니다. -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
                 
<mapper namespace="ClientDAO">
    <resultMap type="com.w2.client.ClientVO" id="client">
        <id property="clientId" column="cId" />
        <result property="clientPwd" column="cPwd" />
        <result property="clientName" column="cName" />
        <result property="clientNum" column="cNum" />
        <result property="clientEmail" column="cEmail" />
        <result property="clientEmailCheck" column="cEmailCheck" />
        <result property="clientBirth" column="cBirth" />
        <result property="clientNickName" column="cNickName" />
        <result property="gradeId" column="grId" />
        <result property="clientPoint" column="cPoint" />
        <result property="clientLogDate" column="cLogDate" />
        <result property="chPwdDate" column="chPwdDate" />
    </resultMap>
    
    <!-- 사용 가능 
    <sql id="미리 지정가능">지정하고 싶은 값 입력 가능</sql>
    <include refid="미리 지정가능"/>
    -->
    
    <!-- 정보 중복 확인 -->
    <select id="checkService" resultType="int" parameterType="Map">
        SELECT COUNT(*) FROM client
        <choose>
            <when test="#{ comp eq 'cId' }">
                WHERE cId = #{ with }
            </when>
            <when test="#{ comp eq 'cNickName' }">
                WHERE cNickName = #{ with }
            </when>
            <when test="#{ comp eq 'cEmail' }">
                WHERE cEmail = #{ with }
            </when>
        </choose>
    </select>
    
    <!-- 회원 가입 -->
    <insert id="clientSignup" parameterType="client">
        INSERT INTO client (cId, cPwd, cName, cNum, cEmail, cEmailCheck, cBirth, cNickName, grId, cPoint)
        VALUES (#{ clientId }, #{ clientPwd }, #{ clientName }, #{ clientNum }, #{ clientEmail }, #{ clientEmailCheck }, 
                #{ clientBirth }, #{ clientNickName }, #{ gradeId }, #{ clientPoint });
    </insert>
    
    <!-- 회원 정보 조회 -->
    <select id="getClient" parameterType="String" resultMap="client">
        SELECT * FROM client WHERE cId=#{ clientId }
    </select>
    
    <!-- 마지막 로그인 일자 업데이트 -->
    <update id="setLogDate" parameterType="String">
        UPDATE client SET cLogDate = CURRENT_TIMESTAMP WHERE cId = #{ clientId }
    </update>
</mapper>

 

-- 추후 로그인 시 마지막 로그인 일자 잠시 출력하려고 함

 

 

 

reProject_08_회원 정보 찾기 기능 구현(아이디 찾기, 비밀번호 찾기)

2023.12.23 - [Project] - reProject_07_로그인 기능 구현 2023.12.21 - 2023.12.22 기존에 작업했던 form action 방식이 아닌 ajax로 처리 1.client_findInfo.jsp 수정 : 태그 수정 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2

hyeonga493.tistory.com

 

반응형