Skip to content

Commit

Permalink
feat: jwt 발급, rest login 요청 성공 #21
Browse files Browse the repository at this point in the history
어드민 계정에 예치금
  • Loading branch information
heokyeongju committed Nov 8, 2022
1 parent 4ccc660 commit a99a7c3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ default void before(MemberService memberService, PostService postService, Produc
memberService.addCash(member1, -5_000L, "출금__일반");
memberService.addCash(member1, 1_000_000L, "충전__무통장입금");
memberService.addCash(member2, 2_000_000L, "충전__무통장입금");
memberService.addCash(admin, 2_000_000L, "충전__무통장입금");

withdrawService.apply(member1,"123412341234","카카오뱅크",10000L);
withdrawService.apply(member2,"987098709870","신협",8000L);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.mutbook.week4_mission.app.domain.member.controller;

import com.mutbook.week4_mission.app.base.dto.RsData;
import com.mutbook.week4_mission.app.domain.member.dto.LoginDto;
import com.mutbook.week4_mission.app.domain.member.entity.Member;
import com.mutbook.week4_mission.app.domain.member.service.MemberService;
import com.mutbook.week4_mission.util.Util;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("api/v1/member")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "ApiV1MemberController", description = "로그인 기능과 로그인 된 회원의 정보를 제공 기능을 담당하는 컨트롤러")
public class ApiV1MemberController {
private final MemberService memberService;
private final PasswordEncoder passwordEncoder;

@PostMapping("/login")
public ResponseEntity<RsData> login(@Valid @RequestBody LoginDto loginDto) {
Member member = memberService.findByUsername(loginDto.getUsername()).orElse(null);

if (member == null) {
return Util.spring.responseEntityOf(RsData.of("F-2", "일치하는 회원이 존재하지 않습니다."));
}

if (passwordEncoder.matches(loginDto.getPassword(), member.getPassword()) == false) {
return Util.spring.responseEntityOf(RsData.of("F-3", "비밀번호가 일치하지 않습니다."));
}

log.debug("Util.json.toStr(member.getAccessTokenClaims()) : " + Util.json.toStr(member.getAccessTokenClaims()));

String accessToken = memberService.genAccessToken(member);

return Util.spring.responseEntityOf(
RsData.of(
"S-1",
"로그인 성공, Access Token을 발급합니다.",
Util.mapOf(
"accessToken", accessToken
)
),
Util.spring.httpHeadersOf("Authentication", accessToken)
);
}
}

0 comments on commit a99a7c3

Please sign in to comment.