reafactoring: mailsender
This commit is contained in:
parent
41a04df278
commit
874b877399
@ -39,11 +39,11 @@ public class UserController {
|
||||
userService.join(user);
|
||||
return ResponseEntity.ok("User registered successfully");
|
||||
}
|
||||
@PostMapping("/findpassword/{user_id}")
|
||||
public ResponseEntity<String> findpassword(@PathVariable("user_id") Long user_id) throws Exception {
|
||||
userService.userCheck(user_id);
|
||||
return ResponseEntity.ok("임시 비밀번호가 이메일로 전송되었습니다.");
|
||||
}
|
||||
// @PostMapping("/findpassword/{user_id}")
|
||||
// public ResponseEntity<String> findpassword(@PathVariable("user_id") Long user_id) throws Exception {
|
||||
// userService.userCheck(user_id);
|
||||
// return ResponseEntity.ok("임시 비밀번호가 이메일로 전송되었습니다.");
|
||||
// }
|
||||
|
||||
@PutMapping("/updateinfo")
|
||||
public ResponseEntity<String> updateUserInfo(
|
||||
|
@ -1,20 +0,0 @@
|
||||
package com.edufocus.edufocus.user.model.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
@Data
|
||||
public class MailDto {
|
||||
|
||||
private String address;
|
||||
private String title;
|
||||
private String message;
|
||||
|
||||
}
|
@ -11,9 +11,7 @@ public interface UserService {
|
||||
String getRefreshToken(Long id) throws Exception;
|
||||
void deleteRefreshToken(Long id) throws Exception;
|
||||
User userInfo(Long id) throws Exception;
|
||||
void sendEamail(User user) throws Exception;
|
||||
void userCheck(Long id) throws Exception;
|
||||
String getUserName(Long id) throws Exception;
|
||||
String getUserName(Long id) throws Exception;
|
||||
void changeUserInfo(InfoDto infoDto,Long id) throws Exception;
|
||||
void changePassword(PasswordDto passwordDto,Long id) throws Exception;
|
||||
|
||||
|
@ -23,7 +23,6 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final JavaMailSender mailSender;//private final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
|
||||
public void join(User user)
|
||||
@ -61,56 +60,10 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendEamail(User user) throws Exception {
|
||||
MailDto mailDto = createMailAndChargePassword(user);
|
||||
|
||||
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
|
||||
|
||||
message.setTo(mailDto.getAddress());
|
||||
message.setFrom("passfinder111@gmail.com");
|
||||
message.setSubject(mailDto.getTitle());
|
||||
message.setText(mailDto.getMessage());
|
||||
|
||||
|
||||
mailSender.send(message);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public MailDto createMailAndChargePassword(User user) throws SQLException {
|
||||
String str = getTempPassword();
|
||||
MailDto dto = new MailDto();
|
||||
dto.setAddress(user.getEmail());
|
||||
dto.setTitle(user.getUserId() + "님의 임시비밀번호 안내 이메일 입니다.");
|
||||
dto.setMessage("안녕하세요. EduFoucs 입니다. " + "\n" + "임시비밀번호 안내 관련 메일 입니다." + "\n[" + user.getName() + "]" + "님의 임시 비밀번호는 "
|
||||
+ str + " 입니다.");
|
||||
|
||||
System.out.println(dto);
|
||||
|
||||
MemberChangeDto memberChangeDto = new MemberChangeDto(user.getId(), str);
|
||||
userRepository.updatePassword(memberChangeDto.getId(), memberChangeDto.getPassword());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userCheck(Long id) throws Exception {
|
||||
|
||||
User user = userRepository.findById(id).orElse(null);
|
||||
|
||||
|
||||
if (user == null) {
|
||||
throw new UserException("유효하지 않은 아이디입니다. 다시 입력하세요");
|
||||
|
||||
} else {
|
||||
|
||||
sendEamail(user);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserName(Long id) throws Exception {
|
||||
|
||||
|
@ -36,15 +36,6 @@ spring.jpa.show-sql=true
|
||||
management.endpoints.web.exposure.include=health,info
|
||||
management.endpoint.health.show-details=always
|
||||
|
||||
spring.mail.host=smtp.gmail.com
|
||||
spring.mail.port=587
|
||||
#spring.mail.username=ssafytestpjt
|
||||
#spring.mail.password=trpjbxqialufuzih
|
||||
spring.mail.username=passfinder111@gmail.com
|
||||
spring.mail.password=mnlyfkiprltjlsmw
|
||||
|
||||
spring.mail.properties.mail.smtp.auth=true
|
||||
spring.mail.properties.mail.smtp.starttls.enable=true
|
||||
|
||||
|
||||
spring.rabbitmq.host=${RABBITMQ_HOST}
|
||||
|
Loading…
Reference in New Issue
Block a user