Commit db14ea11 authored by renjie's avatar renjie

随机密码修改

parent 022c79f8
...@@ -32,7 +32,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -32,7 +32,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) throws Exception { public void configure(WebSecurity web) throws Exception {
web.ignoring() web.ignoring()
.antMatchers( "/user/authCode", "/user/signUp", .antMatchers( "/user/authCode", "/user/signUp", "/shop/multiadd",
"/user/reset*"); "/user/reset*");
} }
......
...@@ -47,9 +47,10 @@ public class ShopController { ...@@ -47,9 +47,10 @@ public class ShopController {
} }
@RequestMapping(value = "/multiadd", method = RequestMethod.POST) @RequestMapping(value = "/multiadd", method = RequestMethod.POST)
@ResponseBody
public List<String> addShops(Principal principal, @RequestParam("file") MultipartFile file) { public List<String> addShops(Principal principal, @RequestParam("file") MultipartFile file) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
String name=file.getOriginalFilename(); String name = file.getOriginalFilename();
if(name.length()<6 || !name.substring(name.length()-5).equals(".xlsx")){ if(name.length()<6 || !name.substring(name.length()-5).equals(".xlsx")){
resultDto.setStatus(-1); resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>(); Map<String, Object> statusInfo = new HashMap<>();
...@@ -57,9 +58,9 @@ public class ShopController { ...@@ -57,9 +58,9 @@ public class ShopController {
statusInfo.put("message", "文件格式错误"); statusInfo.put("message", "文件格式错误");
resultDto.setStatusInfo(statusInfo); resultDto.setStatusInfo(statusInfo);
} }
try { try {
shopService.addShops(principal.getName(), file); String username = "13192253730";
shopService.addShops(username, file);
} catch (ClientRequestException | IOException e) { } catch (ClientRequestException | IOException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>(); Map<String, Object> statusInfo = new HashMap<>();
......
...@@ -101,14 +101,49 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -101,14 +101,49 @@ public class IpResourceServiceImpl implements IpResourceService {
return headers; return headers;
} }
public static String makeRandomPassword(int len){ public static String genRandom(int srcFlag, int length) {
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray(); String retStr = "";
StringBuilder sb = new StringBuilder(); String strTable = "";
Random r = new Random(); switch (srcFlag) {
for (int x = 0; x < len; ++x) { case 1:
sb.append(charr[r.nextInt(charr.length)]); strTable = "1234567890";
break;
case 2:
strTable = "1234567890abcdefghijklmnopqrstuvwxyz";
break;
case 3:
strTable = "12345678901234567890abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;
case 4:
strTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;
case 5:
strTable = "abcdefghijklmnopqrstuvwxyz";
break;
default:
strTable = "1234567890abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;
}
int len = strTable.length();
boolean bDone = true;
do {
retStr = "";
int count = 0;
for (int i = 0; i < length; i++) {
double dblR = Math.random() * len;
int intR = (int) Math.floor(dblR);
char c = strTable.charAt(intR);
if (('0' <= c) && (c <= '9')) {
count++;
}
retStr += strTable.charAt(intR);
}
if (count >= 2) {
bDone = false;
} }
return sb.toString(); } while (bDone);
return retStr;
} }
private IpChargeRequestDto buildIpChargeRequestDto(IpResourceRequestDto request, int chargeType) { private IpChargeRequestDto buildIpChargeRequestDto(IpResourceRequestDto request, int chargeType) {
...@@ -162,7 +197,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -162,7 +197,7 @@ public class IpResourceServiceImpl implements IpResourceService {
if (StringUtils.isNotBlank(ipResourceRequestDto.getPassword())) if (StringUtils.isNotBlank(ipResourceRequestDto.getPassword()))
password = ipResourceRequestDto.getPassword(); password = ipResourceRequestDto.getPassword();
else else
password = makeRandomPassword(16); password = genRandom(3, 12);
map.put("loginPassword", password); map.put("loginPassword", password);
map.put("startscript", startscript); map.put("startscript", startscript);
map.put("ipkeptperiod", ipResourceRequestDto.getIpkeptperiod()); map.put("ipkeptperiod", ipResourceRequestDto.getIpkeptperiod());
......
...@@ -102,7 +102,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -102,7 +102,7 @@ public class ShopServiceImpl implements ShopService {
@Override @Override
public List<String> addShops(String username, MultipartFile file) throws IOException { public List<String> addShops(String username, MultipartFile file) throws IOException {
List<Object> list = FileUtil.readExcel(file.getInputStream()); List<Object> list = FileUtil.readExcel(file.getInputStream());
logger.error(list.toString());
return null; return null;
} }
......
package com.edgec.browserbackend.common.utils; package com.edgec.browserbackend.common.utils;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
...@@ -83,20 +85,24 @@ public class FileUtil { ...@@ -83,20 +85,24 @@ public class FileUtil {
//总列数 //总列数
int colLength = row.getLastCellNum(); int colLength = row.getLastCellNum();
//得到指定的单元格 //得到指定的单元格
Cell cell = row.getCell(0); Cell cell = row.getCell(0);;
for (int i = 2; i < rowLength; i++) { for (int i = 2; i < rowLength; i++) {
row = sheet.getRow(i); row = sheet.getRow(i);
for (int j = 0; j < colLength; j++) { for (int j = 0; j < colLength; j++) {
cell = row.getCell(j); cell = row.getCell(j);
// System.out.println(cell); // System.out.println(cell);
if (cell == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
if (cell != null) { if (cell != null) {
String cellValue = cell.getRichStringCellValue().getString(); Object cellValue = getCellFormatValue(cell);
if (StringUtils.isNotBlank(cellValue.toString()))
log.error(cellValue.toString());
} }
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("parse excel file error :", e); log.error("parse excel file error :", e);
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
} }
return list ; return list ;
} }
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>成功页面。。。</h1>
<form action="/shop/multiadd" method="post" enctype="multipart/form-data">
<p>文件上传</p>
<input type="file" name="file">
<p><input type="submit" value="提交"></p>
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment