-
Notifications
You must be signed in to change notification settings - Fork 26
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
[BE4] 김호남 #15
base: main
Are you sure you want to change the base?
[BE4] 김호남 #15
Conversation
if (principal instanceof OAuth2AuthenticationToken) { | ||
// OAuth2 (카카오 로그인) 사용자의 경우 | ||
OAuth2AuthenticationToken authToken = (OAuth2AuthenticationToken) principal; | ||
Map<String, Object> attributes = authToken.getPrincipal().getAttributes(); | ||
String kakaoId = attributes.get("id").toString(); | ||
siteUser = this.userService.getUserByKakaoId(kakaoId); | ||
} else { | ||
// 일반 로그인 사용자의 경우 | ||
siteUser = this.userService.getUser(principal.getName()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
소셜로그인 유저와, 일반 유저의 구분을 다른 칼럼으로 하다보니 어마어마한 코드중복이 발생했네요,
해당하는 코드를 함수화하거나 소셜로그인과 일반유저를 같은 칼럼으로 구분하는 방법을 찾는게 좋겠습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞습니다 .. 중복이 너무 많아서 함수로 처리하는 방안으로 진행중입니다
return comment; | ||
} | ||
|
||
public List<Comment> findCommentsById(Integer id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메서드이름이 애매모호하네요, findCommentsByQuestionId와 같은 형식이 적절해보입니다.
@GetMapping(value = "/detail/{id}/{sort}") | ||
public String detail(Model model, @PathVariable(value = "id") Integer id, @RequestParam(value = "page", defaultValue = "0") int page, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정렬에 대한 값을 pathvariable로 받는 것은 일반적이지 않은 경우네요, 게다가 아래의 컨트롤러와 같은 페이지를 반환하니 기능을 합치는게 좋아보입니다.
String id = attributes.get("id").toString(); | ||
Map<String, Object> kakaoAccount = (Map<String, Object>) attributes.get("kakao_account"); | ||
String email = kakaoAccount.get("email").toString(); | ||
String username = ((Map<String, Object>) kakaoAccount.get("profile")).get("nickname").toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 가입된 유저의 username을 로그인을 시도한 카카오톡 사용자가 nickname으로 쓰고 있을때엔 어떻게 처리하나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 ... 이것도 생각 못해봤네요
위 코드에서는 프로필 정보 조회할 때 username이 필요해서 넣은 부분인데 말씀하신대로면 중복이 생기네요
message.setText("123456"); | ||
mailSender.send(message); | ||
} | ||
return "123456"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
비밀번호가 너무 허술하네요...
public String sendTempPasswordEmail(String email) { | ||
if (userRepository.findByEmail(email).isPresent()) { | ||
SimpleMailMessage message = new SimpleMailMessage(); | ||
message.setFrom("tigerrla24@gmail.com"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이부분 application.properties로 환경변수에서 값을 주입받는 처리하는 것이 좋아보입니다.
message.setTo(email); | ||
message.setSubject("임시 비밀번호"); | ||
message.setText("123456"); | ||
mailSender.send(message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메일을 동기적으로 보내면 시간이 오래 걸리니 비동기 처리를 하는 것이 좋아보입니다.
public String resetPassword(@RequestParam(value = "email") String email) { | ||
String newPassword = this.userService.sendTempPasswordEmail(email); | ||
SiteUser siteUser = this.userService.getUserFromEmail(email); | ||
|
||
this.userService.modifyPassword(siteUser, siteUser.getUsername(), siteUser.getEmail(), newPassword); | ||
return "redirect:/user/login"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
소셜로그인 사용자도, 이메일을 입력하면 변경된 패스워드를 받게 될텐데 의도한 사항인가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아뇨 의도한 사항은 아니고 그런 상황을 생각을 못햇네요 ;
일반 회원에게만 적용될 수 있도록 수정해야겠습니다
spring.security.oauth2.client.registration.kakao.clientId=aa5aaf6346a4d796ac90b1a920a41168 | ||
spring.security.oauth2.client.registration.kakao.clientSecret=SndVIm1vWTcSRgkGMapMZSCUA9ilRi81 | ||
spring.security.oauth2.client.registration.kakao.redirectUri=http://localhost:8080/login/oauth2/code/kakao |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
민감한 정보들은 .env파일로 관리하여 github 퍼블릭 리포지터리에 올라오지 않도록 해주시면 감사하겠습니다.
kakao developers에서 새로 키를 발급받으세요
spring.mail.username=tigerrla24@gmail.com | ||
spring.mail.password=bjls igpz fben vnbp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
민감한 정보들은 .env파일로 관리하여 github 퍼블릭 리포지터리에 올라오지 않도록 해주시면 감사하겠습니다.
gmail에서 새로 키를 발급받으세요
3-14 9가지 기능 구현 완료하였습니다
어떤 훈수라도 환영입니다