Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 2.3.0 #93

Merged
merged 20 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d20f97b
[refactor/72-task] 주석지우기 및 코드 리펙토링
lsn5963 Jan 10, 2024
68c149e
[refactor/72-task] 주석지우기 및 코드 리펙토링
lsn5963 Jan 10, 2024
9e1f5a1
[refactor/72-task] dto req res 구분
lsn5963 Jan 10, 2024
b71a650
[refactor/72-task] mail 본문 내용 수정하기
lsn5963 Jan 10, 2024
0b7dac2
[refactor/72-task] @data 수정
lsn5963 Jan 10, 2024
435469a
Refactor: 프젝, 마이페이지 Swagger 명세 추가
ibaesuyeon Jan 12, 2024
4338603
[refactor/72-task] 푸쉬 실수 수정
lsn5963 Jan 12, 2024
05f12a9
[refactor/72-task] 키워드 수정
lsn5963 Jan 12, 2024
66e226c
Merge branch 'develop' into feature/project-post
ibaesuyeon Jan 13, 2024
498b8a5
[refactor/72-task] 메일보내기 설정 수정
lsn5963 Jan 13, 2024
41b97ae
[refactor/72-task] 비밀번호바꾸기 auth로 이동
lsn5963 Jan 13, 2024
e3ff0a6
[refactor/72-task] req -> request, res -> response
lsn5963 Jan 13, 2024
b850d80
[refactor/72-task] req -> request, res -> response
lsn5963 Jan 13, 2024
2d9c4ec
Merge pull request #77 from IDEA-CAMPUS/refactor/72-task
lsn5963 Jan 13, 2024
0232b93
Merge pull request #90 from IDEA-CAMPUS/feature/project-post
ibaesuyeon Jan 13, 2024
b067dfb
Refactor: 파일이 없는 경우에 대한 exception 추가
ibaesuyeon Jan 13, 2024
133c728
Merge pull request #91 from IDEA-CAMPUS/feature/image
jisujeong0 Jan 13, 2024
854bf7d
[refactor/72-task] 검증로직 추가
lsn5963 Jan 13, 2024
50a529d
Merge branch 'develop' of https://github.com/IDEA-CAMPUS/IDEA-CAMPUS-…
lsn5963 Jan 13, 2024
f81973a
Merge pull request #92 from IDEA-CAMPUS/refactor/72-task
jisujeong0 Jan 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

import depth.main.ideac.domain.admin.application.AdminService;
import depth.main.ideac.domain.auth.application.AuthService;
import depth.main.ideac.domain.auth.dto.AuthRes;
import depth.main.ideac.domain.auth.dto.FindIdReq;
import depth.main.ideac.domain.auth.dto.SignInReq;
import depth.main.ideac.domain.auth.dto.SignUpReq;
import depth.main.ideac.domain.user.application.UserService;
import depth.main.ideac.domain.user.domain.User;
import depth.main.ideac.domain.auth.dto.response.AuthRes;
import depth.main.ideac.domain.auth.dto.request.FindIdReq;
import depth.main.ideac.domain.auth.dto.request.SignInReq;
import depth.main.ideac.domain.auth.dto.request.PasswordReq;
import depth.main.ideac.global.payload.ErrorResponse;
import depth.main.ideac.global.payload.Message;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -22,7 +20,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Auth API", description = "Authorization 관련 API입니다.")
Expand Down Expand Up @@ -66,4 +63,15 @@ public ResponseEntity<?> findId(@Parameter(description = "Schemas의 FindIdReque
return authService.findId(findIdReq);
}

@Operation(summary = "비밀번호 바꾸기", description = "비밀번호를 바꾼다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "비밀번호 바꾸기 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}),
@ApiResponse(responseCode = "400", description = "비밀번호 바꾸기 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))})
})
@PostMapping(value = "/change-password/{code}")
public ResponseEntity<?> changePassword(@Parameter(description = "Schemas의 PassWordReq를 참고해주세요.")
@Valid @RequestBody PasswordReq passwordReq,
@PathVariable String code) {
return authService.changePassword(passwordReq,code);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package depth.main.ideac.domain.user.presentation;

import depth.main.ideac.domain.user.application.UserService;
import depth.main.ideac.domain.user.dto.PasswordReq;
import depth.main.ideac.global.config.security.token.CurrentUser;
import depth.main.ideac.global.config.security.token.UserPrincipal;
import depth.main.ideac.global.payload.ErrorResponse;
Expand All @@ -12,7 +11,6 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -23,17 +21,6 @@
public class UserController {

private final UserService userService;
@Operation(summary = "메일 보내기", description = "비밀번호를 찾기위해 메일을 보낸다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "비밀번호 바꾸기 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}),
@ApiResponse(responseCode = "400", description = "비밀번호 바꾸기 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))})
})
@PostMapping(value = "/change-password/{code}")
public ResponseEntity<?> changePassword(@Parameter(description = "Schemas의 PassWordReq를 참고해주세요.")
@Valid @RequestBody PasswordReq passwordReq,
@PathVariable String code) {
return userService.changePassword(passwordReq,code);
}

@Operation(summary = "로그아웃", description = "로그아웃 API입니다.")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,42 @@
import depth.main.ideac.domain.auth.domain.Token;
import depth.main.ideac.domain.auth.domain.repository.TokenRepository;
import depth.main.ideac.domain.auth.dto.*;
import depth.main.ideac.domain.auth.dto.request.FindIdReq;
import depth.main.ideac.domain.auth.dto.request.RefreshTokenReq;
import depth.main.ideac.domain.auth.dto.request.SignInReq;
import depth.main.ideac.domain.auth.dto.request.SignUpReq;
import depth.main.ideac.domain.auth.dto.response.AuthRes;
import depth.main.ideac.domain.mail.domain.Verify;
import depth.main.ideac.domain.mail.domain.repository.MailRepository;
import depth.main.ideac.domain.user.domain.Role;
import depth.main.ideac.domain.user.domain.Status;
import depth.main.ideac.domain.user.domain.User;
import depth.main.ideac.domain.user.domain.repository.UserRepository;
import depth.main.ideac.domain.auth.dto.request.PasswordReq;
import depth.main.ideac.global.DefaultAssert;
import depth.main.ideac.global.error.DefaultException;
import depth.main.ideac.global.payload.ApiResponse;
import depth.main.ideac.global.payload.ErrorCode;
import depth.main.ideac.global.payload.Message;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Optional;


@RequiredArgsConstructor
@Service
@Slf4j
public class AuthService {

private final AuthenticationManager authenticationManager;
Expand All @@ -34,13 +47,12 @@ public class AuthService {

private final UserRepository userRepository;
private final TokenRepository tokenRepository;
private final MailRepository mailRepository;

// 회원가입 하기
public ResponseEntity<?> signUp(SignUpReq signUpRequest){

// //검증
// DefaultAssert.isTrue(!userRepository.existsByEmail(signUpRequest.getIdEmail()), "해당 이메일이 존재합니다.");
// DefaultAssert.isTrue(!userRepository.existsByNickname(signUpRequest.getNickname()), "이미 존재하는 닉네임입니다.");
DefaultAssert.isTrue(signUpRequest.getPassword().equals(signUpRequest.getCheckPassword()), "비밀번호가 서로 다릅니다.");

User user = User.builder()
.email(signUpRequest.getIdEmail())
Expand Down Expand Up @@ -70,7 +82,6 @@ public ResponseEntity<?> signUp(SignUpReq signUpRequest){
//로그인 하기
public ResponseEntity<?> signIn(SignInReq signInReq){


Optional<User> user = userRepository.findByEmail(signInReq.getEmail());
DefaultAssert.isTrue(user.isPresent(), "이메일이 틀렸습니다.");

Expand All @@ -79,7 +90,6 @@ public ResponseEntity<?> signIn(SignInReq signInReq){
throw new DefaultException(ErrorCode.INVALID_CHECK, "정지되었거나 탈퇴된 유저입니다.");
}


boolean checkPassword = passwordEncoder.matches(signInReq.getPassword(), findUser.getPassword());
DefaultAssert.isTrue(checkPassword, "비밀번호가 틀렸습니다");

Expand All @@ -89,7 +99,6 @@ public ResponseEntity<?> signIn(SignInReq signInReq){
signInReq.getPassword()
)
);

SecurityContextHolder.getContext().setAuthentication(authentication);

TokenMapping tokenMapping = customTokenProviderService.createToken(authentication);
Expand All @@ -103,20 +112,20 @@ public ResponseEntity<?> signIn(SignInReq signInReq){
AuthRes authResponse = AuthRes.builder()
.accessToken(tokenMapping.getAccessToken())
.refreshToken(token.getRefreshToken()).build();

return ResponseEntity.ok(authResponse);
}

// 핸드폰번호로 아이디(이메일) 찾기
public ResponseEntity<?> findId(FindIdReq findIdReq) {
System.out.println("findIdReq.getPhoneNumber() = " + findIdReq.getPhoneNumber());
Optional<User> findUser = userRepository.findByPhoneNumber(findIdReq.getPhoneNumber());
DefaultAssert.isTrue(findUser.isPresent(), "해당이메일을 갖고 있는 유저가 없습니다.");

User user = findUser.get();
System.out.println("user.getEmail() = " + user.getEmail());
ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(user.getEmail())
.message("가입하신 아이디를 찾아왔어요!")
.build();
return ResponseEntity.ok(apiResponse);
}
Expand Down Expand Up @@ -164,21 +173,51 @@ private boolean valid(String refreshToken){
return true;
}

// 닉네임 중복검증
public ResponseEntity<?> doubleCheckNickname(String nickname) {
ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(userRepository.findByNickname(nickname).isEmpty())
.message("닉네임 검증 완료")
.build();
return ResponseEntity.ok(apiResponse);
}

// 이메일 중복검증
public ResponseEntity<?> doubleCheckEmail(String email) {
ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(userRepository.findByEmail(email).isEmpty())
.message("이메일 검증 완료")
.build();
return ResponseEntity.ok(apiResponse);
}

@Transactional
public ResponseEntity<?> changePassword(@Valid PasswordReq passwordReq, String code){

//검증
DefaultAssert.isTrue(passwordReq.getPassword().equals(passwordReq.getRePassword()), "비밀번호가 서로 다릅니다.");
//만료시간 검증
Verify verify = mailRepository.findByCode(code);

if (verify == null){
throw new DefaultException(ErrorCode.INVALID_CHECK, "이미변경되었습니다.");
}

DefaultAssert.isTrue(verify.checkExpiration(LocalDateTime.now()), "만료되었습니다.");

Optional<User> findUser = userRepository.findByEmail(verify.getEmail());

User user = findUser.get();
user.updatePassWord(passwordEncoder.encode(passwordReq.getPassword()));

// 인증완료 후 삭제
mailRepository.delete(verify);

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(null)
.build();

return ResponseEntity.ok(apiResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ private OAuth2User processOAuth2User(OAuth2UserRequest oAuth2UserRequest, OAuth2

Optional<User> userOptional = userRepository.findByEmail(oAuth2UserInfo.getEmail());
User user;
if(userOptional.isPresent()) {
user = userOptional.get();
DefaultAssert.isAuthentication(user.getProvider().equals(Provider.valueOf(oAuth2UserRequest.getClientRegistration().getRegistrationId())));
// user = updateExistingUser(user, oAuth2UserInfo);
} else {
user = registerNewUser(oAuth2UserRequest, oAuth2UserInfo);
log.info("통과1");

}
user = registerNewUser(oAuth2UserRequest, oAuth2UserInfo);

return UserPrincipal.create(user, oAuth2User.getAttributes());
}

// oauth2 회원 등록
private User registerNewUser(OAuth2UserRequest oAuth2UserRequest, OAuth2UserInfo oAuth2UserInfo) {
User user = User.builder()
.provider(Provider.valueOf(oAuth2UserRequest.getClientRegistration().getRegistrationId()))
Expand All @@ -67,12 +60,4 @@ private User registerNewUser(OAuth2UserRequest oAuth2UserRequest, OAuth2UserInfo
.build();
return userRepository.save(user);
}

// private User updateExistingUser(User user, OAuth2UserInfo oAuth2UserInfo) {
//// 추후 사용시 바뀔예정인 함수
//// user.updateName(oAuth2UserInfo.getName());
//// user.updateImageUrl(oAuth2UserInfo.getImageUrl());
//
// return userRepository.save(user);
// }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package depth.main.ideac.domain.auth.dto;
package depth.main.ideac.domain.auth.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package depth.main.ideac.domain.user.dto;
package depth.main.ideac.domain.auth.dto.request;

import jakarta.validation.constraints.Pattern;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package depth.main.ideac.domain.auth.dto;
package depth.main.ideac.domain.auth.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;

@Data
@Getter
public class RefreshTokenReq {

@Schema( type = "string", example = "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE2NTI3OTgxOTh9.6CoxHB_siOuz6PxsxHYQCgUT1_QbdyKTUwStQDutEd1-cIIARbQ0cyrnAmpIgi3IBoLRaqK7N1vXO42nYy4g5g", description="refresh token 입니다." )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package depth.main.ideac.domain.auth.dto;
package depth.main.ideac.domain.auth.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
import lombok.Getter;


@Data
@Getter
public class SignInReq {

@Schema( type = "string", example = "[email protected]", description="계정 이메일 입니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package depth.main.ideac.domain.auth.dto;
package depth.main.ideac.domain.auth.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.persistence.Column;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.Getter;

@Getter
Expand All @@ -15,6 +14,7 @@ public class SignUpReq {
private String idEmail;

@Schema( type = "string", example = "홍길동", description="이름")
@Size(min = 2, message = "2자 이상 입력해주세요")
@NotBlank
private String name;

Expand All @@ -35,6 +35,7 @@ public class SignUpReq {

@Schema( type = "string", example = "01012341234", description="휴대폰번호")
@NotBlank
@Pattern(regexp = "^01([0|1|6|7|8|9])?([0-9]{3,4})?([0-9]{4})$", message = "번호를 정확하게 입력해주세요")
private String phoneNumber;

@Schema( type = "string", example = "depth", description="소속 동아리")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package depth.main.ideac.domain.auth.dto;
package depth.main.ideac.domain.auth.dto.response;

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

@Data
@Getter
public class AuthRes {

@Schema( type = "string", example = "eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE2NTI3OTgxOTh9.6CoxHB_siOuz6PxsxHYQCgUT1_QbdyKTUwStQDutEd1-cIIARbQ0cyrnAmpIgi3IBoLRaqK7N1vXO42nYy4g5g" , description="access token 을 출력합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,4 @@ public class IdeaPost extends BaseEntity {
private User user;

private Long hits;

// public void updateIdea(UpdateIdeaReq updateIdeaReq) {
// this.title = updateIdeaReq.getTitle();
// this.simpleDescription = updateIdeaReq.getSimpleDescription();
// this.detailedDescription = updateIdeaReq.getDetailedDescription();
// this.url1 = updateIdeaReq.getUrl1();
// this.url2 = updateIdeaReq.getUrl2();
// }
}
Loading