Skip to content

Commit

Permalink
Merge pull request #261 from Link-MIND/feat/#256
Browse files Browse the repository at this point in the history
Feat/#256
  • Loading branch information
sss4920 authored Feb 4, 2025
2 parents 455e631 + 076988f commit c91ba87
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.app.toaster.admin.common.RedirectResponse;
import com.app.toaster.admin.controller.dto.command.VerifyNewAdminCommand;
import com.app.toaster.admin.controller.dto.request.AdminTotpDto;
//import com.app.toaster.admin.controller.dto.request.LinkDto;
import com.app.toaster.admin.controller.dto.request.SignInDto;
import com.app.toaster.admin.controller.dto.response.AdminResponse;
import com.app.toaster.admin.domain.AdminStatus;
import com.app.toaster.admin.entity.ToasterAdmin;
import com.app.toaster.admin.service.AdminService;
import com.app.toaster.admin.config.QrMfaAuthenticator;
//import com.app.toaster.admin.service.AdminLinkService;
import com.app.toaster.exception.Error;
import com.app.toaster.exception.Success;
import com.app.toaster.exception.model.CustomException;
Expand Down Expand Up @@ -36,18 +39,18 @@ class AdminController {
private final S3Service s3Service;
private final QrMfaAuthenticator qrMfaAuthenticator;
private final AdminService adminService;
// private final AdminLinkService adminLinkService;

@PostMapping("/register")
@ResponseBody
public RedirectResponse<?> registerAdmin(@RequestBody SignInDto signInDto, HttpSession session) {

VerifyNewAdminCommand res = adminService.registerAdmin(signInDto.username(), signInDto.password());

String key = res.key();
Long adminId = res.id();
boolean isNewAdmin = res.isNewAdmin();
AdminStatus adminStatus = res.adminStatus();

if (isNewAdmin){
if (adminStatus.equals(AdminStatus.FIRST_REGISTER)){
key = executeDiscordQrOperation(key);
}

Expand Down Expand Up @@ -93,6 +96,17 @@ public RedirectResponse<AdminResponse> responseIsAdminView(HttpSession session,
return RedirectResponse.success(Success.LOGIN_SUCCESS,"main", result);
}

// @PostMapping("/link")
// public void addRecommendLink(@RequestBody LinkDto linkDto){
// adminLinkService.addNewRecommendLink(linkDto);
// }
//
// @GetMapping("/link")
// public String getAllLink(Model model){
// model.addAttribute("links", adminLinkService.findAllLink());
// return "basic/linkListPage";
// }

private String executeDiscordQrOperation(String key){
MultipartFile qrImage = qrMfaAuthenticator.generateQrCode(key);
String imageKey = s3Service.uploadImage(qrImage, "admin/");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.app.toaster.admin.controller.dto.command;

import com.app.toaster.admin.domain.AdminStatus;

public record VerifyNewAdminCommand(
Long id,
String key,
boolean isNewAdmin
AdminStatus adminStatus
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.app.toaster.admin.domain;

import lombok.Getter;

@Getter
public enum AdminStatus {
ACCEPTED,
NEED_RENEW,
FIRST_REGISTER
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.app.toaster.admin.service;

import com.app.toaster.admin.controller.dto.command.VerifyNewAdminCommand;
import com.app.toaster.admin.domain.AdminStatus;
import com.app.toaster.admin.entity.VerifiedAdmin;
import com.app.toaster.admin.entity.ToasterAdmin;
import com.app.toaster.admin.infrastructure.AdminRepository;
Expand Down Expand Up @@ -60,17 +61,17 @@ public TokenResponseDto issueToken(Long testUserId) {


@Transactional
public VerifyNewAdminCommand registerVerifiedUser(final ToasterAdmin toasterAdmin, boolean isNewAdmin) {
public VerifyNewAdminCommand registerVerifiedUser(final ToasterAdmin toasterAdmin, AdminStatus adminStatus) {

String otpKey = null;
Long id = null;

Optional<VerifiedAdmin> existVerifiedAdmin = verifiedAdminRepository.findByAdmin(toasterAdmin);

if (isNewAdmin) { //์ƒˆ๋กœ์šด ์–ด๋“œ๋ฏผ์˜ ๊ฒฝ์šฐ ๋“ฑ๋ก.
if (AdminStatus.NEED_RENEW.equals(adminStatus) || AdminStatus.FIRST_REGISTER.equals(adminStatus)) { //์ƒˆ๋กœ์šด ์–ด๋“œ๋ฏผ์˜ ๊ฒฝ์šฐ ๋“ฑ๋ก.
log.info("๊ฐฑ์‹ ํ•ด์•ผ๋˜๋Š” ์ผ€์ด์Šค.");

deletePastVerify(existVerifiedAdmin);
deletePastVerify(existVerifiedAdmin); //์ƒˆ๋กœ์šด ์–ด๋“œ๋ฏผ์ด๋ฉด ์—ฌ๊ธฐ์„œ ๊ธฐ์กด verify์‚ญ์ œ ์•ˆํ•จ.

GoogleAuthenticatorKey key = googleAuthenticator.createCredentials();

Expand All @@ -96,7 +97,7 @@ public VerifyNewAdminCommand registerVerifiedUser(final ToasterAdmin toasterAdmi

}

return new VerifyNewAdminCommand(id, otpKey, isNewAdmin);
return new VerifyNewAdminCommand(id, otpKey, adminStatus);
}

@Transactional
Expand All @@ -111,9 +112,9 @@ public VerifyNewAdminCommand registerAdmin(String username, String password) {
if (existAdmin != null) {
log.info("์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์ „ ์ด ๊ฒŒ์ž„์„ ํ•ด๋ดค์–ด์š”.");
if (existAdmin.verifyLastDate()) { //๊ฒ€์ฆ๋œ ๊ฒฝ์šฐ๋ฉด ๊ฑ ์–ด๋“œ๋ฏผ์„ ๋ฆฌํ„ด.
return registerVerifiedUser(existAdmin, false);
return registerVerifiedUser(existAdmin, AdminStatus.ACCEPTED);
}else{
return registerVerifiedUser(existAdmin, true); //์•„๋‹Œ ๊ฒฝ์šฐ๋Š” ๊ฐฑ์‹ ์„ ํ•ด์•ผ๋จ.
return registerVerifiedUser(existAdmin, AdminStatus.NEED_RENEW); //์•„๋‹Œ ๊ฒฝ์šฐ๋Š” ๊ฐฑ์‹ ์„ ํ•ด์•ผ๋จ.
}
}

Expand All @@ -126,7 +127,7 @@ public VerifyNewAdminCommand registerAdmin(String username, String password) {
.password(encPassword)
.build();

return registerVerifiedUser(adminRepository.save(toasterAdmin), true);
return registerVerifiedUser(adminRepository.save(toasterAdmin), AdminStatus.FIRST_REGISTER);
}
}
throw new CustomException(Error.NOT_FOUND_USER_EXCEPTION, "์–ด๋“œ๋ฏผ์ด ์•„๋‹™๋‹ˆ๋‹ค.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void sendNotification(NotificationDto notification) {
}
}
}

@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void sendAdmin(NotificationDto notification) {
if (!Arrays.asList(environment.getActiveProfiles()).contains("local")) { // ์ผ๋‹จ ๋กœ์ปฌ ๋ง‰์•„๋‘๊ฒ ์Šต๋‹ˆ๋‹ค. TODO: ์›นํ›… ์ฃผ์†Œ ๋ฐ”๊พธ๊ธฐ
try {
Expand Down

0 comments on commit c91ba87

Please sign in to comment.