Skip to content

Commit

Permalink
Merge pull request #68 from choboss00/feature/1-branch-account
Browse files Browse the repository at this point in the history
FE 요청에 따른 변경
  • Loading branch information
comom87 authored Nov 6, 2023
2 parents efbd65b + 03e3e65 commit bf964f4
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class JWTTokenProvider {
public static final String Token_Prefix = "Bearer ";

public static final String SecretKey = "a2FrYW8tdGVjaC1jYW1wdXMtcHJvamVjdC1nYXJkZW4tc3ByaW5nLXNlY3VyaXR5LWp3dC10b2tlbi1zZWNyZXQta2V5";
public static final int AccessTokenValidTime = 1000 * 60 * 2;
public static final int RefreshTokenValidTime = 1000 * 60 * 5;
public static final int AccessTokenValidTime = 1000 * 60 * 5; // 5분
public static final int RefreshTokenValidTime = 1000 * 60 * 60 * 24; // 1일

private final CustomUserDetailService userDetailService;
private final RefreshTokenJPARepository refreshTokenJPARepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws

// 11. 인증, 권한 필터 설정
httpSecurity.authorizeRequests(
authorize -> authorize.antMatchers("/profiles/**").authenticated()
authorize -> authorize
.antMatchers("/admin/**").access("hasRole('ADMIN')")
.anyRequest().permitAll()
);
Expand All @@ -88,7 +88,7 @@ public CorsConfigurationSource configurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.addAllowedHeader("*");
configuration.addAllowedMethod("*"); // GET, POST, PUT, DELETE (Javascript 요청 허용)
configuration.addAllowedOriginPattern("http://localhost:8080"); // 모든 IP 주소 허용 (프론트 앤드 IP만 허용 react)
configuration.addAllowedOriginPattern("*"); // 모든 IP 주소 허용 (프론트 앤드 IP만 허용 react)
configuration.setAllowCredentials(true); // 클라이언트에서 쿠키 요청 허용
configuration.addExposedHeader("Authorization");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.example.demo.mentoring.contact.ContactStateEnum;
import com.example.demo.mentoring.contact.NotConnectedRegisterUser;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.example.demo.config.errors.exception.Exception404;
import com.example.demo.mentoring.contact.ContactJPARepository;
import com.example.demo.mentoring.contact.NotConnectedRegisterUser;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import com.example.demo.user.userInterest.UserInterestJPARepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.mentoring.contact;

import com.example.demo.mentoring.MentorPost;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.demo.config.auth.CustomUserDetails;
import com.example.demo.config.utils.ApiResponseBuilder;
import com.example.demo.user.Role;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.demo.mentoring.MentorPostJPARepostiory;
import com.example.demo.mentoring.done.ConnectedUser;
import com.example.demo.mentoring.done.DoneJPARepository;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import com.example.demo.user.userInterest.UserInterestJPARepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.mentoring.done;

import com.example.demo.mentoring.MentorPost;
import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.demo.config.auth.CustomUserDetails;
import com.example.demo.config.utils.ApiResponseBuilder;
import com.example.demo.user.Role;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/example/demo/user/UserRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public class UserRequest {
Expand Down Expand Up @@ -40,8 +42,8 @@ public static class SignUpDTO {

private String introduction;

@NotNull(message = "나이를 입력해주세요.")
private int age;
@NotNull(message = "생년월일을 입력해주세요.")
private LocalDate birthdate;

@NotNull(message = "연락처를 입력해주세요.")
private String phone;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/example/demo/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -39,13 +41,18 @@ public void emailCheck(UserRequest.EmailCheckDTO requestDTO) {

@Transactional
public void signup(UserRequest.SignUpDTO requestDTO) {
// requestDTO 의 Birthdate -> age 로 변경해주는 코드
// 나이 계산하기
LocalDate currentDate = LocalDate.now(); // 현재 날짜 가져오기
int age = Period.between(requestDTO.getBirthdate(), currentDate).getYears(); // 현재 날짜와 생일을 비교해서 나이 계산

User user = User.builder().firstName(requestDTO.getFirstName())
.lastName(requestDTO.getLastName())
.email(requestDTO.getEmail())
.password(passwordEncoder.encode(requestDTO.getPassword()))
.country(requestDTO.getCountry())
.introduction(requestDTO.getIntroduction())
.age(requestDTO.getAge())
.age(age)
.phone(requestDTO.getPhone())
.profileImage(requestDTO.getProfileImage())
.role(requestDTO.getRole())
Expand Down Expand Up @@ -122,7 +129,7 @@ public UserResponse.ProfileDTO updateProfile(int id, UserRequest.ProfileUpdateDT
List<String> categoryList = requestDTO.getCategoryList();
for (String category : categoryList) {
Interest interest = interestJPARepository.findByCategory(category)
.orElseThrow(() -> new Exception400("해당 관심사가 존재하지 않습니다."));
.orElseThrow(() -> new Exception400(null,"해당 관심사가 존재하지 않습니다."));
UserInterest updateUserInterest = UserInterest.builder().user(user).interest(interest).build();
updateUserInterestList.add(updateUserInterest);
}
Expand Down

0 comments on commit bf964f4

Please sign in to comment.