Просмотр исходного кода

카카오 기존 회원 연동 및 신규 가입 기능 추가

jsshin 5 лет назад
Родитель
Сommit
a2dcee91f3

+ 11 - 10
src/main/java/com/style24/front/biz/service/TsfCustomerService.java

@@ -118,7 +118,7 @@ public class TsfCustomerService {
 	 * @author jsshin
 	 * @since 2021. 02. 15
 	 */
-	public boolean getCustomerFindByCustId(String custId) {
+	public boolean getCustomerFindByCustIdCount(String custId) {
 		Customer customer = new Customer();
 		customer.setCustId(custId);
 		customer.setSiteCd(TscConstants.Site.STYLE24.value());
@@ -136,7 +136,7 @@ public class TsfCustomerService {
 	 * @author jsshin
 	 * @since 2021. 02. 15
 	 */
-	public boolean getCustomerFindByEmail(String email) {
+	public boolean getCustomerFindByEmailCount(String email) {
 		Customer customer = new Customer();
 		customer.setEmail(email);
 		customer.setSiteCd(TscConstants.Site.STYLE24.value());
@@ -284,7 +284,6 @@ public class TsfCustomerService {
 		boolean isJoin = true;
 		customer.setEncodedPasswd(" ");
 		customer.setCustId(customer.getSnsType()+"_"+customer.getSnsId());
-		customer.setEncodedPasswd(passwordEncoder.encode(customer.getPasswd()));
 		customer.encryptData();
 
 		String gender = "G007_"+customer.getSexGb();
@@ -350,17 +349,19 @@ public class TsfCustomerService {
 		custInfo = getCustomerFindByCi(custSnsInfo.getCi());
 
 		if (custInfo != null) { // 2-1. 고객정보 있는경우
+
 			if (TscConstants.CustStat.SECEDE.value().equals(custInfo.getCustStat())) {
 				resultMap.setString("custStat", "SECEDE_CUST"); // 탈퇴 회원
 				return resultMap;
 			}
+
 			if (TscConstants.CustStat.DORMANT.value().equals(custInfo.getCustStat())) {
 				resultMap.setString("custStat", "DORMANT_CUST"); // 휴면 회원
 				return resultMap;
 			}
-			if (TscConstants.CustStat.ACTIVE.value().equals(custInfo.getCustStat())) {
 
-				if (StringUtils.isBlank(custSnsInfo.getCellPhnno())) {
+			if (TscConstants.CustStat.ACTIVE.value().equals(custInfo.getCustStat())) {
+				if (StringUtils.isBlank(custSnsInfo.getCellPhnno())) { // 휴대폰 정보가 없음 - 회원가입 페이지 이동(ID/PW 제외)
 					resultMap.setString("custStat", "EMPTY_PHONE_CUST");
 					return resultMap;
 				}
@@ -370,6 +371,7 @@ public class TsfCustomerService {
 				resultMap.setString("custStat", "SUCC_CUST");
 				return resultMap;
 			}
+
 		} else { // 2-2. 고객정보 없는 경우
 
 			if (StringUtils.isBlank(custSnsInfo.getCellPhnno())) { // 휴대전화번호가 없는 경우
@@ -377,24 +379,23 @@ public class TsfCustomerService {
 				return resultMap;
 			}
 
-			boolean isFindByPhone =getCustomerFindByCellPhnnoCount(custSnsInfo.getCellPhnno().replace("-",""));
+			boolean isFindByPhone = getCustomerFindByCellPhnnoCount(custSnsInfo.getCellPhnno().replace("-",""));
 			if (isFindByPhone) {
-				resultMap.setString("custStat", "DUP_PHONE_CUST");
+				resultMap.setString("custStat", "DUP_PHONE_CUST"); // 휴대폰 중복
 				return resultMap;
 			}
 
-			boolean isFindByEmail = getCustomerFindByEmail(custSnsInfo.getEmail());
+			boolean isFindByEmail = getCustomerFindByEmailCount(custSnsInfo.getEmail());
 			if (isFindByEmail) {
 				resultMap.setString("custStat", "DUP_EMAIL_CUST"); // 이메일 중복
 				return resultMap;
 			}
 
 			Customer customer = objectMapper.convertValue(custSnsInfo, Customer.class);
-
 			boolean isJoin = saveJoinCustomerSns(customer);
-
 			if (isJoin) {
 				resultMap.setString("custStat", "SUCC_CUST");
+				resultMap.setString("gb", "NEW");
 			} else {
 				resultMap.setString("custStat", "FAIL_CUST");
 			}

+ 10 - 2
src/main/java/com/style24/front/biz/thirdparty/KaKaoLogin.java

@@ -25,6 +25,7 @@ import org.springframework.web.client.RestTemplate;
 import javax.annotation.PostConstruct;
 import java.net.URI;
 import java.util.Locale;
+import java.util.UUID;
 
 
 /**
@@ -162,7 +163,7 @@ public class KaKaoLogin {
 			HttpHeaders headers = new HttpHeaders();
 			headers.set("Authorization", "Bearer " + accessToken);
 			headers.add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
-			HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(params, headers);
+			HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
 			URI url = URI.create(userInfoUrl);
 
 			// POST방식으로 호출
@@ -193,10 +194,17 @@ public class KaKaoLogin {
 				birthSm = kakaoAccount.getString("birthday_type").equals("SOLAR") ? "S":"L";
 			}
 
+			// TODO: 정식 카카오 로그인 정식 서비스되면 해당 내용 삭제 해야 함 2021.02.25 jsshin
+			String ci = kakaoAccount.getString("ci");
+			if (StringUtils.isBlank(ci)) {
+				//ci = "LU9VuATNfK86YTDEsHvOGO5hOhgfHYlaj6rWKGZXPGJtBK4IHlFx/+tbBFrbYMjYUSzI9RCQHygvBwaqKS/tNA=="; // jsshin6246 CI값
+				ci = UUID.randomUUID().toString().replaceAll("-","");
+			}
+
 			resultMap.setString("snsId", obj.get("id").toString());
 			resultMap.setString("custNm", properties.getString("nickname"));
 			resultMap.setString("email", kakaoAccount.getString("email"));
-			resultMap.setString("ci", kakaoAccount.getString("ci"));
+			resultMap.setString("ci", ci);
 			resultMap.setString("cellPhnno", cellPhnno);
 			resultMap.setString("birthYmd", birthYmd);
 			resultMap.setString("birthSm", birthSm);

+ 2 - 2
src/main/java/com/style24/front/biz/web/TsfCustomerController.java

@@ -475,7 +475,7 @@ public class TsfCustomerController extends TsfBaseController {
 			throw new IllegalStateException("확인 할 아이디가 없습니다.");
 		}
 
-		boolean isFind  = customerService.getCustomerFindByCustId(customer.getCustId());
+		boolean isFind  = customerService.getCustomerFindByCustIdCount(customer.getCustId());
 
 		result.setBoolean("isFind", isFind);
 		return result;
@@ -498,7 +498,7 @@ public class TsfCustomerController extends TsfBaseController {
 			throw new IllegalStateException("확인 할 이메일이 없습니다.");
 		}
 
-		boolean isFind = customerService.getCustomerFindByEmail(customer.getEmail());
+		boolean isFind = customerService.getCustomerFindByEmailCount(customer.getEmail());
 
 		result.setBoolean("isFind", isFind);
 

+ 7 - 2
src/main/java/com/style24/front/biz/web/TsfIndexController.java

@@ -265,6 +265,13 @@ public class TsfIndexController extends TsfBaseController {
 			CustSnsInfo custSnsInfo = objectMapper.convertValue(userInfo, CustSnsInfo.class);
 			//상태 체크
 			resultMap = customerService.customerSnsProcessing(custSnsInfo);
+			resultMap.setString("snsId", custSnsInfo.getSnsId());
+			resultMap.setString("snsType", custSnsInfo.getSnsType());
+
+			String gb = resultMap.getString("gb");
+			if (StringUtils.isNotBlank(gb) && gb.equals("NEW")) {
+				//TODO : 신규가입 메일 발송, 알림톡 발송 2021.02.25 jsshin
+			}
 
 		}
 
@@ -274,8 +281,6 @@ public class TsfIndexController extends TsfBaseController {
 		}
 
 		mav.addObject("resultMap", resultMap);
-		mav.addObject("snsId", userInfo.getString("snsId"));
-		mav.addObject("snsType", snsType);
 
 		mav.setViewName(super.getDeviceViewName("SnsCallBackForm"));
 

+ 2 - 9
src/main/java/com/style24/front/support/security/TsfAuthenticationProvider.java

@@ -60,9 +60,8 @@ public class TsfAuthenticationProvider implements AuthenticationProvider {
 
 		// SNS로그인이면
 		if (loginId.startsWith(TsfConstants.SNSLOGIN_PREFIX)) {
-			loginParam.setCustId(GagaStringUtil.replace(loginId, TsfConstants.SNSLOGIN_PREFIX, ""));
-			loginParam.setSnsType(loginId.substring(loginId.indexOf("-", 0) + 1, loginId.lastIndexOf("-") - 1));
-			loginParam.setEmail(passwd); // SNS로그인이면 이메일 정보
+			loginParam.setSnsId(GagaStringUtil.replace(loginId, TsfConstants.SNSLOGIN_PREFIX, ""));
+			loginParam.setSnsType(passwd);
 		} else { // 일반로그인
 			loginParam.setCustId(loginId);
 		}
@@ -90,12 +89,6 @@ public class TsfAuthenticationProvider implements AuthenticationProvider {
 			if (!isMatch) {
 				throw new BadCredentialsException(message.getMessage("LOGN_0002"));
 			}
-		} else {
-			// SNS로그인 시 로그인ID 값은 이메일로 처리했으므로
-			// loginId 값과 회원정보의 이메일 값을 비교해서 동일하면
-			if (StringUtils.isBlank(loginInfo.getSnsType()) && passwd.equals(loginInfo.getEmail())) {
-				throw new TsfEmailDuplicationException(message.getMessage("LOGN_0008"));
-			}
 		}
 
 		if (loginInfo.getCustStat().equals("20")) { // 휴면회원

+ 4 - 4
src/main/java/com/style24/front/support/security/filter/TsfAuthenticationFilter.java

@@ -32,10 +32,10 @@ public class TsfAuthenticationFilter extends UsernamePasswordAuthenticationFilte
 
 		if (StringUtils.isNotBlank(loginParams.getString("snsType"))) { // SNS로그인
 			// SNS로그인일 때는
-			// 로그인ID: SNS_TYPE-SNS_JOIN_ID
-			// 비밀번호: 이메일
-			loginParams.setString("loginId", loginParams.getString("snsType") + "-" + loginParams.getString("snsJoinId"));
-			loginParams.setString("passwd", loginParams.getString("email")); // SNS로그인 시 이메일체크를 위해 추가
+			// 로그인ID: SNSLOGIN_PREFIX-SNS_ID
+			// 패스워드 : SNS 타입
+			loginParams.setString("loginId", loginParams.getString("snsId"));
+			loginParams.setString("passwd", loginParams.getString("snsType"));
 		} else { // 일반로그인
 			if (StringUtils.isNotBlank(loginParams.getString("loginId"))) {
 				loginParams.setString("loginId", loginParams.getString("loginId").trim());

+ 1 - 1
src/main/java/com/style24/persistence/domain/Login.java

@@ -32,7 +32,7 @@ public class Login extends TscBaseDomain {
 	private String custStat;		// 고객상태
 	private String email;			// 이메일
 	private String snsType;			// SNS유형
-	private String snsJoinId;		// SNS가입ID
+	private String snsId;			// SNS가입ID
 	private int loginFailCnt;		// 로그인실패건수
 	private int blockSecs;			// 로그인블락시간(초)
 	private String siteCd;			// 가입사이트코드(공통코드G000)

+ 1 - 1
src/main/java/com/style24/persistence/mybatis/shop/TsfCustomer.xml

@@ -224,7 +224,7 @@
 		     , #{custGb}                           AS CUST_GB
 		     , #{custGrade}                        AS CUST_GRADE
 		     , NOW()                               AS JOIN_DT
-		     , #{foreignerYn}                      AS FOREIGNER_YN
+		     , IFNULL(#{foreignerYn}, 'N')         AS FOREIGNER_YN
 		     , #{custStat}                         AS CUST_STAT
 		     , #{passwdChgDt}                      AS PASSWD_CHG_DT
 		     , 'N'                                 AS TEMP_PASSWD_YN

+ 8 - 6
src/main/java/com/style24/persistence/mybatis/shop/TsfLogin.xml

@@ -14,7 +14,7 @@
 		     , CUST_STAT                                        /*회원상태*/
 		     , EMAIL                                            /*이메일*/
 		     , #{snsType}                     AS SNS_TYPE       /*SNS유형*/
-		     , ''                             AS JOIN_ID         /*SNS가입ID*/
+		     , #{snsId}                       AS SNS_ID         /*SNS가입ID*/
 		     , IFNULL((SELECT LOGIN_FAIL_CNT
 		               FROM   TB_LOGIN_FAIL
 		               WHERE  CUST_ID = #{custId}
@@ -24,11 +24,13 @@
 		FROM   TB_CUSTOMER A
 		WHERE  1 = 1
 		<choose>
-		    <when test="snsType == 'NV'"> <!-- SNS로그인:네이버 -->
-		    </when>
-		    <when test="snsType == 'KK'"> <!-- SNS로그인:카카오 -->
-		    </when>
-		    <when test="snsType == 'YS'"> <!-- SNS로그인:YES24 -->
+		    <when test="snsType != null and snsType != ''"> <!-- SNS 로그인  -->
+		AND CUST_NO = (
+		               SELECT CUST_NO
+		               FROM TB_CUSTOMER_SNS
+		               WHERE SNS_TYPE = #{snsType}
+		               AND   SNS_ID = #{snsId}
+		               )
 		    </when>
 		    <otherwise> <!-- 일반로그인 -->
 		AND    CUST_ID = #{custId}

+ 39 - 10
src/main/webapp/WEB-INF/views/web/SigninFormWeb.html

@@ -233,16 +233,45 @@
 
 	// SNS 로그인 콜백함수
 	var fnSnsSigninCallback = function(userInfo) {
-		console.log('userInfo', userInfo);
-		let params = {};
-		params.snsType = userInfo.snsType;
-		params.snsJoinId = [[${snsLoginPrefix}]] + userInfo.snsId;
-		// $.post(_frontUrl + '/login'
-		// 	, $.param(params)
-		// 	, function(result) {
-		// 		fnReloadAfterLogin(result);
-		// 	}
-		// 	, "json");
+		// Ci이 조회 시 없음
+		if (userInfo.custStat === 'DUP_PHONE_CUST') {
+			mcxDialog.alert("이미 사용 중인 휴대전화번호 입니다.");
+			return;
+		}
+		if (userInfo.custStat === 'DUP_EMAIL_CUST') {
+			mcxDialog.alert("이미 사용 중인 이메일 입니다.");
+			return;
+		}
+		if (userInfo.custStat === 'EMPTY_PHONE_CUST') {
+			cfnGoToPage(_PAGE_CUSTOMER_SNS_JOIN);
+		}
+		// Ci이 조회 시 있음
+		if (userInfo.custStat === 'SECEDE_CUST') {
+			mcxDialog.alert("탈퇴 회원 입니다.");
+			return;
+		}
+		if (userInfo.custStat === 'DORMANT_CUST') {
+			cfnGoToPage(_PAGE_CUSTOMER_DORMANT);
+		}
+
+		if (userInfo.custStat === 'FAIL_CUST') {
+			mcxDialog.alert("회원가입에 실패 했습니다.<br> 고객센터에 문의 하시기 바랍니다.");
+			return;
+		}
+
+		if (userInfo.custStat === 'SUCC_CUST') {
+			let params = {};
+			params.snsType = userInfo.snsType;
+			params.snsId = [[${snsLoginPrefix}]] + userInfo.snsId;
+			$.post(_frontUrl + '/login'
+				, $.param(params)
+				, function(result) {
+					fnReloadAfterLogin(result);
+				}
+				, "json");
+		}
+
+
 	};
 
 	var fnReloadAfterLogin = function(result) {

+ 13 - 15
src/main/webapp/WEB-INF/views/web/SnsCallBackFormWeb.html

@@ -22,21 +22,19 @@
 
 <script th:inline="javascript">
 /*<![CDATA[*/
-	const snsType = [[${snsType}]];
-	const snsId = [[${snsId}]];
-
-	if (snsType === 'KK') {
-		if (gagajf.isNull(snsId)){
-			mcxDialog.alertC("인증에 실패하였습니다.<br> 로그인 정보를 확인해주시기 바랍니다.", {
-				sureBtnText: "확인",
-				sureBtnClick: function() {
-					self.close();
-				}
-			});
-		} else {
-			opener.fnSnsSigninCallback(snsId);
-			self.close();
-		}
+	const resultMap = [[${resultMap}]];
+
+
+	if (gagajf.isNull(resultMap.snsId) && gagajf.isNull(resultMap.snsType)){
+		mcxDialog.alertC("인증에 실패하였습니다.<br> 로그인 정보를 확인해주시기 바랍니다.", {
+			sureBtnText: "확인",
+			sureBtnClick: function() {
+				self.close();
+			}
+		});
+	} else {
+		opener.fnSnsSigninCallback(resultMap);
+		self.close();
 	}