-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
20 changes: 16 additions & 4 deletions
20
src/main/java/ssu/eatssu/domain/admin/controller/AuthenticationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
package ssu.eatssu.domain.admin.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.*; | ||
import ssu.eatssu.domain.admin.dto.LoginRequest; | ||
import ssu.eatssu.domain.admin.service.AuthenticationService; | ||
import ssu.eatssu.domain.user.dto.Tokens; | ||
import ssu.eatssu.global.handler.response.BaseResponse; | ||
|
||
@Slf4j | ||
@Controller | ||
@RequestMapping("/admin") | ||
@RequiredArgsConstructor | ||
public class AuthenticationController { | ||
|
||
private final AuthenticationService authenticationService; | ||
|
||
@GetMapping("/login") | ||
public String loginPage(Model model) { | ||
public String loginPage() { | ||
return "login"; | ||
} | ||
|
||
@ResponseBody | ||
@PostMapping("/login") | ||
public BaseResponse<Tokens> login(@RequestBody LoginRequest request) { | ||
return BaseResponse.success(authenticationService.login(request.password())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ssu.eatssu.domain.admin.dto; | ||
|
||
public record LoginRequest(String password) { | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/ssu/eatssu/domain/admin/service/AuthenticationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ssu.eatssu.domain.admin.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
import ssu.eatssu.domain.admin.controller.AdminAuth; | ||
import ssu.eatssu.domain.auth.security.JwtTokenProvider; | ||
import ssu.eatssu.domain.user.dto.Tokens; | ||
import ssu.eatssu.domain.user.entity.User; | ||
import ssu.eatssu.domain.user.repository.UserRepository; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class AuthenticationService { | ||
private final JwtTokenProvider tokenProvider; | ||
private final PasswordEncoder passwordEncoder; | ||
private final UserRepository userRepository; | ||
private final AdminAuth adminAuth; | ||
|
||
public Tokens login(String password) { | ||
return tokenProvider.generateTokens(adminAuth.loginId(), password); | ||
} | ||
|
||
private void join(String loginId, String password) { | ||
String credentials = createCredentials(password); | ||
|
||
//회원가입 | ||
User user = User.adminJoin(loginId, credentials); | ||
userRepository.save(user); | ||
} | ||
|
||
private String createCredentials(String password) { | ||
return passwordEncoder.encode(password); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters