id, pw 찾기 추가.
parent
f379513681
commit
3983cf4ce4
|
|
@ -84,5 +84,4 @@ button {cursor: pointer;}
|
|||
.pb10 {padding-bottom: 10px !important;}
|
||||
|
||||
|
||||
.clickable{cursor: pointer;}
|
||||
.findBtn{float: right}
|
||||
.clickable{cursor: pointer;}
|
||||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -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(){
|
|||
<Form.Control.Feedback type={"invalid"} >메일을 입력해주세요.</Form.Control.Feedback>
|
||||
</Col>
|
||||
</Form.Group>
|
||||
<Form.Group as={Row} className="mb-3">
|
||||
<Col sm={{ span: 10, offset: 2 }}>
|
||||
<Button className="findBtn" type="submit">찾기</Button>
|
||||
<Row className="mb-3">
|
||||
<Form.Label column xs={{span:8, offset:2}} id="findResultLabel"></Form.Label>
|
||||
<Col xs={2}>
|
||||
<Button type="submit">찾기</Button>
|
||||
</Col>
|
||||
</Form.Group>
|
||||
</Row>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<Form>
|
||||
<Form onSubmit={findPw} noValidate>
|
||||
<Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail">
|
||||
<Form.Label column sm={2}>
|
||||
아이디
|
||||
</Form.Label>
|
||||
<Col sm={10}>
|
||||
<Form.Control type="text" placeholder="ID" />
|
||||
<Form.Control type="text" name="id" placeholder="ID" required />
|
||||
</Col>
|
||||
</Form.Group>
|
||||
<Form.Group as={Row} className="mb-3" controlId="formHorizontalEmail">
|
||||
|
|
@ -19,14 +45,15 @@ function PwFindForm(){
|
|||
이메일
|
||||
</Form.Label>
|
||||
<Col sm={10}>
|
||||
<Form.Control type="email" placeholder="Email" />
|
||||
<Form.Control type="email" name="email" placeholder="Email" required/>
|
||||
</Col>
|
||||
</Form.Group>
|
||||
<Form.Group as={Row} className="mb-3">
|
||||
<Col sm={{ span: 10, offset: 2 }}>
|
||||
<Button className="findBtn" type="submit">찾기</Button>
|
||||
<Row className="mb-3">
|
||||
<Form.Label column xs={{span:8, offset:2}} id="findResultLabel"></Form.Label>
|
||||
<Col xs={2}>
|
||||
<Button type="submit">찾기</Button>
|
||||
</Col>
|
||||
</Form.Group>
|
||||
</Row>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<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")
|
||||
public HashMap<String, Object> accessTokenRefresh(HttpServletRequest request, HttpServletResponse response, @AuthenticationPrincipal UserInfo loginVO){
|
||||
HashMap<String, Object> resultMap = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -10,4 +10,6 @@ public interface UserInfoRepository extends JpaRepository<UserInfo, Integer> {
|
|||
|
||||
Optional<UserInfo> findByUserId(String userId);
|
||||
Optional<UserInfo> findByEmail(String email);
|
||||
|
||||
Optional<UserInfo> findByEmailAndUserId(String email, String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue