<< MemberRegisterService >>
package disassemble.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import disassemble.DAO.MemberDAO;
import disassemble.DTO.MemberDTO;
import disassemble.DTO.RegisterRequest;
public class MemberRegisterService {
private MemberDAO memberDao;
public MemberRegisterService(MemberDAO memberDao) {
this.memberDao = memberDao;
}
public void regist(RegisterRequest req) {
// password == confirmPassword
// email로 계정 등록 여부 확인
// memberDao.insert() 계정 등록
if (!req.getPassword().equals(req.getConfirmPassword())) {
System.out.println("입력하신 두 비밀번호가 일치하지 않습니다...");
return;
}
MemberDTO member = memberDao.selectEmail(req.getEmail());
if (member != null) {
System.out.println(req.getEmail() + "는 이미 등록된 정보입니다.");
return;
}
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yy년 MM월 dd일 hh시 mm분");
MemberDTO insertMember = new MemberDTO();
insertMember.setEmail(req.getEmail());
insertMember.setName(req.getName());
insertMember.setPassword(req.getPassword());
insertMember.setRegisterDate(sdf.format(date));
memberDao.insert(insertMember);
System.out.println("등록 완료\n");
}
}
<< MemberAllService >>
package disassemble.Service;
import java.util.Collection;
import disassemble.DAO.MemberDAO;
import disassemble.DTO.MemberDTO;
public class MemberAllService {
private MemberDAO memberDao;
public MemberAllService(MemberDAO memberDao){
this.memberDao = memberDao;
}
public void selectAll() {
Collection<MemberDTO> members = memberDao.selectAll();
if (members.isEmpty()) {
System.out.println("등록된 정보가 없습니다. 등록 후 이용하세요...");
return;
}
for (MemberDTO member : members) {
System.out.println("이메일 : " + member.getEmail());
System.out.println("비밀번호 : " + member.getPassword());
System.out.println("이름 : " + member.getName());
System.out.println("등록일 : " + member.getRegisterDate() + "\n");
}
}
}
<< ChangePasswordService >>
package disassemble.Service;
import disassemble.DAO.MemberDAO;
import disassemble.DTO.MemberDTO;
public class ChangePasswordService {
private MemberDAO memberDao;
public ChangePasswordService(MemberDAO memberDao) {
this.memberDao = memberDao;
}
public void changePassword(String email, String oldPw, String newPw) {
// 이메일 등록여부 확인.
// 패스워드 확인 및 MemberDAO.update() 호출
MemberDTO member = memberDao.selectEmail(email);
if (member == null) {
System.out.println(email + "는 없는 정보입니다.");
return;
} else if (!member.getPassword().equals(oldPw)) {
System.out.println("비밀번호가 틀립니다.");
return;
} else if (member.getPassword().equals(newPw)) {
System.out.println("변경 비밀번호와 현재 비밀번호가 동일합니다. 다시 입력하세요....");
return;
}
MemberDTO updateMember = new MemberDTO();
updateMember.setEmail(email);
updateMember.setPassword(newPw);
memberDao.update(updateMember);
System.out.println("수정 완료\n");
}
}
<< MemberDeleteService >>
package disassemble.Service;
import disassemble.DAO.MemberDAO;
import disassemble.DTO.MemberDTO;
public class MemberDeleteService {
private MemberDAO memberDao;
public MemberDeleteService(MemberDAO memberDao) {
this.memberDao = memberDao;
}
public void checkPassword(String email, String password, String confirmPassword) {
// 패스워드 확인
// MemberDAO 객체 내 selectEmail() 메소드를 호출
// 저장된 회원 정보와 입력된 회원 정보 검증
// MemberDAO 객체 내 delete() 호출
if (!password.equals(confirmPassword)) {
System.out.println("입력하신 두 비밀번호가 다릅니다...");
return;
}
MemberDTO member = memberDao.selectEmail(email);
if (member == null) {
System.out.println(email + "는 없는 정보입니다.");
return;
} else if (!member.getPassword().equals(password)) {
System.out.println("비밀번호가 틀립니다...");
return;
}
memberDao.delete(email);
System.out.println("삭제 완료\n");
}
}
<< Exit >>
package disassemble.Service;
import disassemble.DAO.MemberDAO;
public class Exit {
private MemberDAO memberDao;
public Exit(MemberDAO memberDao) {
this.memberDao = memberDao;
}
public void exit() {
memberDao.exit();
}
}
'중간평가 > disassemble_2' 카테고리의 다른 글
중간평가 (DTO, DAO) (0) | 2022.08.10 |
---|---|
중간평가 (Main) (0) | 2022.08.10 |