본문 바로가기

My Proect/파이널 프로젝트 - CineDate

8일차 - 아이디, 비밀번호 찾기 화면 및 기능 구현

아이디, 비밀번호 찾기 화면 구현

findID.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/layout/header.jsp"%>

<div id="wrap">
	<div id="in--wrap">
		<div class="flex--wrap">
			<div class="top--title">
				<h1 class="text-center pointFont">아이디 찾기</h1>
			</div>

			<form action="/user/findID" method="post">
				<div class="login--wrap">
					<label for="name">이름</label>
					<input type="text" id="name" name="name" placeholder="이름을 입력해주세요.">
					
					<label for="email">이메일 주소</label>
					<input type="email" id="email" name="email" placeholder="이메일 주소를 입력해주세요.">
					
					<button type="submit" class="btn" id="join--btn">아이디 찾기</button>
				</div>
			</form>
			
			<div class="login--items">
				<span class="btn"><a href="/user/findPassword">비밀번호찾기</a></span>
				<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
				<span class="btn"><a href="/user/signUp">회원가입</a></span>
			</div>
		</div>
	</div>

	<%@ include file="/WEB-INF/view/layout/footer.jsp"%>

 

 

 

 

findPassword.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/layout/header.jsp"%>

<div id="wrap">
	<div id="in--wrap">
		<div class="flex--wrap">
			<div class="top--title">
				<h1 class="text-center pointFont">비밀번호 찾기</h1>
			</div>

			<form action="/user/findNextPassword" method="POST">
				<div class="login--wrap">
					<label for="loginId">아이디</label>
					<input type="text" id="loginId" name="loginId" placeholder="아이디를 입력해주세요.">
					
					<label for="email">이메일 주소</label>
					<input type="email" id="email" name="email" placeholder="이메일 주소를 입력해주세요.">
					
					<button type="submit" class="btn" id="join--btn">비밀번호 찾기</button>
				</div>
			</form>
			
			<div class="login--items">
				<span class="btn"><a href="/user/signIn">로그인</a></span>
				<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
				<span class="btn"><a href="/user/signUp">회원가입</a></span>
			</div>
		</div>
	</div>

	<%@ include file="/WEB-INF/view/layout/footer.jsp"%>

 

 

 


 

 

 

아이디, 비밀번호 찾기 기능 구현

UserRepository
// 이름과 이메일로 아이디 찾기
public User findByLoginIdForEmail(@Param("name") String name, @Param("email") String email);
	
// 아이디와 이메일로 비밀번호 찾기
public User findByLoginIdForPassword(@Param("loginId") String loginId, @Param("email") String email);

 

 

 

 

UserController
/**
	 * 아이디 찾기
	 * @return
	 */
	@GetMapping("/findID")
	public String findIdPage() {
		return "user/findID";
	}

	@PostMapping("/findID")
	public String findId(@RequestParam(name ="name")String name, @RequestParam(name ="email")String email, Model model) {
		User user = userService.findByLoginIdForEmail(name, email);
		model.addAttribute("loginId", user.getLoginId());
		return "user/findNextID";
	}
	
	@PostMapping("/findNextID")
	public String findNextID() {
		return "redirect:/user/findNextID";
	}
	
	/**
	 * 비밀번호 찾기
	 * @param name
	 * @param phoneNum
	 * @param model
	 * @return
	 */
	@GetMapping("/findPassword")
	public String findPasswrod() {
		return "user/findPassword";
	}
	
	@PostMapping("/findNextPassword")
	public String findNextPassword(@RequestParam(name = "loginId") String loginId, @RequestParam(name ="email") String email, Model model) {
		System.out.println(loginId);
		System.out.println(email);
		User user = userService.findByLoginIdForPassword(loginId, email);
		model.addAttribute("password", user.getPassword());
		return "user/findNextPassword";
	}

 

 

 

 

UserService
	/**
	 * 이메일로 아이디 찾기
	 * @return
	 */
	public User findByLoginIdForEmail(String name, String email) {

		User userEntity = null;
		try {
			userEntity = userRepository.findByLoginIdForEmail(name, email);
		} catch (DataAccessException e) {
			throw new DataDeliveryException(Define.FAILED_PROCESSING, HttpStatus.INTERNAL_SERVER_ERROR);
		} catch (Exception e) {
			throw new DataDeliveryException(Define.UNKNOWN_ERROR, HttpStatus.SERVICE_UNAVAILABLE);
		}

		if (userEntity == null) {
			throw new DataDeliveryException("등록된 정보가 없습니다. 다시 확인해주세요.", HttpStatus.BAD_REQUEST);
		}

		return userEntity;
	}

	/**
	 * 비밀번호 찾기
	 * @param loginId
	 * @param password
	 * @return
	 */
	public User findByLoginIdForPassword(String loginId, String email) {

		User userEntity = null;
		try {
			userEntity = userRepository.findByLoginIdForPassword(loginId, email);
		} catch (DataAccessException e) {
			throw new DataDeliveryException(Define.FAILED_PROCESSING, HttpStatus.INTERNAL_SERVER_ERROR);
		} catch (Exception e) {
			throw new DataDeliveryException(Define.UNKNOWN_ERROR, HttpStatus.SERVICE_UNAVAILABLE);
		}

		if (userEntity == null) {
			throw new DataDeliveryException("등록된 정보가 없습니다. 다시 확인해주세요.", HttpStatus.BAD_REQUEST);
		}

		return userEntity;
	}

	/**
	 * name 사용자 존재 여부 조회
	 * @param name
	 * @return User
	 */
	public User searchUsername(String name) {
		return userRepository.findByUsername(name);
	}
	
	/**
	 * LoginId 사용자 존재 여부 조회
	 * @param loginId
	 * @return User
	 */
	public User searchLoginId(String loginId) {
		return userRepository.findByLoginId(loginId);
	}
	
	/**
	 * email 사용자 존재 여부 조회
	 * @return User
	 */
	public User searchEmail(String email) {
		return userRepository.findByEmail(email);
	}

 

 

 

user.xml
// 이름과 이메일로 아이디 찾기
public User findByLoginIdForEmail(@Param("name") String name, @Param("email") String email);
	
// 아이디와 이메일로 비밀번호 찾기
public User findByLoginIdForPassword(@Param("loginId") String loginId, @Param("email") String email);
728x90