Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void incrementCorrectSubmissions() {
}

public boolean isGitPushStatus() {
return user.isGitPushStatus();
return user.getGitPushStatus();
}

public Long getUserId() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public class SignupRequest {
@Size(max = 15, message = "이름은 15글자 이하로 입력 가능합니다")
private String username;

@Schema(description = "사용자 별명 (최대 20자)", example = "다람쥐쳇바퀴에굴러가")
@NotBlank(message = "별명은 반드시 입력되어야합니다")
@Size(max = 20, message = "별명은 20글자 이하로 입력 가능합니다")
private String nickname;

//선택적 입력
@Schema(description = "나이 (선택 입력)", example = "25")
private Integer age;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
@Schema(description = "이메일 인증 번호 입력 응답")
public record VerifyEmailCodeResponse(
@Schema(description = "인증 번호 성공 응답 메세지")
String message
String message,

@Schema(description = "인증 성공 여부 true/false")
boolean result
) {
public static VerifyEmailCodeResponse from(String message) {
return new VerifyEmailCodeResponse(message);
public static VerifyEmailCodeResponse from(String message, boolean result) {
return new VerifyEmailCodeResponse(message, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.concurrent.TimeUnit;

import org.ezcode.codetest.application.usermanagement.auth.dto.request.FindPasswordRequest;
import org.ezcode.codetest.application.usermanagement.auth.dto.request.ResetPasswordRequest;
import org.ezcode.codetest.application.usermanagement.auth.dto.response.FindPasswordResponse;
import org.ezcode.codetest.application.usermanagement.auth.dto.response.RefreshTokenResponse;
import org.ezcode.codetest.application.usermanagement.auth.dto.request.SigninRequest;
Expand All @@ -13,7 +12,10 @@
import org.ezcode.codetest.application.usermanagement.auth.dto.request.SignupRequest;
import org.ezcode.codetest.application.usermanagement.auth.dto.response.SignupResponse;
import org.ezcode.codetest.application.usermanagement.auth.dto.response.VerifyEmailCodeResponse;
import org.ezcode.codetest.application.usermanagement.user.dto.request.ResetPasswordRequest;
import org.ezcode.codetest.application.usermanagement.user.dto.response.ChangeUserPasswordResponse;
import org.ezcode.codetest.application.usermanagement.user.dto.response.LogoutResponse;
import org.ezcode.codetest.application.usermanagement.user.dto.response.VerifyFindPasswordResponse;
import org.ezcode.codetest.domain.user.exception.AuthException;
import org.ezcode.codetest.domain.user.exception.UserException;
import org.ezcode.codetest.domain.user.exception.code.AuthExceptionCode;
Expand Down Expand Up @@ -77,11 +79,12 @@ private void userRegisterationProcess(SignupRequest request) {

//3. 만약 아예 첫 가입 유저일 때
private void createNewUser(SignupRequest request, String encodedPassword) {
String nickname = userDomainService.generateUniqueNickname();
User newUser = User.emailUser(
request.getEmail(),
encodedPassword,
request.getUsername(),
request.getNickname(),
nickname,
request.getAge()
);

Expand Down Expand Up @@ -113,7 +116,7 @@ public VerifyEmailCodeResponse verifyEmailCode(String email, String key) {

if (isMatch){
user.setVerified();
return VerifyEmailCodeResponse.from("인증되었습니다");
return VerifyEmailCodeResponse.from("인증되었습니다", isMatch);
} else {
throw new UserException(UserExceptionCode.NOT_MATCH_CODE);
}
Expand Down Expand Up @@ -228,22 +231,38 @@ public FindPasswordResponse findPassword(FindPasswordRequest request) {

mailService.sendPasswordMail(user.getId(), request.getEmail(), request.getRedirectUrl());

return FindPasswordResponse.from("이메일로 전송되었습니다.");
return FindPasswordResponse.from("이메일 전송되었습니다.");
}

//메일로 받은 링크를 통해 비번 변경
public FindPasswordResponse resetPassword(ResetPasswordRequest request) {
public VerifyFindPasswordResponse verifyFindPassword(String email, String key) {

User user = userDomainService.getUserByEmail(request.getEmail());
User user = userDomainService.getUserByEmail(email);

boolean isMatch = mailService.verifyPasswordCode(user.getId(), key);

boolean isMatch = mailService.verifyPasswordCode(user.getId(), request.getToken());
String tempResetToken = jwtUtil.createEmailToken(user.getId(), email);

if (isMatch){
String encodedPassword = userDomainService.encodePassword(request.getNewPassword());
user.modifyPassword(encodedPassword);
return FindPasswordResponse.from("비밀번호가 변경되었습니다.");
user.setVerified();
return VerifyFindPasswordResponse.from("인증되었습니다", tempResetToken);
} else {
throw new UserException(UserExceptionCode.NOT_MATCH_CODE);
}
}

@Transactional
public ChangeUserPasswordResponse resetPassword(@Valid ResetPasswordRequest request) {
Long userId = jwtUtil.getUserId(request.tempResetToken());
log.info("요청 유저 id : {}", userId);

User user = userDomainService.getUserById(userId);
//기존과 같은 비밀번호일때
userDomainService.passwordComparison(request.newPassword(), user.getPassword());
if (!request.newPassword().equals(request.newPasswordConfirm())){
throw new AuthException(AuthExceptionCode.PASSWORD_NOT_MATCH);
}
String encodedPassword = userDomainService.encodePassword(request.newPassword());
user.modifyPassword(encodedPassword);
return new ChangeUserPasswordResponse("비밀번호 변경이 완료되었습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.ezcode.codetest.application.usermanagement.user.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "비밀번호 리셋을 위한 입력")
public record ResetPasswordRequest (
@Schema(description = "비밀번호 리셋 유저의 토큰 - 유효 시간 10분")
String tempResetToken,

@Schema(description = "변경할 비밀번호", example = "myPassword@@!")
String newPassword,

@Schema(description = "변경할 비밀번호 확인용 재입력", example = "myPassword@@!")
String newPasswordConfirm
){
public static ResetPasswordRequest from(String tempResetToken, String newPassword, String newPasswordConfirm) {
return new ResetPasswordRequest(tempResetToken, newPassword, newPasswordConfirm);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.ezcode.codetest.application.usermanagement.user.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
@Schema(description = "깃허브 자동 Push 여부 변경 후 응답")
public class UserGitubAutoPushResponse {
@Schema(description = "메세지", example = "변경되었습니다")
private final String message;
@Schema(description = "현재 상태", example = "true")
private final boolean gitPushStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public class UserInfoResponse {
@Schema(description = "사용자 티어", example = "GOLD")
private final Tier tier;

@Schema(description = "인증 여부", example = "true")
private final boolean verified;

@Builder
public UserInfoResponse(String username, String email, String nickname, UserRole userRole, Tier tier,
Integer age, String githubUrl, String blogUrl, String profileImageUrl, String introduction) {
Integer age, String githubUrl, String blogUrl, String profileImageUrl, String introduction, boolean verified) {
this.username = username;
this.email = email;
this.nickname = nickname;
Expand All @@ -54,7 +57,8 @@ public UserInfoResponse(String username, String email, String nickname, UserRole
this.introduction = introduction;
this.tier = tier;
this.userRole = userRole;
}
this.verified = verified;
}

public static UserInfoResponse fromEntity(User user) {
return UserInfoResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.ezcode.codetest.application.usermanagement.user.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "비밀번호 찾기 인증 응답")
public record VerifyFindPasswordResponse(
@Schema(description = "인증 번호 성공 응답 메세지")
String message,

@Schema(description = "인증 성공 후 발급, 유저 정보를 담은 토큰(email, userId), 유효시간 10분")
String tempResetToken
) {
public static VerifyFindPasswordResponse from(String message, String tempResetToken) {
return new VerifyFindPasswordResponse(message, tempResetToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public UserInfoResponse getUserInfo(AuthUser authUser) {
.githubUrl(user.getGithubUrl())
.userRole(user.getRole())
.tier(user.getTier())
.verified(user.isVerified())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,23 @@ public boolean validateToken(String refreshToken) {
return false;
}
}

public String createEmailToken(Long userId, String email) {
if ( email == null ) {
throw new IllegalArgumentException("토큰에 필요한 필수 매개변수가 null입니다.");
}

Date date = new Date();
long EXPIRATION_TIME = 600 * 1000; // 10분

return BEARER_PREFIX +
Jwts.builder()
.setSubject(String.valueOf(userId))
.claim("email", email)
.setExpiration(new Date(date.getTime() + EXPIRATION_TIME))
.setIssuedAt(date)
.signWith(key, signatureAlgorithm)
.compact();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,15 @@ public void setGithubUrl(String githubUrl){
this.githubUrl = githubUrl;
}


public void decreaseReviewToken() {
this.reviewToken -= 1;
}

public void setGitPushStatus(boolean gitPushStatus) {
this.gitPushStatus = gitPushStatus;
}

public boolean getGitPushStatus() {
return gitPushStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public MimeMessage CreatePasswordMail(Long userId, String email, String redirect
String body = "";
body += "<h3>" + "아래 버튼을 클릭하여 비밀번호 변경을 완료해 주세요" + "</h3>";
// 이메일 버튼
body += "<a href='"+redirectUrl+"/api/auth/reset-password?email="+ email + "&key=" + verificationCode + "' target='_blenk'>비밀번호 변경하기</a>";
body += "<a href='"+redirectUrl+"/api/auth/find-password-verify?email="+ email + "&key=" + verificationCode + "' target='_blenk'>비밀번호 변경하기</a>";
body += "<h3>" + "감사합니다." + "</h3>";
message.setText(body,"UTF-8", "html");
} catch (MessagingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
public class UserDomainService {
private final UserRepository userRepository;
private final UserAuthTypeRepository userAuthTypeRepository;
private final UserGithubInfoRepository userGithubInfoRepository;
private final PasswordEncoder passwordEncoder;
private static final java.util.Random RANDOM = new java.util.Random();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

import org.ezcode.codetest.application.usermanagement.user.dto.request.UserGithubRepoSelectRequest;
import org.ezcode.codetest.application.usermanagement.user.dto.response.UserGithubRepoResponse;
import org.ezcode.codetest.application.usermanagement.user.dto.response.UserGitubAutoPushResponse;
import org.ezcode.codetest.common.security.util.AESUtil;
import org.ezcode.codetest.domain.user.exception.UserException;
import org.ezcode.codetest.domain.user.exception.code.UserExceptionCode;
import org.ezcode.codetest.domain.user.model.entity.AuthUser;
import org.ezcode.codetest.domain.user.model.entity.User;
import org.ezcode.codetest.domain.user.model.entity.UserGithubInfo;
import org.ezcode.codetest.domain.user.repository.UserGithubInfoRepository;
import org.springframework.core.ParameterizedTypeReference;
Expand All @@ -20,8 +22,10 @@

import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

@Slf4j
@Service
@RequiredArgsConstructor
public class UserGithubService {
Expand Down Expand Up @@ -100,8 +104,26 @@ public UserGithubRepoResponse selectGithubRepo(AuthUser authUser, UserGithubRepo
.orElseThrow(() -> new UserException(UserExceptionCode.NO_GITHUB_REPO));

userGithub.setGithubRepo(request.repositoryName(), selectedRepo.getDefaultBranch());

userGithubInfoRepository.updateGithubInfo(userGithub);

User user = userGithub.getUser();
user.setGitPushStatus(true); //레포를 선택하면 자동으로 push 설정이 true

return selectedRepo;
}

@Transactional
public UserGitubAutoPushResponse changeAutoPushSetting(AuthUser authUser) {
UserGithubInfo userGithubInfo = userGithubInfoRepository.getUserGithubInfo(authUser.getId());
if (userGithubInfo == null) { //유저의 깃허브 정보가 없으면 에러 반환
throw new UserException(UserExceptionCode.NO_GITHUB_INFO);
}
User user = userGithubInfo.getUser();
boolean userGitPushStatus = user.getGitPushStatus();
user.setGitPushStatus(!userGitPushStatus);
log.info("기존 status: {} || 변경 status : {}", userGitPushStatus, user.getGitPushStatus());

return new UserGitubAutoPushResponse("변경되었습니다", user.getGitPushStatus());
}
}
Loading