-
Notifications
You must be signed in to change notification settings - Fork 0
Pjs #3
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
base: master
Are you sure you want to change the base?
Pjs #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package org.dailystudio.sbs.api; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.dailystudio.sbs.dto.*; | ||
| import org.dailystudio.sbs.service.AccountService; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/account") //경로 | ||
| @RequiredArgsConstructor | ||
| public class AccountController { | ||
|
|
||
| private final AccountService accountService; | ||
|
|
||
| @PostMapping("/login") | ||
| public ResponseEntity<AccountResDto> loginAccount(@RequestBody AccountLoginReqDto accountLoginReqDto) { | ||
| AccountResDto accountResDto = accountService.login(accountLoginReqDto); | ||
| return ResponseEntity.ok().body(accountResDto); | ||
| } | ||
|
|
||
|
|
||
| @PostMapping("/signUp") | ||
| public ResponseEntity<Boolean> signAccount(@RequestBody AccountSignUpReqDto accountSignUpReqDto) { | ||
|
|
||
| boolean flag = accountService.signUp(accountSignUpReqDto); | ||
| return ResponseEntity.ok(flag); | ||
| } | ||
|
|
||
| @GetMapping("/findByUsingEmail/{email}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. url은 이렇게 서술하는 느낌일일 필요가 없을것 같아 |
||
| public ResponseEntity<AccountResDto> findEmailAccount(@PathVariable("email") String email) { | ||
|
|
||
| AccountResDto accountResDto = accountService.findAccountByUsingEmail(email); | ||
| return ResponseEntity.ok().body(accountResDto); | ||
| } | ||
|
|
||
|
|
||
| @PutMapping("/changName/{modifiedUserName}") | ||
| public ResponseEntity<AccountChangeNameResDto> changeNameAccount(@PathVariable String modifiedUserNAME, @RequestBody AccountChangeNameReqDto accountChangeNameReqDto) { | ||
|
|
||
| AccountChangeNameResDto accountChangeNameResDto = accountService.changeName(modifiedUserNAME, accountChangeNameReqDto); | ||
| //성공적으로 바뀌었으면 바뀐이름 리턴 | ||
| return ResponseEntity.ok().body(accountChangeNameResDto); | ||
| } | ||
|
|
||
| //요청할게 없어서? 안에 안넣었습니다 | ||
| @GetMapping("/returnAllUser") | ||
| public ResponseEntity<AccountFindAllUserDto> returnAllUserAccount() { | ||
|
|
||
| AccountFindAllUserDto accountFindAllUserDto = accountService.findAllUser(); | ||
| return ResponseEntity.ok().body(accountFindAllUserDto); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.dailystudio.sbs.config; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
|
|
||
| @Configuration | ||
| public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
|
|
||
| @Override | ||
| protected void configure(HttpSecurity http) throws Exception { | ||
| http. | ||
| authorizeRequests() | ||
| .antMatchers("/h2/*") | ||
| .permitAll() | ||
| .and() | ||
| .csrf().disable() | ||
| .headers() | ||
| .frameOptions() | ||
| .disable(); | ||
| } | ||
|
|
||
| @Bean | ||
| public BCryptPasswordEncoder bCryptPasswordEncoder() { | ||
| return new BCryptPasswordEncoder(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ public Docket api() { | |
| return new Docket(DocumentationType.SWAGGER_2) | ||
| .select() | ||
| .apis(RequestHandlerSelectors.any()) // 현재 RequestMapping으로 할당된 모든 URL 리스트를 추출 | ||
| .paths(PathSelectors.ant("/api/**")) // 그중 /api/** 인 URL들만 필터링 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ????왜? |
||
| .paths(PathSelectors.ant("/account/**")) // 그중 /api/** 인 URL들만 필터링 | ||
| .build(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.dailystudio.sbs.domain; | ||
|
|
||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import javax.persistence.*; | ||
|
|
||
| @Entity | ||
| @NoArgsConstructor | ||
| @Table(name = "account") | ||
| @Getter | ||
| public class Account { | ||
|
|
||
| @Id //프라이머리 키 | ||
| @GeneratedValue(strategy = GenerationType.AUTO) //전략을 정해주는거 | ||
| @Column(name = "account_id") //데이터베이스에 저장되는이름 | ||
| private Long id; | ||
|
|
||
| @Column(name = "account_email", unique = true, nullable = false) | ||
| private String email; | ||
|
|
||
| @Column(name = "account_name", nullable = false) | ||
| private String name; | ||
|
|
||
| @Column(name = "account_pass", nullable = false) | ||
| private String pass; | ||
|
|
||
| public Account(String email, String name, String pass) { | ||
| this.email = email; | ||
| this.name = name; | ||
| this.pass = pass; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package org.dailystudio.sbs.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class AccountChangeNameReqDto { | ||
|
|
||
| private String email; | ||
| private String name; | ||
| private String pass; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package org.dailystudio.sbs.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class AccountChangeNameResDto { | ||
| private String name; | ||
|
|
||
| public AccountChangeNameResDto(String name) { | ||
| this.name= name; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.dailystudio.sbs.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class AccountFindAccountByUsingEmailReqDto { | ||
| private String email; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.dailystudio.sbs.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Getter | ||
| public class AccountFindAllUserDto { | ||
|
|
||
| private List<AccountResDto> accounts = new ArrayList<>(); | ||
|
|
||
| public AccountFindAllUserDto(List<AccountResDto> accounts) { | ||
|
|
||
| this.accounts= accounts; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.dailystudio.sbs.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class AccountLoginReqDto { | ||
| private String email; | ||
| private String pass; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.dailystudio.sbs.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class AccountResDto { | ||
| //이메일이랑 이름만 ! | ||
| private String email; | ||
| private String name; | ||
|
|
||
|
|
||
| public AccountResDto(String email, String name) { | ||
| this.email = email; | ||
| this.name= name; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.dailystudio.sbs.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import org.dailystudio.sbs.domain.Account; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
|
|
||
| @Getter | ||
| public class AccountSignUpReqDto { | ||
| //가입하기 위해 받는정보에는 id가필요없다. 데이터베이스에 저장할때 자동저장. | ||
| // private Long id; | ||
| private String email; | ||
| private String name; | ||
| private String pass; | ||
|
|
||
| public Account toAccountEntity(PasswordEncoder passwordEncoder) { | ||
| String encodedPassword = passwordEncoder.encode(pass); | ||
| return new Account(email, name, encodedPassword); | ||
| } | ||
| /* | ||
| public Account toEntity(PasswordEncoder passwordEncoder) { | ||
|
|
||
| return Account.builder() | ||
| .email(this.email) | ||
| .pass(passwordEncoder.encode(this.pass)) | ||
| .build(); | ||
| }*/ | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.dailystudio.sbs.repository; | ||
|
|
||
| import org.dailystudio.sbs.domain.Account; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface AccountRepository extends JpaRepository<Account, Long> { | ||
| Account findByEmail(String email); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package org.dailystudio.sbs.service; | ||
|
|
||
|
|
||
| import com.fasterxml.jackson.databind.util.BeanUtil; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.dailystudio.sbs.domain.Account; | ||
| import org.dailystudio.sbs.dto.*; | ||
| import org.dailystudio.sbs.repository.AccountRepository; | ||
| import org.springframework.beans.BeanUtils; | ||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class AccountService { | ||
|
|
||
| private final AccountRepository accountRepository; | ||
| private final BCryptPasswordEncoder bCryptPasswordEncoder; | ||
|
|
||
|
|
||
| @Transactional | ||
| public boolean signUp(AccountSignUpReqDto accountSignUpReqDto) | ||
| { | ||
|
|
||
| String email = accountSignUpReqDto.getEmail(); | ||
| String pass = accountSignUpReqDto.getPass(); | ||
| String name = accountSignUpReqDto.getName(); | ||
|
|
||
| // | ||
| if(accountRepository.findByEmail(email) != null) | ||
| { | ||
| return false; | ||
| } | ||
| Account account = accountSignUpReqDto.toAccountEntity(bCryptPasswordEncoder); | ||
| accountRepository.save(account); | ||
| return true; | ||
|
|
||
| } | ||
|
|
||
| @Transactional | ||
| public AccountResDto login(AccountLoginReqDto accountLoginReqDto) { | ||
|
|
||
| String email = accountLoginReqDto.getEmail(); | ||
|
|
||
| Account account = accountRepository.findByEmail(email); | ||
|
|
||
| //그런 이메일을 가진 객체가 없다면 null반환 | ||
| if (account == null) { | ||
| return null; | ||
| } | ||
| //비밀번호를 복호화한 비밀번호와 같다면 그 객체를 반환 | ||
| if(bCryptPasswordEncoder.matches(accountLoginReqDto.getPass(), account.getPass())) | ||
| { | ||
| AccountResDto accountResDto = new AccountResDto(account.getEmail(), account.getName()); | ||
| return accountResDto; | ||
| } | ||
|
|
||
| //비번이랑 같지않아요~ | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| @Transactional | ||
| public AccountResDto findAccountByUsingEmail(String email) { | ||
|
|
||
| Account account = accountRepository.findByEmail(email); | ||
| if (account == null) { | ||
| return null; | ||
| } | ||
|
|
||
| AccountResDto accountResDto = new AccountResDto(account.getEmail(), account.getName()); | ||
|
|
||
| return accountResDto; | ||
| } | ||
|
|
||
| @Transactional | ||
| public AccountChangeNameResDto changeName(String modifiedUserName, AccountChangeNameReqDto accountChangeNameReqDto) { | ||
|
|
||
|
|
||
| String name = accountChangeNameReqDto.getName(); | ||
| String email = accountChangeNameReqDto.getEmail(); | ||
| String pass = accountChangeNameReqDto.getPass(); | ||
| String input_name = modifiedUserName; | ||
|
|
||
| Account account = accountRepository.findByEmail(email); | ||
|
|
||
| if(account == null) | ||
| { | ||
| return null; | ||
| } | ||
| if (!account.getEmail().equals(email)) { | ||
| return null; | ||
| } | ||
| if (!account.getPass().equals(pass)) { | ||
| return null; | ||
| } | ||
| if (!account.getName().equals(name)) { | ||
| return null; | ||
| } | ||
| AccountChangeNameResDto accountChangeNameResDto = new AccountChangeNameResDto(input_name); | ||
|
|
||
| //삭제하고 다시넣어주나? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 삭제하고 다시 넣으면 안됑 |
||
| accountRepository.deleteById(account.getId()); | ||
| //이쪽까지오면 다 같으니거니까! | ||
| Account modified_account = new Account(email,pass,name); | ||
| accountRepository.save(modified_account); | ||
|
|
||
| //바뀐이름만 리턴 | ||
| return accountChangeNameResDto; | ||
|
|
||
| } | ||
|
|
||
| @Transactional | ||
| public AccountFindAllUserDto findAllUser() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 잘만든것 같아 |
||
|
|
||
| List<Account> accounts = accountRepository.findAll(); | ||
| List<AccountResDto> accountResDtoList = new ArrayList<>(); | ||
|
|
||
| //AccountFindAllUserDto의 매개변수로 들어갈, ResDtoList를 만들자 | ||
| for(Account account_index : accounts) | ||
| { | ||
| AccountResDto accountResDto = new AccountResDto(account_index.getEmail(), account_index.getName()); | ||
| accountResDtoList.add(accountResDto); | ||
| } | ||
|
|
||
| AccountFindAllUserDto accountFindAllUserDto = new AccountFindAllUserDto(accountResDtoList); | ||
|
|
||
|
|
||
| return accountFindAllUserDto; | ||
| } | ||
|
|
||
| } | ||
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.
이걸 api/account하면 되는뎅