id, pw 찾기 추가.

thkim
강석 최 2023-12-28 16:24:22 +09:00
parent f379513681
commit 3983cf4ce4
8 changed files with 113 additions and 32 deletions

View File

@ -85,4 +85,3 @@ button {cursor: pointer;}
.clickable{cursor: pointer;} .clickable{cursor: pointer;}
.findBtn{float: right}

View File

@ -7,9 +7,9 @@ import URL from 'constants/url';
import CODE from 'constants/code'; import CODE from 'constants/code';
import Row from 'react-bootstrap/Row'; import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col'; import Col from 'react-bootstrap/Col';
import Modal from "react-bootstrap/Modal";
import { getLocalItem, setLocalItem, setSessionItem } from 'utils/storage'; import { getLocalItem, setLocalItem, setSessionItem } from 'utils/storage';
import Modal from "react-bootstrap/Modal";
import IdFindForm from "./IdFindForm"; import IdFindForm from "./IdFindForm";
import PwFindForm from "./PwFindForm"; import PwFindForm from "./PwFindForm";

View File

@ -1,12 +1,10 @@
import * as EgovNet from "../../api/egovFetch"; import * as EgovNet from "../../api/egovFetch";
import CODE from "../../constants/code";
import Row from "react-bootstrap/Row"; import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col"; import Col from "react-bootstrap/Col";
import Form from "react-bootstrap/Form"; import Form from "react-bootstrap/Form";
import Button from "react-bootstrap/Button"; import Button from "react-bootstrap/Button";
import {setLocalItem} from "../../utils/storage";
function IdFindForm(){ function IdFindForm(){
@ -28,7 +26,7 @@ function IdFindForm(){
body: JSON.stringify({email: form.email.value}) body: JSON.stringify({email: form.email.value})
}, },
(resp) => { (resp) => {
alert(resp.resultMessage) document.querySelector("#findResultLabel").innerText = resp.resultMessage;
}) })
} }
} }
@ -44,11 +42,12 @@ function IdFindForm(){
<Form.Control.Feedback type={"invalid"} >메일을 입력해주세요.</Form.Control.Feedback> <Form.Control.Feedback type={"invalid"} >메일을 입력해주세요.</Form.Control.Feedback>
</Col> </Col>
</Form.Group> </Form.Group>
<Form.Group as={Row} className="mb-3"> <Row className="mb-3">
<Col sm={{ span: 10, offset: 2 }}> <Form.Label column xs={{span:8, offset:2}} id="findResultLabel"></Form.Label>
<Button className="findBtn" type="submit">찾기</Button> <Col xs={2}>
<Button type="submit">찾기</Button>
</Col> </Col>
</Form.Group> </Row>
</Form> </Form>
); );
} }

View File

@ -2,16 +2,42 @@ import Form from "react-bootstrap/Form";
import Row from "react-bootstrap/Row"; import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col"; import Col from "react-bootstrap/Col";
import Button from "react-bootstrap/Button"; import Button from "react-bootstrap/Button";
import * as EgovNet from "../../api/egovFetch";
function PwFindForm(){ 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 ( return (
<Form> <Form onSubmit={findPw} noValidate>
<Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail"> <Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail">
<Form.Label column sm={2}> <Form.Label column sm={2}>
아이디 아이디
</Form.Label> </Form.Label>
<Col sm={10}> <Col sm={10}>
<Form.Control type="text" placeholder="ID" /> <Form.Control type="text" name="id" placeholder="ID" required />
</Col> </Col>
</Form.Group> </Form.Group>
<Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail"> <Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail">
@ -19,14 +45,15 @@ function PwFindForm(){
이메일 이메일
</Form.Label> </Form.Label>
<Col sm={10}> <Col sm={10}>
<Form.Control type="email" placeholder="Email" /> <Form.Control type="email" name="email" placeholder="Email" required/>
</Col> </Col>
</Form.Group> </Form.Group>
<Form.Group as={Row} className="mb-3"> <Row className="mb-3">
<Col sm={{ span: 10, offset: 2 }}> <Form.Label column xs={{span:8, offset:2}} id="findResultLabel"></Form.Label>
<Button className="findBtn" type="submit">찾기</Button> <Col xs={2}>
<Button type="submit">찾기</Button>
</Col> </Col>
</Form.Group> </Row>
</Form> </Form>
); );
} }

View File

@ -97,8 +97,16 @@ public class EgovLoginApiController extends BaseController {
Integer insertResult = loginService.insertUser(loginVO); Integer insertResult = loginService.insertUser(loginVO);
if(insertResult!=null){ if(insertResult!=null){
resultMap.put("resultCode", ResponseCode.SUCCESS.getCode()); if(insertResult==-1){
resultMap.put("resultMessage", "저장 되었습니다."); 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{ }else{
resultMap.put("resultCode", ResponseCode.SAVE_ERROR.getCode()); resultMap.put("resultCode", ResponseCode.SAVE_ERROR.getCode());
resultMap.put("resultMessage", "저장에 실패하였습니다."); resultMap.put("resultMessage", "저장에 실패하였습니다.");
@ -132,6 +140,30 @@ public class EgovLoginApiController extends BaseController {
return resultMap; return resultMap;
} }
@Operation(
summary = "비밀번호 찾기",
description = "비밀번호 찾기",
tags = {"EgovLoginApiController"}
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "300", description = "조회 실패")
})
@PostMapping(value = "/findPw")
public HashMap<String, Object> findPw(@RequestBody LoginVO loginVO) throws Exception {
HashMap<String, Object> resultMap = new HashMap<String, Object>();
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") @RequestMapping("/accessTokenRefresh")
public HashMap<String, Object> accessTokenRefresh(HttpServletRequest request, HttpServletResponse response, @AuthenticationPrincipal UserInfo loginVO){ public HashMap<String, Object> accessTokenRefresh(HttpServletRequest request, HttpServletResponse response, @AuthenticationPrincipal UserInfo loginVO){
HashMap<String, Object> resultMap = new HashMap<>(); HashMap<String, Object> resultMap = new HashMap<>();

View File

@ -10,4 +10,6 @@ public interface UserInfoRepository extends JpaRepository<UserInfo, Integer> {
Optional<UserInfo> findByUserId(String userId); Optional<UserInfo> findByUserId(String userId);
Optional<UserInfo> findByEmail(String email); Optional<UserInfo> findByEmail(String email);
Optional<UserInfo> findByEmailAndUserId(String email, String id);
} }

View File

@ -2,6 +2,7 @@ package com.dbnt.kcscbackend.auth.service;
import com.dbnt.kcscbackend.auth.entity.LoginVO; 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); public Integer insertUser(LoginVO loginVO);
String selectEmail(LoginVO loginVO); String selectEmail(LoginVO loginVO);
String updateTempPassword(LoginVO loginVO);
} }

View File

@ -17,6 +17,8 @@ import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Random;
/** /**
* *
* @author * @author
@ -46,20 +48,21 @@ public class EgovLoginServiceImpl extends EgovAbstractServiceImpl implements Ego
@Transactional @Transactional
public Integer insertUser(LoginVO loginVO){ public Integer insertUser(LoginVO loginVO){
UserInfo savedUser = userInfoRepository.findByUserId(loginVO.getId()).orElse(null); UserInfo idCheck = userInfoRepository.findByUserId(loginVO.getId()).orElse(null);
if(savedUser == null){ if (idCheck != null){
savedUser = userInfoRepository.findByEmail(loginVO.getEmail()).orElse(null); return -1;
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();
}
} }
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){ public String selectEmail(LoginVO loginVO){
@ -67,6 +70,22 @@ public class EgovLoginServiceImpl extends EgovAbstractServiceImpl implements Ego
return savedUser==null?null:savedUser.getUserId(); 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 @Override
public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
return userInfoRepository.findByUserId(userId).orElseThrow(() -> new UsernameNotFoundException(userId)); return userInfoRepository.findByUserId(userId).orElseThrow(() -> new UsernameNotFoundException(userId));