728x90 반응형 Spring17 [Spring JPA] 1-12. 회원 가입 : 로그인 로그아웃 package com.studyolle.config; import org.springframework.boot.autoconfigure.security.servlet.PathRequest; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.. 2021. 5. 4. [Spring JPA] 1-11. 회원 가입 : 현재 인증된 사용자 정보 참조 package com.studyolle.account.controller; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.security.core.annotation.AuthenticationPrincipal; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) @AuthenticationPrincipal(expression = "#this == 'an.. 2021. 5. 4. [Spring JPA] 1-10. 회원 가입 : 인증 메일 확인 테스트 @DisplayName("인증 메일 확인 - 입력값 오류") @Test void checkEmailToken_with_wrong_input() throws Exception { mockMvc.perform(get("/check-email-token") .param("token", "sdfjslwfwef") .param("email", "email@email.com")) .andExpect(status().isOk()) .andExpect(model().attributeExists("error")) .andExpect(view().name("account/checked-email")) .andExpect(unauthenticated()); } @DisplayName("인증 메일 확인 - 입력값 정상") @.. 2021. 5. 1. [Spring JPA] 1-9. 회원 가입 : 인증 메일 확인 AccountController에서 인증메일확인 컨트롤러를 작성해 줍니다. @GetMapping("/check-email-token") public String checkEmailToken(String token, String email, Model model) { Account account = accountRepository.findByEmail(email); String view= "account/checked-email"; if(account == null) { model.addAttribute("error","wrong.email"); return view; } if(!account.getEmailCheckToken().equals(token)) { model.addAttribute("error.. 2021. 5. 1. [Spring JPA] 1-8. 회원 가입 : 패스워드 인코더 해싱 알고리즘(bcrypt)와 솔트(salt)를 활용해서 비밀번호를 인코더해줘야 한다. 비밀번호를 암호화 하기 위해서 AccoutService에서 입력된 비밀번호를 해싱 알고리즘을 통해서 암호화 처리를 해주어야 한다. public Account saveNewAccount(SignUpForm signUpForm) { Account account = Account.builder() .email(signUpForm.getEmail()) .nickname(signUpForm.getNickname()) .password(passwordEncoder.encode(signUpForm.getPassword())) .studyCreatedByWeb(true).studyEnrollmentResultByWeb(true).s.. 2021. 4. 30. [Spring JPA] 1-7. 회원 가입 리펙토링 및 테스트 먼저 지금까지 작성한 코드들을 테스트 하기위해 AccoutControllerTest를 수정해 줍니다. @DisplayName("회원 가입 처리 - 입력값 오류") @Test void signUpSubmit_with_wrong_input() throws Exception { mockMvc.perform(post("/sign-up").param("nickname", "keesun").param("email", "keesun@email.com") .param("password", "12345678").with(csrf())) .andExpect(status().isOk()).andExpect(view().name("account/sign-up")); assertTrue(accountRepository.exis.. 2021. 4. 30. 이전 1 2 3 다음 728x90 반응형