Jelajahi Sumber

네이버 카카오 회원 가입 기능 추가

jsshin 5 tahun lalu
induk
melakukan
dcc772f38d

+ 7 - 1
src/main/java/com/style24/front/biz/dao/TsfCustomerDao.java

@@ -58,6 +58,12 @@ public interface TsfCustomerDao {
 	 */
 	Customer getCusomterActiveAndDormant(Customer customer);
 
-
+	/**
+	 * SNS 정보로 고객 테이블 조회
+	 * @param custSnsInfo - 고객정보
+	 * @return 고객정보
+	 * @author jsshin
+	 * @since 2021. 02. 24
+	 */
 	Customer getCusomterSnsFind(CustSnsInfo custSnsInfo);
 }

+ 99 - 13
src/main/java/com/style24/front/biz/service/TsfCustomerService.java

@@ -160,6 +160,26 @@ public class TsfCustomerService {
 		customer.setHypenCellPhone(); // 010-0000-0000
 		customer.setSiteCd(TscConstants.Site.STYLE24.value());
 		customer.encryptData();
+
+		int result = customerDao.getCustomerInfoCount(customer);
+
+		return result > 0;
+	}
+
+	/**
+	 * 해당 CI로 가입된 이력이 있는지 확인
+	 * @param ci - 연계정보
+	 * @return boolean - 있으면 TRUE/ 없으면 FALSE
+	 * @author jsshin
+	 * @since 2021. 02. 15
+	 */
+	public boolean getCustomerFindByCiCount(String ci) {
+		TscSession.setAttribute("maskingYn","Y");
+		Customer customer = new Customer();
+		customer.setCi(ci);
+		customer.setSiteCd(TscConstants.Site.STYLE24.value());
+		customer.encryptData();
+
 		int result = customerDao.getCustomerInfoCount(customer);
 
 		return result > 0;
@@ -284,10 +304,10 @@ public class TsfCustomerService {
 		boolean isJoin = true;
 		customer.setEncodedPasswd(" ");
 		customer.setCustId(customer.getSnsType()+"_"+customer.getSnsId());
-		customer.encryptData();
-
 		String gender = "G007_"+customer.getSexGb();
 		customer.setSexGb(gender);
+		customer.encryptData();
+
 		customer.setSiteCd(TscConstants.Site.STYLE24.value());
 		customer.setFrontGb(TsfSession.getFrontGb());
 		customer.setAfLinkCd(TsfSession.getAttribute("afLinkCd"));
@@ -295,11 +315,13 @@ public class TsfCustomerService {
 		customer.setCustGb(TscConstants.CustGb.NORMAL.value());
 		customer.setCustGrade(TscConstants.CustGrade.WELCOME.value());
 
+
 		int custCnt = customerDao.createCustomer(customer);
 		customerDao.createCustomerSns(customer);
 
 		if (custCnt > 0) {
 			saveJoinPostProcessing(customer);
+			TsfSession.setAttribute("custNo", String.valueOf(customer.getCustNo()));
 		} else {
 			isJoin = false;
 		}
@@ -329,7 +351,8 @@ public class TsfCustomerService {
 
 	/**
 	 * Sns 정보에대한 상태 처리
-	 * @param custSnsInfo
+	 *
+	 * @param custSnsInfo - SNS 고객 정보
 	 * @author jsshin
 	 * @since 2021. 02. 19
 	 */
@@ -345,7 +368,11 @@ public class TsfCustomerService {
 			return resultMap;
 		}
 
-		// 2. CI(연계정보)로 가입 되어져 있는 고객이 있는지 ?
+		if (StringUtils.isBlank(custSnsInfo.getCi())) {
+			throw new IllegalStateException("연계정보 값이 없습니다. 고객센터에 문의하시기 바랍니다.");
+		}
+
+		// 2. CI(연계정보)로 가입 되어져 있는 고객이 확인
 		custInfo = getCustomerFindByCi(custSnsInfo.getCi());
 
 		if (custInfo != null) { // 2-1. 고객정보 있는경우
@@ -393,9 +420,10 @@ public class TsfCustomerService {
 
 			Customer customer = objectMapper.convertValue(custSnsInfo, Customer.class);
 			boolean isJoin = saveJoinCustomerSns(customer);
+
 			if (isJoin) {
-				resultMap.setString("custStat", "SUCC_CUST");
-				resultMap.setString("gb", "NEW");
+				resultMap.setString("custNo", String.valueOf(customer.getCustNo()));
+				resultMap.setString("custStat", "NEW_CUST");
 			} else {
 				resultMap.setString("custStat", "FAIL_CUST");
 			}
@@ -405,21 +433,19 @@ public class TsfCustomerService {
 		return resultMap;
 	}
 
-
 	/**
 	 * 로그인 처리
-	 * @param custId - 고객아이디
+	 * @param custNo- 고객번호
 	 * @param request - 요청
 	 * @author jsshin
 	 * @since 2021. 02. 18
 	 */
-	public void getLogin(String custId, HttpServletRequest request) {
-		if (StringUtils.isBlank(custId)) {
-			throw new IllegalStateException("고객 아이디가 없습니다. 로그인 다시 해보시기 바랍니다.");
+	public void getLogin(Integer custNo, HttpServletRequest request) {
+		if (custNo == null) {
+			throw new IllegalStateException("고객번호가 없습니다.");
 		}
-
 		Login loginParam = new Login();
-		loginParam.setCustId(custId);
+		loginParam.setCustNo(custNo);
 		Login loginInfo = loginService.getLoginCheckInfo(loginParam);
 
 		// 권한 설정
@@ -440,8 +466,11 @@ public class TsfCustomerService {
 
 	/**
 	 * Session 생성
+	 *
 	 * @param request - HttpServletRequest
 	 * @param loginDetails - 로그인 상세 정보
+	 * @author jsshin
+	 * @since 2021. 02. 18
 	 */
 	private void createSession(HttpServletRequest request, TsfLoginDetails loginDetails) {
 		HttpSession session = request.getSession(true);
@@ -449,4 +478,61 @@ public class TsfCustomerService {
 		session.setAttribute("session", loginDetails);
 	}
 
+
+	/**
+	 * 일반고객 정보 유효성
+	 *
+	 * @param customer - 고객정보
+	 * @return GagaMap - 유효성 결과 값
+	 * @author jsshin
+	 * @since 2021. 02. 18
+	 */
+	public GagaMap generalCustomerValidation (Customer customer) {
+		GagaMap resultMap = new GagaMap();
+
+		// 1. 아이디 확인
+		boolean boolCustId = getCustomerFindByCustIdCount(customer.getCustId());
+		if (!boolCustId) {
+			resultMap.setString("custStat", "DUP_ID_CUST");
+			return resultMap;
+		}
+
+		// 2. 이메일 확인
+		boolean boolEmail = getCustomerFindByEmailCount(customer.getEmail());
+		if (!boolEmail) {
+			resultMap.setString("custStat", "DUP_EMAIL_CUST");
+			return resultMap;
+		}
+
+		// 3. 휴대전화
+		boolean boolPhone = getCustomerFindByCellPhnnoCount(customer.getCellPhnno());
+		if (!boolPhone) {
+			resultMap.setString("custStat", "DUP_PHONE_CUST");
+			return resultMap;
+		}
+
+		// 4. CI
+		boolean boolCi = getCustomerFindByCiCount(customer.getCi());
+		if (!boolCi) {
+			resultMap.setString("custStat", "DUP_CI_CUST");
+			return resultMap;
+		}
+
+		resultMap.setString("custStat", "PASS_CUST");
+
+		return resultMap;
+	}
+
+	/**
+	 * SNS 정보로 고객 테이블 조회
+	 * @param custSnsInfo - 고객정보
+	 * @return 고객정보
+	 * @author jsshin
+	 * @since 2021. 02. 26
+	 */
+	Customer getCusomterSnsFind(CustSnsInfo custSnsInfo) {
+		return customerDao.getCusomterSnsFind(custSnsInfo);
+	}
+
+
 }

+ 11 - 6
src/main/java/com/style24/front/biz/thirdparty/KaKaoLogin.java

@@ -181,8 +181,12 @@ public class KaKaoLogin {
 			GagaMap kakaoAccount = gson.fromJson(obj.get("kakao_account"), GagaMap.class);
 
 			Locale locale = Locale.KOREA;
-			String cellPhnno = getPhoneNumber(kakaoAccount.getString("phone_number"), locale.getCountry());
+
+			String snsId = obj.get("id").toString();
+			String custNm = properties.getString("nickname");
+			String email = kakaoAccount.getString("email");
 			String birthYmd = kakaoAccount.getString("birthyear") + kakaoAccount.getString("birthday");
+			String cellPhnno = getPhoneNumber(kakaoAccount.getString("phone_number"), locale.getCountry());
 
 			String sexGb = "";
 			if (StringUtils.isNotBlank(kakaoAccount.getString("gender"))) {
@@ -197,13 +201,13 @@ public class KaKaoLogin {
 			// 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("-","");
+				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("snsId", snsId);
+			resultMap.setString("custNm", custNm);
+			resultMap.setString("email", email);
 			resultMap.setString("ci", ci);
 			resultMap.setString("cellPhnno", cellPhnno);
 			resultMap.setString("birthYmd", birthYmd);
@@ -310,4 +314,5 @@ public class KaKaoLogin {
 
 		return result;
 	}
+
 }

+ 77 - 4
src/main/java/com/style24/front/biz/thirdparty/NaverLogin.java

@@ -155,10 +155,25 @@ public class NaverLogin {
 
 			Gson gson = new GsonBuilder().create();
 			JsonObject obj = gson.fromJson(jsonResult, JsonObject.class);
-			JsonObject response = gson.fromJson(obj.get("response"), JsonObject.class);
-
-			resultMap.setString("snsId", response.get("id").toString());
-			resultMap.setString("email", response.get("email").toString());
+			GagaMap response = gson.fromJson(obj.get("response"), GagaMap.class);
+
+			String snsId = response.getString("id");
+			String custNm = this.uniCodeDeCode(response.getString("name"));
+			String email = response.getString("email");
+			// TODO: 네이버 로그인 셋팅 시 휴대폰 필수로 셋팅 한다고 함 jsshin 2021-02-26
+			String cellphnno = response.getString("mobile").equals("") ? "010-2590-6246" : response.getString("mobile");
+			// TODO: 출생년도도 필수 값으로 셋팅 해야 할것 같음 jsshin 2021-02-26
+			String birthYmd = (response.getString("birthyear").equals("") ? "1990" : response.getString("birthyear")) + response.getString("birthday").replaceAll("-","");
+			String sexGb = response.getString("gender");
+			String ci = this.requestReplace(response.getString("ci"),"encodeData");
+
+			resultMap.setString("snsId", snsId);
+			resultMap.setString("custNm", custNm);
+			resultMap.setString("email", email);
+			resultMap.setString("ci", ci);
+			resultMap.setString("cellPhnno", cellphnno);
+			resultMap.setString("birthYmd", birthYmd);
+			resultMap.setString("sexGb", sexGb);
 
 		} catch (Exception e) {
 			log.error(e.getMessage());
@@ -236,4 +251,62 @@ public class NaverLogin {
 		return resultMap;
 	}
 
+	public String requestReplace (String paramValue, String gubun) {
+
+		String result = "";
+
+		if (paramValue != null) {
+
+			paramValue = paramValue.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
+
+			paramValue = paramValue.replaceAll("\\*", "");
+			paramValue = paramValue.replaceAll("\\?", "");
+			paramValue = paramValue.replaceAll("\\[", "");
+			paramValue = paramValue.replaceAll("\\{", "");
+			paramValue = paramValue.replaceAll("\\(", "");
+			paramValue = paramValue.replaceAll("\\)", "");
+			paramValue = paramValue.replaceAll("\\^", "");
+			paramValue = paramValue.replaceAll("\\$", "");
+			paramValue = paramValue.replaceAll("'", "");
+			paramValue = paramValue.replaceAll("@", "");
+			paramValue = paramValue.replaceAll("%", "");
+			paramValue = paramValue.replaceAll(";", "");
+			paramValue = paramValue.replaceAll(":", "");
+			paramValue = paramValue.replaceAll("-", "");
+			paramValue = paramValue.replaceAll("#", "");
+			paramValue = paramValue.replaceAll("--", "");
+			paramValue = paramValue.replaceAll("-", "");
+			paramValue = paramValue.replaceAll(",", "");
+
+			if(!"encodeData".equals(gubun)){
+				paramValue = paramValue.replaceAll("\\+", "");
+				paramValue = paramValue.replaceAll("/", "");
+				paramValue = paramValue.replaceAll("=", "");
+			}
+
+			result = paramValue;
+
+		}
+		return result;
+	}
+
+	public String uniCodeDeCode(String unicode) {
+		if (StringUtils.isBlank(unicode)) {
+			return "";
+		}
+
+		StringBuffer str = new StringBuffer();
+		char ch = 0;
+		for( int i= unicode.indexOf("\\u"); i > -1; i = unicode.indexOf("\\u") ){
+			ch = (char)Integer.parseInt( unicode.substring( i + 2, i + 6 ) ,16);
+			str.append( unicode.substring(0, i) );
+			str.append( String.valueOf(ch) );
+			unicode = unicode.substring(i + 6);
+		}
+		str.append(unicode);
+
+		return str.toString();
+	}
+
+
 }

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

@@ -602,7 +602,6 @@ public class TsfCustomerController extends TsfBaseController {
 		// 3.고객정보 생성 및 혜택 처리
 		boolean isJoin = customerService.saveJoinCustomer(customer);
 
-
 		if (isJoin) {
 			// 4.알림톡 발송
 			try {
@@ -621,10 +620,7 @@ public class TsfCustomerController extends TsfBaseController {
 			} catch (Exception e) {
 				log.error("error", e);
 			}
-
-			// 6. 가입성공시 로그인 처리 실패시
-			customerService.getLogin(customer.getCustId(), request);
-
+			customerService.getLogin(customer.getCustNo(), request);
 		} else {
 			TsfSession.setAttribute("maskingCustId",customer.getMaskingCustId());
 		}
@@ -655,5 +651,4 @@ public class TsfCustomerController extends TsfBaseController {
 	}
 
 
-
 }

+ 14 - 6
src/main/java/com/style24/front/biz/web/TsfIndexController.java

@@ -164,7 +164,8 @@ public class TsfIndexController extends TsfBaseController {
 	 * @since 2021. 02. 23
 	 */
 	@GetMapping("/signin/kakologin")
-	public String signinKaKaoLogin(@RequestParam(value = "rememberMe", required = false) String rememberMe, @RequestParam(value = "requestGb", required = false) String requestGb) {
+	public String signinKaKaoLogin(@RequestParam(value = "rememberMe", required = false) String rememberMe
+			, @RequestParam(value = "requestGb", required = false) String requestGb) {
 
 		if (StringUtils.isNotBlank(rememberMe)) {
 			// RememberMe 세션 저장
@@ -189,7 +190,8 @@ public class TsfIndexController extends TsfBaseController {
 	 * @since 2020. 5. 25
 	 */
 	@GetMapping("/signin/naverlogin")
-	public String signinNaverLogin(@RequestParam(value = "rememberMe", required = false) String rememberMe, @RequestParam(value = "requestGb", required = false) String requestGb) {
+	public String signinNaverLogin(@RequestParam(value = "rememberMe", required = false) String rememberMe
+			, @RequestParam(value = "requestGb", required = false) String requestGb) {
 
 		if (StringUtils.isNotBlank(rememberMe)) {
 			// RememberMe 세션 저장
@@ -219,7 +221,7 @@ public class TsfIndexController extends TsfBaseController {
 	@RequestMapping("/signin/snsLoginCallback")
 	public ModelAndView signinSnsLoginCallback(@RequestParam(value = "snsType", required = false) String snsType, HttpSession session
 			, @RequestParam(value = "code", required = false) String code, @RequestParam(value = "state", required = false) String state
-			, @RequestParam(value = "error", required = false) boolean isError) {
+			, @RequestParam(value = "error", required = false) boolean isError, HttpServletRequest request) {
 
 		ModelAndView mav = new ModelAndView();
 
@@ -263,16 +265,22 @@ public class TsfIndexController extends TsfBaseController {
 		GagaMap resultMap = new GagaMap();
 		if (isSnsLoing) {
 			CustSnsInfo custSnsInfo = objectMapper.convertValue(userInfo, CustSnsInfo.class);
+			log.info("custSnsInfo ==> {}", custSnsInfo.toString());
 			//상태 체크
 			resultMap = customerService.customerSnsProcessing(custSnsInfo);
 			resultMap.setString("snsId", custSnsInfo.getSnsId());
 			resultMap.setString("snsType", custSnsInfo.getSnsType());
+			String custStat = resultMap.getString("custStat");
 
-			String gb = resultMap.getString("gb");
-			if (StringUtils.isNotBlank(gb) && gb.equals("NEW")) {
-				//TODO : 신규가입 메일 발송, 알림톡 발송 2021.02.25 jsshin
+			// 신규가입 이면 바로 로그인 처리
+			if ("NEW_CUST".equals(custStat)) {
+				customerService.getLogin(Integer.parseInt(resultMap.getString("custNo")), request);
 			}
 
+			// 가입 폼으로 이동
+			if ("EMPTY_PHONE_CUST".equals(custStat)) {
+				session.setAttribute("custSnsInfo", custSnsInfo);
+			}
 		}
 
 		// RememberMe 값이 있고 true이면

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

@@ -25,13 +25,16 @@
 		WHERE  1 = 1
 		<choose>
 		    <when test="snsType != null and snsType != ''"> <!-- SNS 로그인  -->
-		AND CUST_NO = (
+		AND    CUST_NO = (
 		               SELECT CUST_NO
 		               FROM TB_CUSTOMER_SNS
 		               WHERE SNS_TYPE = #{snsType}
 		               AND   SNS_ID = #{snsId}
 		               )
 		    </when>
+		    <when test="custNo != null and custNo != ''">
+		AND    CUST_NO = #{custNo}
+		    </when>
 		    <otherwise> <!-- 일반로그인 -->
 		AND    CUST_ID = #{custId}
 		    </otherwise>

+ 4 - 1
src/main/webapp/WEB-INF/views/web/SigninFormWeb.html

@@ -253,11 +253,14 @@
 		if (userInfo.custStat === 'DORMANT_CUST') {
 			cfnGoToPage(_PAGE_CUSTOMER_DORMANT);
 		}
-
 		if (userInfo.custStat === 'FAIL_CUST') {
 			mcxDialog.alert("회원가입에 실패 했습니다.<br> 고객센터에 문의 하시기 바랍니다.");
 			return;
 		}
+		if (userInfo.custStat === 'NEW_CUST') {
+			cfnGoToPage(_PAGE_CUSTOMER_JOIN_COMPLETE);
+		}
+
 
 		if (userInfo.custStat === 'SUCC_CUST') {
 			let params = {};