diff --git a/egovframe-template-simple-react-contribution/src/css/base.css b/egovframe-template-simple-react-contribution/src/css/base.css index 930d2ef..761408a 100644 --- a/egovframe-template-simple-react-contribution/src/css/base.css +++ b/egovframe-template-simple-react-contribution/src/css/base.css @@ -84,5 +84,4 @@ button {cursor: pointer;} .pb10 {padding-bottom: 10px !important;} -.clickable{cursor: pointer;} -.findBtn{float: right} \ No newline at end of file +.clickable{cursor: pointer;} \ No newline at end of file diff --git a/egovframe-template-simple-react-contribution/src/pages/login/EgovLoginContent.jsx b/egovframe-template-simple-react-contribution/src/pages/login/EgovLoginContent.jsx index a4d329c..c475c1f 100644 --- a/egovframe-template-simple-react-contribution/src/pages/login/EgovLoginContent.jsx +++ b/egovframe-template-simple-react-contribution/src/pages/login/EgovLoginContent.jsx @@ -7,9 +7,9 @@ import URL from 'constants/url'; import CODE from 'constants/code'; import Row from 'react-bootstrap/Row'; import Col from 'react-bootstrap/Col'; +import Modal from "react-bootstrap/Modal"; import { getLocalItem, setLocalItem, setSessionItem } from 'utils/storage'; -import Modal from "react-bootstrap/Modal"; import IdFindForm from "./IdFindForm"; import PwFindForm from "./PwFindForm"; diff --git a/egovframe-template-simple-react-contribution/src/pages/login/IdFindForm.jsx b/egovframe-template-simple-react-contribution/src/pages/login/IdFindForm.jsx index dfdcabf..1ac674d 100644 --- a/egovframe-template-simple-react-contribution/src/pages/login/IdFindForm.jsx +++ b/egovframe-template-simple-react-contribution/src/pages/login/IdFindForm.jsx @@ -1,12 +1,10 @@ import * as EgovNet from "../../api/egovFetch"; -import CODE from "../../constants/code"; import Row from "react-bootstrap/Row"; import Col from "react-bootstrap/Col"; import Form from "react-bootstrap/Form"; import Button from "react-bootstrap/Button"; -import {setLocalItem} from "../../utils/storage"; function IdFindForm(){ @@ -28,7 +26,7 @@ function IdFindForm(){ body: JSON.stringify({email: form.email.value}) }, (resp) => { - alert(resp.resultMessage) + document.querySelector("#findResultLabel").innerText = resp.resultMessage; }) } } @@ -44,11 +42,12 @@ function IdFindForm(){ 메일을 입력해주세요. - - - + + + + - + ); } diff --git a/egovframe-template-simple-react-contribution/src/pages/login/PwFindForm.jsx b/egovframe-template-simple-react-contribution/src/pages/login/PwFindForm.jsx index a1307c2..9573a1f 100644 --- a/egovframe-template-simple-react-contribution/src/pages/login/PwFindForm.jsx +++ b/egovframe-template-simple-react-contribution/src/pages/login/PwFindForm.jsx @@ -2,16 +2,42 @@ import Form from "react-bootstrap/Form"; import Row from "react-bootstrap/Row"; import Col from "react-bootstrap/Col"; import Button from "react-bootstrap/Button"; +import * as EgovNet from "../../api/egovFetch"; function PwFindForm(){ + + const findPw = (e) => { + e.preventDefault(); + e.stopPropagation(); + const form = e.currentTarget; + if(!form.email.value){ + alert("이메일을 입력해주세요.") + }if(!form.id.value){ + alert("아이디를 입력해주세요.") + }else{ + EgovNet.requestFetch( + "/auth/findPw", + { + method: "POST", + headers: { + 'Content-type': 'application/json' + }, + body: JSON.stringify({email: form.email.value, id: form.id.value}) + }, + (resp) => { + document.querySelector("#findResultLabel").innerText = resp.resultMessage; + }) + } + } + return ( -
+ 아이디 - + @@ -19,14 +45,15 @@ function PwFindForm(){ 이메일 - + - - - + + + + - +
); } diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/EgovLoginApiController.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/EgovLoginApiController.java index 3a17dc7..048b7f0 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/EgovLoginApiController.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/EgovLoginApiController.java @@ -97,8 +97,16 @@ public class EgovLoginApiController extends BaseController { Integer insertResult = loginService.insertUser(loginVO); if(insertResult!=null){ - resultMap.put("resultCode", ResponseCode.SUCCESS.getCode()); - resultMap.put("resultMessage", "저장 되었습니다."); + if(insertResult==-1){ + resultMap.put("resultCode", ResponseCode.SAVE_ERROR.getCode()); + resultMap.put("resultMessage", "사용중인 아이디입니다."); + }else if(insertResult==-2){ + resultMap.put("resultCode", ResponseCode.SAVE_ERROR.getCode()); + resultMap.put("resultMessage", "가입된 이메일입니다."); + }else{ + resultMap.put("resultCode", ResponseCode.SUCCESS.getCode()); + resultMap.put("resultMessage", "저장 되었습니다."); + } }else{ resultMap.put("resultCode", ResponseCode.SAVE_ERROR.getCode()); resultMap.put("resultMessage", "저장에 실패하였습니다."); @@ -132,6 +140,30 @@ public class EgovLoginApiController extends BaseController { return resultMap; } + @Operation( + summary = "비밀번호 찾기", + description = "비밀번호 찾기", + tags = {"EgovLoginApiController"} + ) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "조회 성공"), + @ApiResponse(responseCode = "300", description = "조회 실패") + }) + @PostMapping(value = "/findPw") + public HashMap findPw(@RequestBody LoginVO loginVO) throws Exception { + HashMap resultMap = new HashMap(); + + String password = loginService.updateTempPassword(loginVO); + if(password!=null){ + resultMap.put("resultCode", ResponseCode.SUCCESS.getCode()); + resultMap.put("resultMessage", "비밀번호가 발급되었습니다.\n 새 비밀번호: "+password); + }else{ + resultMap.put("resultCode", ResponseCode.SAVE_ERROR.getCode()); + resultMap.put("resultMessage", "조회에 실패하였습니다."); + } + return resultMap; + } + @RequestMapping("/accessTokenRefresh") public HashMap accessTokenRefresh(HttpServletRequest request, HttpServletResponse response, @AuthenticationPrincipal UserInfo loginVO){ HashMap resultMap = new HashMap<>(); diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/repository/UserInfoRepository.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/repository/UserInfoRepository.java index 561c0fc..10406ef 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/repository/UserInfoRepository.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/repository/UserInfoRepository.java @@ -10,4 +10,6 @@ public interface UserInfoRepository extends JpaRepository { Optional findByUserId(String userId); Optional findByEmail(String email); + + Optional findByEmailAndUserId(String email, String id); } diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/service/EgovLoginService.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/service/EgovLoginService.java index feb2b9e..fc7b6aa 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/service/EgovLoginService.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/service/EgovLoginService.java @@ -2,6 +2,7 @@ package com.dbnt.kcscbackend.auth.service; import com.dbnt.kcscbackend.auth.entity.LoginVO; +import com.dbnt.kcscbackend.auth.entity.UserInfo; /** * 일반 로그인을 처리하는 비즈니스 구현 클래스 @@ -52,4 +53,6 @@ public interface EgovLoginService { public Integer insertUser(LoginVO loginVO); String selectEmail(LoginVO loginVO); + + String updateTempPassword(LoginVO loginVO); } \ No newline at end of file diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/service/impl/EgovLoginServiceImpl.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/service/impl/EgovLoginServiceImpl.java index 7760150..e3bb1b8 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/service/impl/EgovLoginServiceImpl.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/auth/service/impl/EgovLoginServiceImpl.java @@ -17,6 +17,8 @@ import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Random; + /** * 일반 로그인을 처리하는 비즈니스 구현 클래스 * @author 공통서비스 개발팀 박지욱 @@ -46,20 +48,21 @@ public class EgovLoginServiceImpl extends EgovAbstractServiceImpl implements Ego @Transactional public Integer insertUser(LoginVO loginVO){ - UserInfo savedUser = userInfoRepository.findByUserId(loginVO.getId()).orElse(null); - if(savedUser == null){ - savedUser = userInfoRepository.findByEmail(loginVO.getEmail()).orElse(null); - if (savedUser == null){ - UserInfo info = new UserInfo(); - info.setUserId(loginVO.getId()); - info.setPassword(convertPassword(loginVO.getPassword())); - info.setEmail(loginVO.getEmail()); - info.setUserSe("USR"); - userInfoRepository.save(info); - return info.getUserSeq(); - } + UserInfo idCheck = userInfoRepository.findByUserId(loginVO.getId()).orElse(null); + if (idCheck != null){ + return -1; } - return null; + UserInfo emailCheck = userInfoRepository.findByEmail(loginVO.getEmail()).orElse(null); + if(emailCheck != null){ + return -2; + } + UserInfo info = new UserInfo(); + info.setUserId(loginVO.getId()); + info.setPassword(convertPassword(loginVO.getPassword())); + info.setEmail(loginVO.getEmail()); + info.setUserSe("USR"); + userInfoRepository.save(info); + return info.getUserSeq(); } public String selectEmail(LoginVO loginVO){ @@ -67,6 +70,22 @@ public class EgovLoginServiceImpl extends EgovAbstractServiceImpl implements Ego return savedUser==null?null:savedUser.getUserId(); } + @Transactional + public String updateTempPassword(LoginVO loginVO){ + UserInfo user = userInfoRepository.findByEmailAndUserId(loginVO.getEmail(), loginVO.getId()).orElse(null); + if(user!=null){ + Random rd = new Random(); + StringBuilder password = new StringBuilder(); + for(int i=0; i<10; i++){ + int rdNum = rd.nextInt(95)+33; + password.append((char)rdNum); + } + user.setPassword(convertPassword(password.toString())); + return password.toString(); + } + return null; + } + @Override public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException { return userInfoRepository.findByUserId(userId).orElseThrow(() -> new UsernameNotFoundException(userId));