Skip to content

Commit ede775b

Browse files
authored
[FEAT] Prod 서버 배포 CD 구축 및 1차 배포
[FEAT] Prod 서버 배포 CD 구축 및 1차 배포
2 parents 83c3c21 + a7f73be commit ede775b

File tree

12 files changed

+87
-8
lines changed

12 files changed

+87
-8
lines changed

.github/workflows/cd-main.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: Dockerizing to Amazon ECR for Prod
33
on:
44
push:
55
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
86

97
env:
108
AWS_REGION: ap-northeast-2
@@ -80,4 +78,4 @@ jobs:
8078
# # Use the Dockerfile.prod and build the image
8179
# docker build -f Dockerfile.main --build-arg SPRING_PROFILES_ACTIVE=main -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
8280
# # Push the image to ECR
83-
# docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
81+
# docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Java CI with Gradle
22

33
on:
44
pull_request:
5-
branches: [ "release", "develop" ]
5+
branches: [ "main", "develop" ]
66

77

88
jobs:
@@ -71,4 +71,4 @@ jobs:
7171
run: chmod +x gradlew
7272

7373
- name: Build with Gradle
74-
run: ./gradlew clean build
74+
run: ./gradlew clean build

src/main/java/swm/betterlife/antifragile/common/config/SecurityConfig.java

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.springframework.http.HttpMethod.DELETE;
44
import static org.springframework.http.HttpMethod.GET;
5+
import static org.springframework.http.HttpMethod.POST;
56

67
import java.util.Arrays;
78
import java.util.List;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package swm.betterlife.antifragile.common.exception;
2+
3+
import swm.betterlife.antifragile.common.exception.code.ErrorCode;
4+
5+
public class PasswordSameException extends BaseException {
6+
public PasswordSameException() {
7+
super(ErrorCode.PASSWORD_SAME.getMessage());
8+
}
9+
}

src/main/java/swm/betterlife/antifragile/common/exception/code/ErrorCode.java

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum ErrorCode {
1414
// Member
1515
MEMBER_NOT_FOUND("멤버를 찾을 수 없습니다"),
1616
HUMAN_MEMBER_CANNOT_BE_ACCESSED("휴먼 계정의 아이디의 정보는 조회할 수 없습니다"),
17+
PASSWORD_SAME("새로운 비밀번호는 기존 비밀번호와 달라야합니다."),
1718

1819
// DiaryAnalysis
1920
DIARY_ANALYSIS_NOT_FOUND("해당 날짜에 사용자의 일기 분석을 찾을 수 없습니다"),

src/main/java/swm/betterlife/antifragile/domain/auth/controller/AuthController.java

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public ResponseBody<Void> logout(
5050
return ResponseBody.ok();
5151
}
5252

53+
5354
@DeleteMapping()
5455
public ResponseBody<Void> delete(
5556
@AuthenticationPrincipal PrincipalDetails principalDetails

src/main/java/swm/betterlife/antifragile/domain/auth/dto/request/AuthSignUpRequest.java

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
public record AuthSignUpRequest(
99
String email,
10+
String password,
1011
LoginType loginType,
1112
String nickname,
1213
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package swm.betterlife.antifragile.domain.auth.dto.request;
2+
3+
public record PasswordModifyRequest(
4+
String curPassword,
5+
String newPassword
6+
) {
7+
}

src/main/java/swm/betterlife/antifragile/domain/auth/service/AuthService.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ public AuthSignUpResponse signUp(
8181
throw new RuntimeException("이미 존재하는 이메일입니다."); //todo: Custom Ex
8282
}
8383

84-
String password = getPasswordByLoginType(authSignUpRequest.loginType());
84+
String password = getPasswordByLoginType(
85+
authSignUpRequest.loginType(), authSignUpRequest.password()
86+
);
8587
String encodedPassword = passwordEncoder.encode(password);
8688

8789
Member member = Member.builder()
@@ -141,8 +143,9 @@ private Authentication getAuthenticate(
141143
return authenticationManagerBuilder.getObject().authenticate(authenticationToken);
142144
}
143145

144-
private String getPasswordByLoginType(LoginType loginType) {
146+
private String getPasswordByLoginType(LoginType loginType, String password) {
145147
return switch (loginType) {
148+
case NORMAL -> password;
146149
case GOOGLE -> googlePassword;
147150
case KAKAO -> kakaoPassword;
148151
case NAVER -> naverPassword;

src/main/java/swm/betterlife/antifragile/domain/member/controller/MemberController.java

+14
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import org.springframework.security.core.annotation.AuthenticationPrincipal;
66
import org.springframework.web.bind.annotation.GetMapping;
77
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.RequestBody;
89
import org.springframework.web.bind.annotation.RequestMapping;
910
import org.springframework.web.bind.annotation.RequestParam;
1011
import org.springframework.web.bind.annotation.RequestPart;
1112
import org.springframework.web.bind.annotation.RestController;
1213
import org.springframework.web.multipart.MultipartFile;
1314
import swm.betterlife.antifragile.common.response.ResponseBody;
1415
import swm.betterlife.antifragile.common.security.PrincipalDetails;
16+
import swm.betterlife.antifragile.domain.auth.dto.request.PasswordModifyRequest;
1517
import swm.betterlife.antifragile.domain.member.dto.request.MemberProfileModifyRequest;
1618
import swm.betterlife.antifragile.domain.member.dto.response.MemberDetailInfoResponse;
1719
import swm.betterlife.antifragile.domain.member.dto.response.MemberInfoResponse;
@@ -82,4 +84,16 @@ public ResponseBody<MemberStatusResponse> checkMemberStatus(
8284
memberService.checkMemberStatus(email, loginType)
8385
);
8486
}
87+
88+
@PostMapping("/password")
89+
public ResponseBody<Void> modifyPassword(
90+
@AuthenticationPrincipal PrincipalDetails principalDetails,
91+
@RequestBody PasswordModifyRequest passwordModifyRequest
92+
) {
93+
memberService.modifyPassword(
94+
principalDetails.email(), principalDetails.memberId(),
95+
principalDetails.loginType(), passwordModifyRequest
96+
);
97+
return ResponseBody.ok();
98+
}
8599
}

src/main/java/swm/betterlife/antifragile/domain/member/entity/LoginType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@Getter
77
@RequiredArgsConstructor
88
public enum LoginType {
9-
GOOGLE("구글"), NAVER("네이버"), KAKAO("카카오");
9+
NORMAL("일반"), GOOGLE("구글"), NAVER("네이버"), KAKAO("카카오");
1010

1111
private final String toKorean;
1212
}

src/main/java/swm/betterlife/antifragile/domain/member/service/MemberService.java

+44
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@
1313
import org.springframework.data.mongodb.core.query.Query;
1414
import org.springframework.data.mongodb.core.query.Update;
1515
import org.springframework.scheduling.annotation.Scheduled;
16+
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
17+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
18+
import org.springframework.security.core.Authentication;
19+
import org.springframework.security.crypto.password.PasswordEncoder;
1620
import org.springframework.stereotype.Service;
1721
import org.springframework.transaction.annotation.Transactional;
1822
import org.springframework.web.multipart.MultipartFile;
1923
import swm.betterlife.antifragile.common.exception.ExcessRecommendLimitException;
2024
import swm.betterlife.antifragile.common.exception.MemberNotFoundException;
25+
import swm.betterlife.antifragile.common.exception.PasswordSameException;
2126
import swm.betterlife.antifragile.common.util.S3ImageComponent;
27+
import swm.betterlife.antifragile.domain.auth.dto.request.PasswordModifyRequest;
2228
import swm.betterlife.antifragile.domain.member.controller.MemberNicknameDuplResponse;
2329
import swm.betterlife.antifragile.domain.member.dto.request.MemberProfileModifyRequest;
2430
import swm.betterlife.antifragile.domain.member.dto.response.MemberDetailInfoResponse;
@@ -40,6 +46,10 @@ public class MemberService {
4046
private final MemberPointService memberPointService;
4147
private final MemberDiaryService memberDiaryService;
4248
private final S3ImageComponent s3ImageComponent;
49+
private final PasswordEncoder passwordEncoder;
50+
private final AuthenticationManagerBuilder authenticationManagerBuilder;
51+
52+
4353

4454
@Transactional(readOnly = true)
4555
public MemberInfoResponse findMemberById(String id) {
@@ -149,6 +159,30 @@ public MemberStatusResponse checkMemberStatus(
149159

150160
}
151161

162+
@Transactional
163+
public void modifyPassword(
164+
String email, String memberId,
165+
LoginType loginType, PasswordModifyRequest passwordModifyRequest
166+
) {
167+
String curPassword = passwordModifyRequest.curPassword();
168+
String newPassword = passwordModifyRequest.newPassword();
169+
Authentication authentication
170+
= getAuthenticate(email, curPassword, loginType);
171+
172+
if (curPassword.equals(newPassword)) {
173+
throw new PasswordSameException();
174+
}
175+
String encodedPassword = passwordEncoder.encode(newPassword);
176+
Query query = new Query(Criteria.where("id").is(memberId));
177+
Update update = new Update().set("password", encodedPassword);
178+
179+
UpdateResult result = mongoTemplate.updateFirst(query, update, Member.class);
180+
181+
if (result.getMatchedCount() == 0) {
182+
throw new MemberNotFoundException();
183+
}
184+
}
185+
152186
@Scheduled(cron = "0 0 0 * * *")
153187
public void resetRemainRecommendNumber() {
154188
Query query = new Query();
@@ -157,4 +191,14 @@ public void resetRemainRecommendNumber() {
157191
mongoTemplate.updateMulti(query, update, Member.class);
158192
}
159193

194+
private Authentication getAuthenticate(
195+
String email, String password,
196+
LoginType loginType
197+
) {
198+
String username = loginType.name() + ":" + email;
199+
UsernamePasswordAuthenticationToken authenticationToken
200+
= new UsernamePasswordAuthenticationToken(username, password);
201+
return authenticationManagerBuilder.getObject().authenticate(authenticationToken);
202+
}
203+
160204
}

0 commit comments

Comments
 (0)