TASK:凭证更新;

This commit is contained in:
shahaibo
2024-09-13 11:13:23 +08:00
parent cebc05d132
commit 472f5e65b4
3 changed files with 60 additions and 0 deletions

View File

@@ -107,4 +107,11 @@ public class ThirdPartyController {
public Response<String> getRedirectUrl() {
return Response.success(REDIRECT_URL);
}
@CrossOrigin
@ApiOperation(value = "add No Login Required")
@PostMapping("/updateNoLoginRequiredNew")
public Response<String> updateNoLoginRequiredNew(@RequestBody NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) {
return Response.success(accountService.updateNoLoginRequiredNew(noLoginRequiredDTO, request));
}
}

View File

@@ -157,4 +157,6 @@ public interface AccountService extends IService<Account> {
IPage<Account> getPageByIds(List<Long> ids, int pageNum, int size);
List<Account> getByIds(List<Long> ids);
String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request);
}

View File

@@ -875,6 +875,57 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
"                        </html>";
}
@Override
@Transactional(rollbackFor = Exception.class)
public String updateNoLoginRequiredNew(NoLoginRequiredDTO noLoginRequiredDTO, HttpServletRequest request) {
// 验证机房注册序列号001-100
String id = noLoginRequiredDTO.getId();
if (!isStringInRange(id)) {
throw new BusinessException("Illegal serial number.");
}
// 获取真实 IP 地址,考虑了经过代理的情况
String ipAddress = request.getHeader("X-Forwarded-For");
if (ipAddress == null || ipAddress.isEmpty() || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.isEmpty() || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.isEmpty() || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
}
String browserIdentifiers = ipAddress + "," + id;
// 构建查询条件,查找已注册的账户数量
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Account::getUserName, "PolyU-SFT-" + id);
// queryWrapper.lambda().eq(Account::getBrowserIdentifiers, browserIdentifiers);
List<Account> existingAccounts = accountMapper.selectList(queryWrapper);
// 检查序列号是否被注册
if (!CollectionUtil.isNotEmpty(existingAccounts)) {
throw new BusinessException("Updated serial number not found.");
}
Account account = existingAccounts.get(0);
account.setBrowserIdentifiers(browserIdentifiers);
accountMapper.updateById(account);
return "<!DOCTYPE html>\n" +
"                        <html lang=\"en\">\n" +
"                        <head>\n" +
"                            <meta charset=\"UTF-8\">\n" +
"                            <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
"                            <title>Document</title>\n" +
" <link rel=\"icon\" href=\"https://polyu.aida.com.hk/favicon.ico\">\n" +
"                        </head>\n" +
"                        <body>\n" +
"                        </body>\n" +
"                            <script>\n" +
"                                window.location.href = 'https://polyu.aida.com.hk?" + id + "';\n" +
"                            </script>\n" +
"                        </html>";
}
public static boolean isStringInRange(String input) {
// 去除字符串两端的空格
input = input.trim();