계정 발급, 수정 임시비밀번호 로직 변경

This commit is contained in:
comicgum
2026-09-17 15:44:25 +09:00
parent ef277abe70
commit d70c457d10
13 changed files with 289 additions and 141 deletions
+4 -4
View File
@@ -1,8 +1,8 @@
# docker build -t hd1-was:1.0.8 .
# docker tag hd1-was:1.0.8 192.168.219.191:19101/hd1-was:1.0.8
# docker push 192.168.219.191:19101/hd1-was:1.0.8
# docker build -t hd1-was:1.1.0 .
# 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.1.0
# or
# .\_docker_push.bat 1.0.8
# .\_docker_push.bat 1.1.0
FROM eclipse-temurin:21-jdk
WORKDIR /app
+6 -6
View File
@@ -1,13 +1,13 @@
# docker pull 49.165.181.28:19101/hd1-was:1.0.8
docker stop hd1-was
docker rm hd1-was
docker-compose up -d
# docker pull 49.165.181.28:19101/hd1-was:1.1.0
# docker stop hd1-was
# docker rm hd1-was
# docker-compose up -d
# or
# _docker_pull_restart.sh 1.0.8
# _docker_pull_restart.sh 1.1.0
services:
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
ports:
- "28080:18080"
@@ -104,7 +104,8 @@ class AccountController {
Boolean perm_uid1 = _AG.toBoolean(body.get("perm_uid1"));
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);
return result;
}
@@ -26,4 +26,6 @@ public interface AccountMapper {
int updateInitAccount(Long gid, String user_id, String user_pw);
int updateResetPassword(Long gid, String user_pw);
int invalidatePendingIssuedAccount(String user_id);
}
@@ -14,6 +14,8 @@ public interface BizGroupMapper {
String phone, String address);
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> selectBizGroupByTerminalId(Long terminal_id);
@@ -23,8 +23,11 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
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.BizGroupMapper;
@Service
@@ -34,14 +37,16 @@ public class AccountService {
private final AccountMapper accountMapper;
private final PasswordEncoder passwordEncoder;
private final SMSSender smsSender;
private final BizGroupMapper bizGroupMapper;
@Value("${sms.callback}") String smsCallback;
@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.passwordEncoder = passwordEncoder;
this.smsSender = smsSender;
this.bizGroupMapper = bizGroupMapper;
}
public CtResponse getAccount(Long gid, String user_id) {
@@ -78,6 +83,7 @@ public class AccountService {
return mapResult;
}
@Transactional
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) {
CtResponse result = new CtResponse();
@@ -85,7 +91,8 @@ public class AccountService {
//UserInfo userInfo = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
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)
biz_group_id = new_biz_group_id;
@@ -107,19 +114,33 @@ public class AccountService {
DbLogger.insert(2L, "계정정보 수정", userInfo.getGid());
}
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()) {
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;
}
String tempPw = TempPassword.create();
Map<String, Object> params = new HashMap<>();
params.put("user_id", user_id);
//params.put("user_pw", user_pw);
params.put("user_pw", enc_pw);
params.put("user_pw", passwordEncoder.encode(tempPw));
params.put("name", name);
params.put("phone", phone);
params.put("phone", mobile);
params.put("email", email);
params.put("state", state);
params.put("state", BizGroupService.ACCOUNT_STATE_INIT);
params.put("biz_group_id", biz_group_id);
if (biz_group_id == 667) //TempCode
@@ -134,19 +155,58 @@ public class AccountService {
if (accountMapper.insertAccount(params) == 0) {
result.setErrCode(ErrorCode.INVALID_PARAMETER);
return result;
}
else {
DbLogger.insert(2L, "신규 계정 추가, id: " + user_id, userInfo.getGid());
//result.put("result", Map.of("gid", params.get("gid")));
Map<String, Object> ret = new HashMap<String, Object>();
ret.put("gid", params.get("gid"));
result.put("result", ret);
// 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")));
Map<String, Object> ret = new HashMap<String, Object>();
ret.put("gid", params.get("gid"));
result.put("result", ret);
}
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.
* 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]", "");
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);
return result;
}
@@ -210,12 +271,14 @@ public class AccountService {
CtResponse resAccount = getAccount(gid, null);
Map<String, Object> mapAccount = (Map<String, Object>)resAccount.get("result");
if (mapAccount == null) {
logger.info("resetPassword: account not found, gid={}", gid);
result.setErrCode(ErrorCode.INVALID_USER);
return result;
}
String newPw = TempPassword.create();
if (accountMapper.updateResetPassword(gid, passwordEncoder.encode(newPw)) == 0) {
logger.info("resetPassword: nothing updated, gid={}", gid);
result.setErrCode(ErrorCode.QUERY_ERROR);
return result;
}
@@ -228,6 +291,7 @@ public class AccountService {
SMSSender.Result sendResult = smsSender.send(smsCallback, mobile, msg);
if (sendResult.isSuccess() == false) {
logger.warn("resetPassword: sms failed, gid={}, mobile={}, result={}", gid, mobile, sendResult);
result.setErrCode(ErrorCode.SMS_SEND_FAILED);
result.put("sms_code", sendResult.code);
return result;
@@ -13,7 +13,6 @@ import org.apache.ibatis.jdbc.SQL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
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.Permission;
import com.handong.smartservice.component.RcTreeBizGroup;
import com.handong.smartservice.component.SMSSender;
import com.handong.smartservice.component.TempPassword;
import com.handong.smartservice.component.UserInfo;
import com.handong.smartservice.mapper.AccountMapper;
@@ -43,10 +41,7 @@ public class BizGroupService {
@Autowired BizGroupMapper bizGroupMapper;
@Autowired AccountMapper accountMapper;
@Autowired PasswordEncoder passwordEncoder;
@Autowired SMSSender smsSender;
@Value("${sms.callback}") String smsCallback;
@Value("${account.site-url}") String siteUrl;
@Autowired AccountService accountService;
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);
return result;
}
accountService.invalidatePendingIssuedAccount(biz_reg_num);
if (accountMapper.countActiveUserId(biz_reg_num, 0L) > 0) {
result.setErrCode(ErrorCode.ACCOUNT_ALREADY_EXIST);
return result;
@@ -179,14 +175,7 @@ public class BizGroupService {
params.put("permission", permission.get());
accountMapper.insertAccount(params);
String msg = "[스마트서비스] 계정이 발급되었습니다.\n"
+ "사이트: " + siteUrl + "\n"
+ "ID: " + biz_reg_num + "\n"
+ "임시비밀번호: " + tempPw + "\n"
+ "로그인 후 아이디와 비밀번호를 변경해 주세요.";
SMSSender.Result sendResult = smsSender.send(smsCallback, mobile, msg);
return sendResult.isSuccess() ? null : sendResult.code;
return accountService.sendIssuedAccountMessage(biz_reg_num, tempPw, mobile);
}
@@ -163,6 +163,14 @@
WHERE gid = #{gid} AND state != 2
</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">
<if test='ids != null and ids.size > 0'>
UPDATE account
@@ -41,6 +41,13 @@
</if>
</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 biz_group_id
FROM biz_group