Skip to content

Commit

Permalink
[FEATURE] E4-S10 사용자에게 4자리의 코드번호 메일로 전달 #285
Browse files Browse the repository at this point in the history
  • Loading branch information
HyeJeongIm committed Jan 24, 2022
1 parent c55b179 commit d82bf93
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 13 deletions.
4 changes: 3 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ dependencies {
testImplementation 'org.springframework.security:spring-security-test'
implementation 'com.sun.xml.bind:jaxb1-impl:2.2.5.1'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"


implementation 'org.springframework.boot:spring-boot-starter-mail'

}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public void addCorsMappings(CorsRegistry registry) {
"https://vuelogin.choicloudlab.com",
"http://localhost:8070",
"https://ciat-dev.choicloudlab.com",
"https://ciat.choicloudlab.com"
"https://ciat.choicloudlab.com",
"https://smtp.naver.com",
"https://smtp.naver.com:465"

)
.allowedMethods("*");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public void addCorsMappings(CorsRegistry registry) {
"http://localhost:8070",
"https://ciat-frontend.choicloudlab.com",
"https://ciat-dev.choicloudlab.com",
"https://ciat.choicloudlab.com"
"https://ciat.choicloudlab.com",
"https://smtp.naver.com",
"https://smtp.naver.com:465"
)
.allowedMethods("*");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected void configure(HttpSecurity http) throws Exception {
.authorizeRequests()
.antMatchers("/api/v1/user/signin").permitAll()
.antMatchers("/api/v1/user/signup").permitAll()
.antMatchers(HttpMethod.POST, "/api/v1/user/resetPassword").permitAll()
.antMatchers(HttpMethod.GET, "/api/v1/feed").permitAll()
.antMatchers(HttpMethod.GET, "/api/v1/feed/**").permitAll()
.antMatchers(HttpMethod.GET, "/api/v1/feeds").permitAll()
Expand All @@ -90,6 +91,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.POST, "/api/v1/gardenList").permitAll()
.antMatchers(HttpMethod.GET, "/api/v1/gardenDtl/**").permitAll()
.antMatchers(HttpMethod.GET, "/swagger-ui.html/**").permitAll()

.antMatchers("/healthcheck").permitAll()

.anyRequest().authenticated()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package com.infp.ciat.user.controller;

import com.infp.ciat.config.auth.PrincipalDetails;
import com.infp.ciat.user.controller.dto.request.ResetPasswordRequestDTO;
import com.infp.ciat.user.controller.dto.request.SignupRequestDTO;
import com.infp.ciat.user.controller.dto.response.LoginSuccessResponse;
import com.infp.ciat.user.controller.dto.response.SignUpResponse;
import com.infp.ciat.user.service.AccountService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import javax.mail.internet.MimeMessage;
import javax.validation.Valid;
import java.util.Random;

@RestController
@RequiredArgsConstructor
Expand All @@ -21,6 +28,11 @@
public class AccountController {
private final AccountService accountService;

private final JavaMailSender javaMailSender;

@Value("${spring.mail.username}")
private String fromMail;

@PostMapping("/signup")
public ResponseEntity<SignUpResponse> signUp(@Valid @RequestBody SignupRequestDTO requestDTO) {

Expand All @@ -30,13 +42,42 @@ public ResponseEntity<SignUpResponse> signUp(@Valid @RequestBody SignupRequestDT
return new ResponseEntity<>(new SignUpResponse(created_id), HttpStatus.CREATED);
}

/***
* 회원가입 성공후 response
* @param user
* @return
*/
@GetMapping("/success")
public ResponseEntity<LoginSuccessResponse> login_success(@AuthenticationPrincipal PrincipalDetails user) {
return new ResponseEntity<>(new LoginSuccessResponse(user.getUsername()), HttpStatus.OK);
@SneakyThrows
@PostMapping("/resetPassword")
public void resetPassword(@RequestBody ResetPasswordRequestDTO requestDTO) {

System.out.println("email: " + requestDTO.getEmail());
System.out.println("fromMail: " + fromMail);

MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
mimeMessageHelper.setFrom(fromMail);
mimeMessageHelper.setTo(requestDTO.getEmail());
mimeMessageHelper.setSubject("[ciat] 임시 비밀번호 안내");

Random random = new Random();
String code = "";
for (int i = 0; i < 4; i++) {
code += random.nextInt(10);
}

StringBuilder body = new StringBuilder();

body.append("3시간 안에 코드를 입력해주세요.\n");
body.append("코드: " + code);

mimeMessageHelper.setText(body.toString(), true);
javaMailSender.send(mimeMessage);

}

/***
* 회원가입 성공후 response
* @param user
* @return
*/
@GetMapping("/success")
public ResponseEntity<LoginSuccessResponse> login_success(@AuthenticationPrincipal PrincipalDetails user) {
return new ResponseEntity<>(new LoginSuccessResponse(user.getUsername()), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.infp.ciat.user.controller.dto.request;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class ResetPasswordRequestDTO {

private String email;

@Builder
public ResetPasswordRequestDTO(String email) {
this.email = email;
}
}
9 changes: 9 additions & 0 deletions backend/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ server:
cookie:
http-only: false
secure: false

jwt:
secret: ENC(1MBsToCDbYBEvJkfxlSkoBb30kG1MYPqYOcyUcKZOhnodcSkYMncHeTYNyKr0GfYocr9yI3G1cR6DJHykIZTpQ==)

Expand All @@ -17,6 +18,14 @@ logging:
util:
EC2MetadataUtils: error
spring:
mail:
host: smtp.naver.com
port: 465
username: developeraki@naver.com
password: onerooflab!
properties:
mail.smtp.auth: true
mail.smtp.ssl.enable: true
security:
oauth2:
client:
Expand Down
12 changes: 12 additions & 0 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ server:
cookie:
http-only: false
secure: false




jwt:
secret: ENC(1MBsToCDbYBEvJkfxlSkoBb30kG1MYPqYOcyUcKZOhnodcSkYMncHeTYNyKr0GfYocr9yI3G1cR6DJHykIZTpQ==)

Expand All @@ -18,6 +22,14 @@ logging:
EC2MetadataUtils: error

spring:
mail:
host: smtp.naver.com
port: 465
username: developeraki@naver.com
password: onerooflab!
properties:
mail.smtp.auth: true
mail.smtp.ssl.enable: true
servlet:
multipart:
max-file-size: 2MB
Expand Down

0 comments on commit d82bf93

Please sign in to comment.