Commit db14ea11 authored by renjie's avatar renjie

随机密码修改

parent 022c79f8
......@@ -32,7 +32,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers( "/user/authCode", "/user/signUp",
.antMatchers( "/user/authCode", "/user/signUp", "/shop/multiadd",
"/user/reset*");
}
......
......@@ -47,9 +47,10 @@ public class ShopController {
}
@RequestMapping(value = "/multiadd", method = RequestMethod.POST)
@ResponseBody
public List<String> addShops(Principal principal, @RequestParam("file") MultipartFile file) {
ResultDto resultDto = new ResultDto();
String name=file.getOriginalFilename();
String name = file.getOriginalFilename();
if(name.length()<6 || !name.substring(name.length()-5).equals(".xlsx")){
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
......@@ -57,9 +58,9 @@ public class ShopController {
statusInfo.put("message", "文件格式错误");
resultDto.setStatusInfo(statusInfo);
}
try {
shopService.addShops(principal.getName(), file);
String username = "13192253730";
shopService.addShops(username, file);
} catch (ClientRequestException | IOException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
......
......@@ -101,14 +101,49 @@ public class IpResourceServiceImpl implements IpResourceService {
return headers;
}
public static String makeRandomPassword(int len){
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
StringBuilder sb = new StringBuilder();
Random r = new Random();
for (int x = 0; x < len; ++x) {
sb.append(charr[r.nextInt(charr.length)]);
public static String genRandom(int srcFlag, int length) {
String retStr = "";
String strTable = "";
switch (srcFlag) {
case 1:
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;
}
return sb.toString();
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;
}
} while (bDone);
return retStr;
}
private IpChargeRequestDto buildIpChargeRequestDto(IpResourceRequestDto request, int chargeType) {
......@@ -162,7 +197,7 @@ public class IpResourceServiceImpl implements IpResourceService {
if (StringUtils.isNotBlank(ipResourceRequestDto.getPassword()))
password = ipResourceRequestDto.getPassword();
else
password = makeRandomPassword(16);
password = genRandom(3, 12);
map.put("loginPassword", password);
map.put("startscript", startscript);
map.put("ipkeptperiod", ipResourceRequestDto.getIpkeptperiod());
......
......@@ -102,7 +102,7 @@ public class ShopServiceImpl implements ShopService {
@Override
public List<String> addShops(String username, MultipartFile file) throws IOException {
List<Object> list = FileUtil.readExcel(file.getInputStream());
logger.error(list.toString());
return null;
}
......
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.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
......@@ -83,20 +85,24 @@ public class FileUtil {
//总列数
int colLength = row.getLastCellNum();
//得到指定的单元格
Cell cell = row.getCell(0);
Cell cell = row.getCell(0);;
for (int i = 2; i < rowLength; i++) {
row = sheet.getRow(i);
for (int j = 0; j < colLength; j++) {
cell = row.getCell(j);
// System.out.println(cell);
if (cell == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
if (cell != null) {
String cellValue = cell.getRichStringCellValue().getString();
Object cellValue = getCellFormatValue(cell);
if (StringUtils.isNotBlank(cellValue.toString()))
log.error(cellValue.toString());
}
}
}
} catch (Exception e) {
log.error("parse excel file error :", e);
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
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