계정 발급, 수정 임시비밀번호 로직 변경
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
# docker build -t hd1-was:1.0.8 .
|
# docker build -t hd1-was:1.1.0 .
|
||||||
# docker tag hd1-was:1.0.8 192.168.219.191:19101/hd1-was:1.0.8
|
# docker tag hd1-was:1.1.0 192.168.219.191:19101/hd1-was:1.1.0
|
||||||
# docker push 192.168.219.191:19101/hd1-was:1.0.8
|
# docker push 192.168.219.191:19101/hd1-was:1.1.0
|
||||||
# or
|
# or
|
||||||
# .\_docker_push.bat 1.0.8
|
# .\_docker_push.bat 1.1.0
|
||||||
|
|
||||||
FROM eclipse-temurin:21-jdk
|
FROM eclipse-temurin:21-jdk
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
# docker pull 49.165.181.28:19101/hd1-was:1.0.8
|
# docker pull 49.165.181.28:19101/hd1-was:1.1.0
|
||||||
docker stop hd1-was
|
# docker stop hd1-was
|
||||||
docker rm hd1-was
|
# docker rm hd1-was
|
||||||
docker-compose up -d
|
# docker-compose up -d
|
||||||
# or
|
# or
|
||||||
# _docker_pull_restart.sh 1.0.8
|
# _docker_pull_restart.sh 1.1.0
|
||||||
|
|
||||||
services:
|
services:
|
||||||
hd1:
|
hd1:
|
||||||
image: 49.165.181.28:19101/hd1-was:1.0.8
|
image: 49.165.181.28:19101/hd1-was:1.1.0
|
||||||
container_name: hd1-was
|
container_name: hd1-was
|
||||||
ports:
|
ports:
|
||||||
- "28080:18080"
|
- "28080:18080"
|
||||||
|
|||||||
+2
-1
@@ -104,7 +104,8 @@ class AccountController {
|
|||||||
Boolean perm_uid1 = _AG.toBoolean(body.get("perm_uid1"));
|
Boolean perm_uid1 = _AG.toBoolean(body.get("perm_uid1"));
|
||||||
Boolean perm_cancel = _AG.toBoolean(body.get("perm_cancel"));
|
Boolean perm_cancel = _AG.toBoolean(body.get("perm_cancel"));
|
||||||
|
|
||||||
if (user_id == null || user_id.isEmpty()) {
|
// A new account is issued with the business number as its ID, so only a modification names one
|
||||||
|
if (isModify && (user_id == null || user_id.isEmpty())) {
|
||||||
result.setErrCode(ErrorCode.INVALID_PARAMETER);
|
result.setErrCode(ErrorCode.INVALID_PARAMETER);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ public interface AccountMapper {
|
|||||||
int updateInitAccount(Long gid, String user_id, String user_pw);
|
int updateInitAccount(Long gid, String user_id, String user_pw);
|
||||||
|
|
||||||
int updateResetPassword(Long gid, String user_pw);
|
int updateResetPassword(Long gid, String user_pw);
|
||||||
|
|
||||||
|
int invalidatePendingIssuedAccount(String user_id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ public interface BizGroupMapper {
|
|||||||
|
|
||||||
Map<String, Object> selectExistBizGroup(Long biz_group_id, String biz_reg_num);
|
Map<String, Object> selectExistBizGroup(Long biz_group_id, String biz_reg_num);
|
||||||
|
|
||||||
|
String selectBizRegNumById(Long biz_group_id);
|
||||||
|
|
||||||
Map<String, Object> selectBizGroupByDeviceId(Long device_id);
|
Map<String, Object> selectBizGroupByDeviceId(Long device_id);
|
||||||
Map<String, Object> selectBizGroupByTerminalId(Long terminal_id);
|
Map<String, Object> selectBizGroupByTerminalId(Long terminal_id);
|
||||||
|
|
||||||
|
|||||||
+74
-10
@@ -23,8 +23,11 @@ import org.springframework.security.core.Authentication;
|
|||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
|
|
||||||
import com.handong.smartservice.mapper.AccountMapper;
|
import com.handong.smartservice.mapper.AccountMapper;
|
||||||
|
import com.handong.smartservice.mapper.BizGroupMapper;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -34,14 +37,16 @@ public class AccountService {
|
|||||||
private final AccountMapper accountMapper;
|
private final AccountMapper accountMapper;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
private final SMSSender smsSender;
|
private final SMSSender smsSender;
|
||||||
|
private final BizGroupMapper bizGroupMapper;
|
||||||
|
|
||||||
@Value("${sms.callback}") String smsCallback;
|
@Value("${sms.callback}") String smsCallback;
|
||||||
@Value("${account.site-url}") String siteUrl;
|
@Value("${account.site-url}") String siteUrl;
|
||||||
|
|
||||||
public AccountService(AccountMapper accountMapper, PasswordEncoder passwordEncoder, SMSSender smsSender) {
|
public AccountService(AccountMapper accountMapper, PasswordEncoder passwordEncoder, SMSSender smsSender, BizGroupMapper bizGroupMapper) {
|
||||||
this.accountMapper = accountMapper;
|
this.accountMapper = accountMapper;
|
||||||
this.passwordEncoder = passwordEncoder;
|
this.passwordEncoder = passwordEncoder;
|
||||||
this.smsSender = smsSender;
|
this.smsSender = smsSender;
|
||||||
|
this.bizGroupMapper = bizGroupMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CtResponse getAccount(Long gid, String user_id) {
|
public CtResponse getAccount(Long gid, String user_id) {
|
||||||
@@ -78,6 +83,7 @@ public class AccountService {
|
|||||||
return mapResult;
|
return mapResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public CtResponse addOrModifyAccount(boolean isModify, Long gid, String user_id, String user_pw, String email, String name, String phone,Long state,
|
public CtResponse addOrModifyAccount(boolean isModify, Long gid, String user_id, String user_pw, String email, String name, String phone,Long state,
|
||||||
Long biz_group_id, Long new_biz_group_id, Boolean perm_group, Boolean perm_uid1, Boolean perm_cancel) {
|
Long biz_group_id, Long new_biz_group_id, Boolean perm_group, Boolean perm_uid1, Boolean perm_cancel) {
|
||||||
CtResponse result = new CtResponse();
|
CtResponse result = new CtResponse();
|
||||||
@@ -85,7 +91,8 @@ public class AccountService {
|
|||||||
//UserInfo userInfo = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
//UserInfo userInfo = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
UserInfo userInfo = UserInfo.getCurr();
|
UserInfo userInfo = UserInfo.getCurr();
|
||||||
|
|
||||||
String enc_pw = passwordEncoder.encode(user_pw);
|
// A modification without a password (someone else's account) keeps the stored one
|
||||||
|
String enc_pw = user_pw == null || user_pw.isEmpty() ? null : passwordEncoder.encode(user_pw);
|
||||||
|
|
||||||
if (new_biz_group_id != 0 && new_biz_group_id != biz_group_id)
|
if (new_biz_group_id != 0 && new_biz_group_id != biz_group_id)
|
||||||
biz_group_id = new_biz_group_id;
|
biz_group_id = new_biz_group_id;
|
||||||
@@ -107,19 +114,33 @@ public class AccountService {
|
|||||||
DbLogger.insert(2L, "계정정보 수정", userInfo.getGid());
|
DbLogger.insert(2L, "계정정보 수정", userInfo.getGid());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// A new account is issued like the one of a new business group: the ID is the group's business number,
|
||||||
|
// a temporary password is texted to the mobile number, and the user picks their own ID and password at the first sign in
|
||||||
|
String mobile = phone == null ? "" : phone.replaceAll("[^0-9]", "");
|
||||||
|
user_id = biz_group_id == 0 ? null : bizGroupMapper.selectBizRegNumById(biz_group_id);
|
||||||
if (user_id == null || user_id.isEmpty()) {
|
if (user_id == null || user_id.isEmpty()) {
|
||||||
result.setErrCode(ErrorCode.INVALID_PARAMETER);
|
result.setErrCode(ErrorCode.INVALID_BIZ_REG_NUM);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (mobile.matches("^01[016789][0-9]{7,8}$") == false) {
|
||||||
|
result.setErrCode(ErrorCode.INVALID_MOBILE);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
invalidatePendingIssuedAccount(user_id);
|
||||||
|
if (accountMapper.countActiveUserId(user_id, 0L) > 0) {
|
||||||
|
result.setErrCode(ErrorCode.ACCOUNT_ALREADY_EXIST);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String tempPw = TempPassword.create();
|
||||||
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = new HashMap<>();
|
||||||
params.put("user_id", user_id);
|
params.put("user_id", user_id);
|
||||||
//params.put("user_pw", user_pw);
|
params.put("user_pw", passwordEncoder.encode(tempPw));
|
||||||
params.put("user_pw", enc_pw);
|
|
||||||
params.put("name", name);
|
params.put("name", name);
|
||||||
params.put("phone", phone);
|
params.put("phone", mobile);
|
||||||
params.put("email", email);
|
params.put("email", email);
|
||||||
params.put("state", state);
|
params.put("state", BizGroupService.ACCOUNT_STATE_INIT);
|
||||||
params.put("biz_group_id", biz_group_id);
|
params.put("biz_group_id", biz_group_id);
|
||||||
|
|
||||||
if (biz_group_id == 667) //TempCode
|
if (biz_group_id == 667) //TempCode
|
||||||
@@ -134,19 +155,58 @@ public class AccountService {
|
|||||||
|
|
||||||
if (accountMapper.insertAccount(params) == 0) {
|
if (accountMapper.insertAccount(params) == 0) {
|
||||||
result.setErrCode(ErrorCode.INVALID_PARAMETER);
|
result.setErrCode(ErrorCode.INVALID_PARAMETER);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
DbLogger.insert(2L, "신규 계정 추가, id: " + user_id, userInfo.getGid());
|
// A failed message rolls the account back, so the registration can simply be retried
|
||||||
|
String smsCode = sendIssuedAccountMessage(user_id, tempPw, mobile);
|
||||||
|
if (smsCode != null) {
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
result.setErrCode(ErrorCode.SMS_SEND_FAILED);
|
||||||
|
result.put("sms_code", smsCode);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
DbLogger.insert(2L, "신규 계정 추가(계정발급), id: " + user_id, userInfo.getGid());
|
||||||
//result.put("result", Map.of("gid", params.get("gid")));
|
//result.put("result", Map.of("gid", params.get("gid")));
|
||||||
Map<String, Object> ret = new HashMap<String, Object>();
|
Map<String, Object> ret = new HashMap<String, Object>();
|
||||||
ret.put("gid", params.get("gid"));
|
ret.put("gid", params.get("gid"));
|
||||||
result.put("result", ret);
|
result.put("result", ret);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terminates the earlier issued accounts of a business number that still wait for their first sign in,
|
||||||
|
* so the account issued next is the only one whose temporary password works. Runs inside the caller's
|
||||||
|
* transaction: a failed issue (e.g. the text message) restores them.
|
||||||
|
*/
|
||||||
|
public void invalidatePendingIssuedAccount(String user_id) {
|
||||||
|
int changed = accountMapper.invalidatePendingIssuedAccount(user_id);
|
||||||
|
if (changed > 0)
|
||||||
|
logger.info("invalidatePendingIssuedAccount: user_id={}, invalidated={}", user_id, changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texts the sign in information of a newly issued account.
|
||||||
|
*
|
||||||
|
* @return null when the message was sent, otherwise the gateway result code
|
||||||
|
*/
|
||||||
|
public String sendIssuedAccountMessage(String user_id, String tempPw, String mobile) {
|
||||||
|
String msg = "[스마트서비스] 계정이 발급되었습니다.\n"
|
||||||
|
+ "사이트: " + siteUrl + "\n"
|
||||||
|
+ "ID: " + user_id + "\n"
|
||||||
|
+ "임시비밀번호: " + tempPw + "\n"
|
||||||
|
+ "로그인 후 아이디와 비밀번호를 변경해 주세요.";
|
||||||
|
|
||||||
|
SMSSender.Result sendResult = smsSender.send(smsCallback, mobile, msg);
|
||||||
|
if (sendResult.isSuccess() == false)
|
||||||
|
logger.warn("sendIssuedAccountMessage: sms failed, user_id={}, mobile={}, result={}", user_id, mobile, sendResult);
|
||||||
|
|
||||||
|
return sendResult.isSuccess() ? null : sendResult.code;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the temporary ID and password of an issued account (state 6) with the user's own.
|
* Replaces the temporary ID and password of an issued account (state 6) with the user's own.
|
||||||
* The temporary credentials are checked again here, because the caller has no token yet.
|
* The temporary credentials are checked again here, because the caller has no token yet.
|
||||||
@@ -203,6 +263,7 @@ public class AccountService {
|
|||||||
|
|
||||||
String mobile = phone == null ? "" : phone.replaceAll("[^0-9]", "");
|
String mobile = phone == null ? "" : phone.replaceAll("[^0-9]", "");
|
||||||
if (gid == 0 || mobile.matches("^01[016789][0-9]{7,8}$") == false) {
|
if (gid == 0 || mobile.matches("^01[016789][0-9]{7,8}$") == false) {
|
||||||
|
logger.info("resetPassword: bad parameter, gid={}, mobile={}", gid, mobile);
|
||||||
result.setErrCode(ErrorCode.INVALID_MOBILE);
|
result.setErrCode(ErrorCode.INVALID_MOBILE);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -210,12 +271,14 @@ public class AccountService {
|
|||||||
CtResponse resAccount = getAccount(gid, null);
|
CtResponse resAccount = getAccount(gid, null);
|
||||||
Map<String, Object> mapAccount = (Map<String, Object>)resAccount.get("result");
|
Map<String, Object> mapAccount = (Map<String, Object>)resAccount.get("result");
|
||||||
if (mapAccount == null) {
|
if (mapAccount == null) {
|
||||||
|
logger.info("resetPassword: account not found, gid={}", gid);
|
||||||
result.setErrCode(ErrorCode.INVALID_USER);
|
result.setErrCode(ErrorCode.INVALID_USER);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String newPw = TempPassword.create();
|
String newPw = TempPassword.create();
|
||||||
if (accountMapper.updateResetPassword(gid, passwordEncoder.encode(newPw)) == 0) {
|
if (accountMapper.updateResetPassword(gid, passwordEncoder.encode(newPw)) == 0) {
|
||||||
|
logger.info("resetPassword: nothing updated, gid={}", gid);
|
||||||
result.setErrCode(ErrorCode.QUERY_ERROR);
|
result.setErrCode(ErrorCode.QUERY_ERROR);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -228,6 +291,7 @@ public class AccountService {
|
|||||||
|
|
||||||
SMSSender.Result sendResult = smsSender.send(smsCallback, mobile, msg);
|
SMSSender.Result sendResult = smsSender.send(smsCallback, mobile, msg);
|
||||||
if (sendResult.isSuccess() == false) {
|
if (sendResult.isSuccess() == false) {
|
||||||
|
logger.warn("resetPassword: sms failed, gid={}, mobile={}, result={}", gid, mobile, sendResult);
|
||||||
result.setErrCode(ErrorCode.SMS_SEND_FAILED);
|
result.setErrCode(ErrorCode.SMS_SEND_FAILED);
|
||||||
result.put("sms_code", sendResult.code);
|
result.put("sms_code", sendResult.code);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+3
-14
@@ -13,7 +13,6 @@ import org.apache.ibatis.jdbc.SQL;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -25,7 +24,6 @@ import com.handong.smartservice.component.DbLogger;
|
|||||||
import com.handong.smartservice.component.ErrorCode;
|
import com.handong.smartservice.component.ErrorCode;
|
||||||
import com.handong.smartservice.component.Permission;
|
import com.handong.smartservice.component.Permission;
|
||||||
import com.handong.smartservice.component.RcTreeBizGroup;
|
import com.handong.smartservice.component.RcTreeBizGroup;
|
||||||
import com.handong.smartservice.component.SMSSender;
|
|
||||||
import com.handong.smartservice.component.TempPassword;
|
import com.handong.smartservice.component.TempPassword;
|
||||||
import com.handong.smartservice.component.UserInfo;
|
import com.handong.smartservice.component.UserInfo;
|
||||||
import com.handong.smartservice.mapper.AccountMapper;
|
import com.handong.smartservice.mapper.AccountMapper;
|
||||||
@@ -43,10 +41,7 @@ public class BizGroupService {
|
|||||||
@Autowired BizGroupMapper bizGroupMapper;
|
@Autowired BizGroupMapper bizGroupMapper;
|
||||||
@Autowired AccountMapper accountMapper;
|
@Autowired AccountMapper accountMapper;
|
||||||
@Autowired PasswordEncoder passwordEncoder;
|
@Autowired PasswordEncoder passwordEncoder;
|
||||||
@Autowired SMSSender smsSender;
|
@Autowired AccountService accountService;
|
||||||
|
|
||||||
@Value("${sms.callback}") String smsCallback;
|
|
||||||
@Value("${account.site-url}") String siteUrl;
|
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Object> getBizGroupList(Long offset, Long limit, String date_start, String date_end,
|
public Map<String, Object> getBizGroupList(Long offset, Long limit, String date_start, String date_end,
|
||||||
@@ -98,6 +93,7 @@ public class BizGroupService {
|
|||||||
result.setErrCode(ErrorCode.INVALID_MOBILE);
|
result.setErrCode(ErrorCode.INVALID_MOBILE);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
accountService.invalidatePendingIssuedAccount(biz_reg_num);
|
||||||
if (accountMapper.countActiveUserId(biz_reg_num, 0L) > 0) {
|
if (accountMapper.countActiveUserId(biz_reg_num, 0L) > 0) {
|
||||||
result.setErrCode(ErrorCode.ACCOUNT_ALREADY_EXIST);
|
result.setErrCode(ErrorCode.ACCOUNT_ALREADY_EXIST);
|
||||||
return result;
|
return result;
|
||||||
@@ -179,14 +175,7 @@ public class BizGroupService {
|
|||||||
params.put("permission", permission.get());
|
params.put("permission", permission.get());
|
||||||
accountMapper.insertAccount(params);
|
accountMapper.insertAccount(params);
|
||||||
|
|
||||||
String msg = "[스마트서비스] 계정이 발급되었습니다.\n"
|
return accountService.sendIssuedAccountMessage(biz_reg_num, tempPw, mobile);
|
||||||
+ "사이트: " + siteUrl + "\n"
|
|
||||||
+ "ID: " + biz_reg_num + "\n"
|
|
||||||
+ "임시비밀번호: " + tempPw + "\n"
|
|
||||||
+ "로그인 후 아이디와 비밀번호를 변경해 주세요.";
|
|
||||||
|
|
||||||
SMSSender.Result sendResult = smsSender.send(smsCallback, mobile, msg);
|
|
||||||
return sendResult.isSuccess() ? null : sendResult.code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,14 @@
|
|||||||
WHERE gid = #{gid} AND state != 2
|
WHERE gid = #{gid} AND state != 2
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- An issued account that never signed in to pick its own ID (state 6) is terminated (state 2)
|
||||||
|
when a newer account is issued with the same business number: only the latest temporary password works -->
|
||||||
|
<update id="invalidatePendingIssuedAccount">
|
||||||
|
UPDATE account
|
||||||
|
SET state = 2
|
||||||
|
WHERE user_id = #{user_id} AND state = 6
|
||||||
|
</update>
|
||||||
|
|
||||||
<update id="changeState">
|
<update id="changeState">
|
||||||
<if test='ids != null and ids.size > 0'>
|
<if test='ids != null and ids.size > 0'>
|
||||||
UPDATE account
|
UPDATE account
|
||||||
|
|||||||
@@ -41,6 +41,13 @@
|
|||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- The business number is the ID an account is issued with -->
|
||||||
|
<select id="selectBizRegNumById" resultType="string">
|
||||||
|
SELECT biz_reg_num
|
||||||
|
FROM biz_group
|
||||||
|
WHERE state != 2 AND biz_group_id = #{biz_group_id}
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectExistBizGroup" resultType="map">
|
<select id="selectExistBizGroup" resultType="map">
|
||||||
SELECT biz_group_id
|
SELECT biz_group_id
|
||||||
FROM biz_group
|
FROM biz_group
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import React, { useState, useRef, useEffect } from "react";
|
import React, { useState, useRef, useEffect } from "react";
|
||||||
import CtModal from "@/components/CtModal";
|
import CtModal from "@/components/CtModal";
|
||||||
import ResetPasswordModal from "@/components/ResetPasswordModal";
|
|
||||||
import Button from "@/components/ui/button/Button2";
|
import Button from "@/components/ui/button/Button2";
|
||||||
import { useModal } from "@/hooks/useModal";
|
|
||||||
import Label from '@/components/form/Label2';
|
import Label from '@/components/form/Label2';
|
||||||
import Input from '@/components/form/input/InputField2';
|
import Input from '@/components/form/input/InputField2';
|
||||||
import Select from '@/components/form/Select2';
|
import Select from '@/components/form/Select2';
|
||||||
import { useMultiState } from "@/hooks/useMultiState";
|
import { useMultiState } from "@/hooks/useMultiState";
|
||||||
import api, { useAuthStore } from '@/lib/_AG';
|
import api, { useAuthStore } from '@/lib/_AG';
|
||||||
|
import { resetAccountPassword } from '@/lib/resetAccountPassword';
|
||||||
import Checkbox from "@/components/form/input/Checkbox";
|
import Checkbox from "@/components/form/input/Checkbox";
|
||||||
|
|
||||||
|
|
||||||
@@ -45,23 +44,50 @@ export default function AddModifyAccountModal({ multiState, onOk, isOpen, closeM
|
|||||||
|
|
||||||
const [ user_pw_confirm, setUserPwConfirm ] = useState<string>("");
|
const [ user_pw_confirm, setUserPwConfirm ] = useState<string>("");
|
||||||
|
|
||||||
const { isOpen: isOpenReset, openModal: openResetModal, closeModal: closeResetModal } = useModal();
|
// Only the signed-in user changes their own password here; anyone else's password is reset by text message
|
||||||
|
const isSelf = multiState.values.isModify && tokenPayload?.user_id === multiState.values.user_id;
|
||||||
|
// A new account gets a temporary password by text message, like an account issued with a business group
|
||||||
|
const showPassword = isSelf;
|
||||||
|
|
||||||
|
// Modifying yourself keeps the password unless the change box is checked
|
||||||
|
const [ isChangePw, setIsChangePw ] = useState<boolean>(false);
|
||||||
|
const needPassword = isSelf && isChangePw;
|
||||||
|
|
||||||
|
// Every opening starts with the box cleared and nothing typed
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
setIsChangePw(false);
|
||||||
|
setUserPwConfirm("");
|
||||||
|
}
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
|
const handleChangeIsChangePw = (checked: boolean) => {
|
||||||
|
setIsChangePw(checked);
|
||||||
|
if (!checked) {
|
||||||
|
multiState.set("user_pw", "");
|
||||||
|
setUserPwConfirm("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleClickAddOrModify = () => {
|
const handleClickAddOrModify = () => {
|
||||||
if (multiState.values.user_id == "") {
|
if (multiState.values.isModify && multiState.values.user_id == "") {
|
||||||
alert("계정 아이디를 입력하셔야 합니다.");
|
alert("계정 아이디를 입력하셔야 합니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (multiState.values.user_pw == "") {
|
else if (!multiState.values.isModify && !multiState.values.biz_reg_num) {
|
||||||
|
alert("사업자번호가 등록된 사업자만 계정을 발급할 수 있습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (needPassword && multiState.values.user_pw == "") {
|
||||||
alert("계정 비밀번호를 입력하셔야 합니다.");
|
alert("계정 비밀번호를 입력하셔야 합니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (user_pw_confirm == "") {
|
else if (needPassword && user_pw_confirm == "") {
|
||||||
alert("비밀번호 확인을 입력하셔야 합니다.");
|
alert("비밀번호 확인을 입력하셔야 합니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (multiState.values.user_pw !== user_pw_confirm) {
|
else if (needPassword && multiState.values.user_pw !== user_pw_confirm) {
|
||||||
alert("비밀번호 확인이 일치하지 않습니다.");
|
alert("비밀번호 확인이 일치하지 않습니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -73,6 +99,10 @@ export default function AddModifyAccountModal({ multiState, onOk, isOpen, closeM
|
|||||||
alert("휴대폰 번호를 입력하셔야 합니다.");
|
alert("휴대폰 번호를 입력하셔야 합니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (!multiState.values.isModify && !/^01[016789][0-9]{7,8}$/.test(multiState.values.phone.replace(/[^0-9]/g, ""))) {
|
||||||
|
alert("임시 비밀번호를 문자로 보내려면 올바른 휴대폰 번호를 입력해야 합니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (multiState.values.isModify) {
|
if (multiState.values.isModify) {
|
||||||
api.post('/api/modify-account.do', multiState.values).then((resp) => {
|
api.post('/api/modify-account.do', multiState.values).then((resp) => {
|
||||||
@@ -93,9 +123,21 @@ export default function AddModifyAccountModal({ multiState, onOk, isOpen, closeM
|
|||||||
console.log(resp);
|
console.log(resp);
|
||||||
|
|
||||||
if (resp.data.errCode == 0) {
|
if (resp.data.errCode == 0) {
|
||||||
alert("추가되었습니다.");
|
alert("추가되었습니다. 발급된 계정 정보를 휴대폰으로 보냈습니다.");
|
||||||
onOk();
|
onOk();
|
||||||
}
|
}
|
||||||
|
else if (resp.data.errCode == -19) {
|
||||||
|
alert("임시 비밀번호를 문자로 보내려면 올바른 휴대폰 번호를 입력해야 합니다.");
|
||||||
|
}
|
||||||
|
else if (resp.data.errCode == -20) {
|
||||||
|
alert("문자 발송에 실패해 계정 등록이 취소되었습니다. 잠시 후 다시 시도하세요.");
|
||||||
|
}
|
||||||
|
else if (resp.data.errCode == -17) {
|
||||||
|
alert("사업자번호가 등록된 사업자만 계정을 발급할 수 있습니다.");
|
||||||
|
}
|
||||||
|
else if (resp.data.errCode == -21) {
|
||||||
|
alert("이 사업자번호를 아이디로 사용 중인 계정이 이미 있습니다.");
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
alert("일시적으로 사용할 수 없습니다 : " + resp.data.errCode);
|
alert("일시적으로 사용할 수 없습니다 : " + resp.data.errCode);
|
||||||
}
|
}
|
||||||
@@ -123,16 +165,28 @@ export default function AddModifyAccountModal({ multiState, onOk, isOpen, closeM
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label redPoint>아이디</Label>
|
<Label redPoint>아이디</Label>
|
||||||
<Input type="text" value={multiState.values.user_id} onChange={(e) => multiState.set("user_id", e.target.value)} disabled={multiState.values.isModify ? true : false} />
|
{/* A new account signs in with the business number and picks its own ID at the first sign in */}
|
||||||
|
{ multiState.values.isModify ?
|
||||||
|
<Input type="text" value={multiState.values.user_id} disabled />
|
||||||
|
:
|
||||||
|
<Input type="text" value={"사업자번호로 발급" + (multiState.values.biz_reg_num ? " (" + multiState.values.biz_reg_num + ")" : "")} disabled />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
{ showPassword && <>
|
||||||
|
{ isSelf &&
|
||||||
|
<div>
|
||||||
|
<Checkbox checked={isChangePw} onChange={handleChangeIsChangePw} label="비밀번호 변경" />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div>
|
||||||
|
<Label redPoint={needPassword}>비밀번호</Label>
|
||||||
|
<Input type="password" value={multiState.values.user_pw} onChange={(e) => multiState.set("user_pw", e.target.value)} disabled={!needPassword} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label redPoint>비밀번호</Label>
|
<Label redPoint={needPassword}>비밀번호 확인</Label>
|
||||||
<Input type="password" defaultValue="" onChange={(e) => multiState.set("user_pw", e.target.value)} />
|
<Input type="password" value={user_pw_confirm} onChange={(e) => setUserPwConfirm(e.target.value)} disabled={!needPassword} />
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label redPoint>비밀번호 확인</Label>
|
|
||||||
<Input type="password" value={user_pw_confirm} onChange={(e) => setUserPwConfirm(e.target.value)} />
|
|
||||||
</div>
|
</div>
|
||||||
|
</>}
|
||||||
<div>
|
<div>
|
||||||
<Label redPoint>이름</Label>
|
<Label redPoint>이름</Label>
|
||||||
<Input type="text" value={multiState.values.name} onChange={(e) => multiState.set("name", e.target.value)} />
|
<Input type="text" value={multiState.values.name} onChange={(e) => multiState.set("name", e.target.value)} />
|
||||||
@@ -156,6 +210,8 @@ export default function AddModifyAccountModal({ multiState, onOk, isOpen, closeM
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>상태</Label>
|
<Label>상태</Label>
|
||||||
|
{/* A new account always starts initialized: the server sets it */}
|
||||||
|
{ multiState.values.isModify ?
|
||||||
<Select
|
<Select
|
||||||
placeholder="선택하세요"
|
placeholder="선택하세요"
|
||||||
options={[
|
options={[
|
||||||
@@ -168,15 +224,16 @@ export default function AddModifyAccountModal({ multiState, onOk, isOpen, closeM
|
|||||||
]}
|
]}
|
||||||
defaultValue={multiState.values.state} onChange={(e) => multiState.set("state", e.target.value)}
|
defaultValue={multiState.values.state} onChange={(e) => multiState.set("state", e.target.value)}
|
||||||
className="dark:bg-dark-900" />
|
className="dark:bg-dark-900" />
|
||||||
|
:
|
||||||
|
<Input type="text" value="초기화 (첫 로그인 시 아이디·비밀번호 변경)" disabled />
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
{ multiState.values.isModify &&
|
{ multiState.values.isModify && !isSelf &&
|
||||||
<div>
|
<div>
|
||||||
<Label>비밀번호 초기화</Label>
|
<Button size="sm" variant="outline" onClick={() => resetAccountPassword(multiState.values.gid, multiState.values.phone)}>비밀번호 초기화</Button>
|
||||||
<Button size="sm" variant="outline" onClick={openResetModal}>비밀번호 초기화</Button>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</CtModal>
|
</CtModal>
|
||||||
<ResetPasswordModal gid={multiState.values.gid} phone={multiState.values.phone} isOpen={isOpenReset} closeModal={closeResetModal} />
|
|
||||||
</>
|
</>
|
||||||
// </div>
|
// </div>
|
||||||
);
|
);
|
||||||
|
|||||||
+74
-19
@@ -1,14 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import React, { useState, useRef, useEffect } from "react";
|
import React, { useState, useRef, useEffect } from "react";
|
||||||
import CtModal from "@/components/CtModal";
|
import CtModal from "@/components/CtModal";
|
||||||
import ResetPasswordModal from "@/components/ResetPasswordModal";
|
|
||||||
import Button from "@/components/ui/button/Button2";
|
import Button from "@/components/ui/button/Button2";
|
||||||
import { useModal } from "@/hooks/useModal";
|
|
||||||
import Label from '@/components/form/Label2';
|
import Label from '@/components/form/Label2';
|
||||||
import Input from '@/components/form/input/InputField2';
|
import Input from '@/components/form/input/InputField2';
|
||||||
import Select from '@/components/form/Select2';
|
import Select from '@/components/form/Select2';
|
||||||
import { useMultiState } from "@/hooks/useMultiState";
|
import { useMultiState } from "@/hooks/useMultiState";
|
||||||
import api, { useAuthStore } from '@/lib/_AG';
|
import api, { useAuthStore } from '@/lib/_AG';
|
||||||
|
import { resetAccountPassword } from '@/lib/resetAccountPassword';
|
||||||
import Checkbox from "@/components/form/input/Checkbox";
|
import Checkbox from "@/components/form/input/Checkbox";
|
||||||
|
|
||||||
|
|
||||||
@@ -46,23 +45,50 @@ export default function AddModifyCustomerAccountModal({ multiState, onOk, isOpen
|
|||||||
|
|
||||||
const [ user_pw_confirm, setUserPwConfirm ] = useState<string>("");
|
const [ user_pw_confirm, setUserPwConfirm ] = useState<string>("");
|
||||||
|
|
||||||
const { isOpen: isOpenReset, openModal: openResetModal, closeModal: closeResetModal } = useModal();
|
// Only the signed-in user changes their own password here; anyone else's password is reset by text message
|
||||||
|
const isSelf = multiState.values.isModify && tokenPayload?.user_id === multiState.values.user_id;
|
||||||
|
// A new account gets a temporary password by text message, like an account issued with a business group
|
||||||
|
const showPassword = isSelf;
|
||||||
|
|
||||||
|
// Modifying yourself keeps the password unless the change box is checked
|
||||||
|
const [ isChangePw, setIsChangePw ] = useState<boolean>(false);
|
||||||
|
const needPassword = isSelf && isChangePw;
|
||||||
|
|
||||||
|
// Every opening starts with the box cleared and nothing typed
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
setIsChangePw(false);
|
||||||
|
setUserPwConfirm("");
|
||||||
|
}
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
|
const handleChangeIsChangePw = (checked: boolean) => {
|
||||||
|
setIsChangePw(checked);
|
||||||
|
if (!checked) {
|
||||||
|
multiState.set("user_pw", "");
|
||||||
|
setUserPwConfirm("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleClickAddOrModify = () => {
|
const handleClickAddOrModify = () => {
|
||||||
if (multiState.values.user_id == "") {
|
if (multiState.values.isModify && multiState.values.user_id == "") {
|
||||||
alert("계정 아이디를 입력하셔야 합니다.");
|
alert("계정 아이디를 입력하셔야 합니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (multiState.values.user_pw == "") {
|
else if (!multiState.values.isModify && !multiState.values.biz_reg_num) {
|
||||||
|
alert("사업자번호가 등록된 사업자만 계정을 발급할 수 있습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (needPassword && multiState.values.user_pw == "") {
|
||||||
alert("계정 비밀번호를 입력하셔야 합니다.");
|
alert("계정 비밀번호를 입력하셔야 합니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (user_pw_confirm == "") {
|
else if (needPassword && user_pw_confirm == "") {
|
||||||
alert("비밀번호 확인을 입력하셔야 합니다.");
|
alert("비밀번호 확인을 입력하셔야 합니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (multiState.values.user_pw !== user_pw_confirm) {
|
else if (needPassword && multiState.values.user_pw !== user_pw_confirm) {
|
||||||
alert("비밀번호 확인이 일치하지 않습니다.");
|
alert("비밀번호 확인이 일치하지 않습니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -74,6 +100,10 @@ export default function AddModifyCustomerAccountModal({ multiState, onOk, isOpen
|
|||||||
alert("휴대폰 번호를 입력하셔야 합니다.");
|
alert("휴대폰 번호를 입력하셔야 합니다.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (!multiState.values.isModify && !/^01[016789][0-9]{7,8}$/.test(multiState.values.phone.replace(/[^0-9]/g, ""))) {
|
||||||
|
alert("임시 비밀번호를 문자로 보내려면 올바른 휴대폰 번호를 입력해야 합니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { biz_group_name, biz_reg_num, ...params } = multiState.values;
|
const { biz_group_name, biz_reg_num, ...params } = multiState.values;
|
||||||
|
|
||||||
@@ -96,9 +126,21 @@ export default function AddModifyCustomerAccountModal({ multiState, onOk, isOpen
|
|||||||
console.log(resp);
|
console.log(resp);
|
||||||
|
|
||||||
if (resp.data.errCode == 0) {
|
if (resp.data.errCode == 0) {
|
||||||
alert("추가되었습니다.");
|
alert("추가되었습니다. 발급된 계정 정보를 휴대폰으로 보냈습니다.");
|
||||||
onOk();
|
onOk();
|
||||||
}
|
}
|
||||||
|
else if (resp.data.errCode == -19) {
|
||||||
|
alert("임시 비밀번호를 문자로 보내려면 올바른 휴대폰 번호를 입력해야 합니다.");
|
||||||
|
}
|
||||||
|
else if (resp.data.errCode == -20) {
|
||||||
|
alert("문자 발송에 실패해 계정 등록이 취소되었습니다. 잠시 후 다시 시도하세요.");
|
||||||
|
}
|
||||||
|
else if (resp.data.errCode == -17) {
|
||||||
|
alert("사업자번호가 등록된 사업자만 계정을 발급할 수 있습니다.");
|
||||||
|
}
|
||||||
|
else if (resp.data.errCode == -21) {
|
||||||
|
alert("이 사업자번호를 아이디로 사용 중인 계정이 이미 있습니다.");
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
alert("일시적으로 사용할 수 없습니다 : " + resp.data.errCode);
|
alert("일시적으로 사용할 수 없습니다 : " + resp.data.errCode);
|
||||||
}
|
}
|
||||||
@@ -126,18 +168,28 @@ export default function AddModifyCustomerAccountModal({ multiState, onOk, isOpen
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label redPoint>아이디</Label>
|
<Label redPoint>아이디</Label>
|
||||||
<Input type="text" value={multiState.values.user_id} onChange={(e) => multiState.set("user_id", e.target.value)} disabled={multiState.values.isModify ? true : false} />
|
{/* A new account signs in with the business number and picks its own ID at the first sign in */}
|
||||||
|
{ multiState.values.isModify ?
|
||||||
|
<Input type="text" value={multiState.values.user_id} disabled />
|
||||||
|
:
|
||||||
|
<Input type="text" value={"사업자번호로 발급" + (multiState.values.biz_reg_num ? " (" + multiState.values.biz_reg_num + ")" : "")} disabled />
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
{ !multiState.values.isModify || (multiState.values.isModify && tokenPayload?.user_id === multiState.values.user_id) ? <>
|
{ showPassword && <>
|
||||||
|
{ isSelf &&
|
||||||
<div>
|
<div>
|
||||||
<Label redPoint>비밀번호</Label>
|
<Checkbox checked={isChangePw} onChange={handleChangeIsChangePw} label="비밀번호 변경" />
|
||||||
<Input type="password" defaultValue="" onChange={(e) => multiState.set("user_pw", e.target.value)} />
|
</div>
|
||||||
|
}
|
||||||
|
<div>
|
||||||
|
<Label redPoint={needPassword}>비밀번호</Label>
|
||||||
|
<Input type="password" value={multiState.values.user_pw} onChange={(e) => multiState.set("user_pw", e.target.value)} disabled={!needPassword} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label redPoint>비밀번호 확인</Label>
|
<Label redPoint={needPassword}>비밀번호 확인</Label>
|
||||||
<Input type="password" value={user_pw_confirm} onChange={(e) => setUserPwConfirm(e.target.value)} />
|
<Input type="password" value={user_pw_confirm} onChange={(e) => setUserPwConfirm(e.target.value)} disabled={!needPassword} />
|
||||||
</div>
|
</div>
|
||||||
</> : <></>}
|
</>}
|
||||||
<div>
|
<div>
|
||||||
<Label redPoint>이름</Label>
|
<Label redPoint>이름</Label>
|
||||||
<Input type="text" value={multiState.values.name} onChange={(e) => multiState.set("name", e.target.value)} />
|
<Input type="text" value={multiState.values.name} onChange={(e) => multiState.set("name", e.target.value)} />
|
||||||
@@ -161,6 +213,8 @@ export default function AddModifyCustomerAccountModal({ multiState, onOk, isOpen
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>상태</Label>
|
<Label>상태</Label>
|
||||||
|
{/* A new account always starts initialized: the server sets it */}
|
||||||
|
{ multiState.values.isModify ?
|
||||||
<Select
|
<Select
|
||||||
placeholder="선택하세요"
|
placeholder="선택하세요"
|
||||||
options={[
|
options={[
|
||||||
@@ -169,15 +223,16 @@ export default function AddModifyCustomerAccountModal({ multiState, onOk, isOpen
|
|||||||
]}
|
]}
|
||||||
defaultValue={multiState.values.state} onChange={(e) => multiState.set("state", e.target.value)}
|
defaultValue={multiState.values.state} onChange={(e) => multiState.set("state", e.target.value)}
|
||||||
className="dark:bg-dark-900" />
|
className="dark:bg-dark-900" />
|
||||||
|
:
|
||||||
|
<Input type="text" value="초기화 (첫 로그인 시 아이디·비밀번호 변경)" disabled />
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
{ multiState.values.isModify &&
|
{ multiState.values.isModify && !isSelf &&
|
||||||
<div>
|
<div>
|
||||||
<Label>비밀번호 초기화</Label>
|
<Button size="sm" variant="outline" onClick={() => resetAccountPassword(multiState.values.gid, multiState.values.phone)}>비밀번호 초기화</Button>
|
||||||
<Button size="sm" variant="outline" onClick={openResetModal}>비밀번호 초기화</Button>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</CtModal>
|
</CtModal>
|
||||||
<ResetPasswordModal gid={multiState.values.gid} phone={multiState.values.phone} isOpen={isOpenReset} closeModal={closeResetModal} />
|
|
||||||
</>
|
</>
|
||||||
// </div>
|
// </div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
"use client";
|
|
||||||
import React, { useEffect, useState } from "react";
|
|
||||||
import CtModal from "@/components/CtModal";
|
|
||||||
import Label from '@/components/form/Label2';
|
|
||||||
import Input from '@/components/form/input/InputField2';
|
|
||||||
import api from '@/lib/_AG';
|
|
||||||
|
|
||||||
|
|
||||||
interface ResetPasswordModalProps {
|
|
||||||
gid: string;
|
|
||||||
phone: string; // the account's mobile number, shown as the default
|
|
||||||
isOpen: boolean;
|
|
||||||
closeModal: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sends a new temporary password to the account holder's mobile number */
|
|
||||||
export default function ResetPasswordModal({ gid, phone, isOpen, closeModal }: ResetPasswordModalProps) {
|
|
||||||
const [ inputPhone, setInputPhone ] = useState<string>("");
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isOpen)
|
|
||||||
setInputPhone(phone ?? "");
|
|
||||||
}, [isOpen, phone]);
|
|
||||||
|
|
||||||
const handleClickSend = () => {
|
|
||||||
if (inputPhone.trim() == "") {
|
|
||||||
alert("휴대폰 번호를 입력하세요");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
api.post('/api/reset-account-password.do', { gid: gid, phone: inputPhone }).then((resp) => {
|
|
||||||
if (resp.data.errCode == 0) {
|
|
||||||
alert("임시 비밀번호 전송완료");
|
|
||||||
closeModal();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
alert("전송에 실패했습니다.");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
alert("전송에 실패했습니다.");
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<CtModal
|
|
||||||
title="비밀번호 초기화"
|
|
||||||
okBtnText="임시 비밀번호 전송"
|
|
||||||
onClickOk={handleClickSend}
|
|
||||||
isOpen={isOpen}
|
|
||||||
closeModal={closeModal}
|
|
||||||
className="max-w-[500px] p-6 lg:p-10"
|
|
||||||
>
|
|
||||||
<div className="whitespace-pre-line text-sm text-gray-700 dark:text-gray-400">
|
|
||||||
{"비밀번호 초기화는 사용자의 휴대폰에 임시 비밀번호를 문자로 전송합니다.\n사용자의 휴대폰 번호를 입력하세요."}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label>휴대폰 번호</Label>
|
|
||||||
<Input type="text" placeholder="휴대폰 번호를 입력하세요." value={inputPhone} onChange={(e) => setInputPhone(e.target.value)}
|
|
||||||
onKeyDown={(e) => {if (e.key === "Enter") handleClickSend()}} />
|
|
||||||
</div>
|
|
||||||
</CtModal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import api from '@/lib/_AG';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces an account's password with a random one and texts it to the given mobile number.
|
||||||
|
* Used by the account modify modals, with the mobile number typed in the modal.
|
||||||
|
*/
|
||||||
|
export const resetAccountPassword = (gid: string, phone: string) => {
|
||||||
|
if (!phone || phone.trim() == "") {
|
||||||
|
alert("휴대폰 번호를 입력하세요");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!confirm("비밀번호를 초기화하고 " + phone + " 번호로 임시 비밀번호를 전송하시겠습니까?"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
api.post('/api/reset-account-password.do', { gid: gid, phone: phone }).then((resp) => {
|
||||||
|
console.log("reset-account-password", resp.data);
|
||||||
|
|
||||||
|
if (resp.data.errCode == 0)
|
||||||
|
alert("임시 비밀번호 전송완료");
|
||||||
|
else
|
||||||
|
alert("전송에 실패했습니다.");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
alert("전송에 실패했습니다.");
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user