Commit 19cdac75 by 邓实川 Committed by chenzg

密码修改,短信验证优化

parent 4131e0f0
......@@ -6,7 +6,6 @@ import java.util.List;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -84,9 +83,9 @@ public class LoginController {
phone = entRegisterDto.getUsername();
entRegisterDto.setPhone(phone);
}
JSONObject j = aliyunSMS.yzm(entRegisterDto, entRegisterDto.getTc(), code);
// String bizId = (String) j.get("BizId");
// Integer type = entRegisterDto.getMessageType();
JSONObject j = aliyunSMS.authCode(entRegisterDto, entRegisterDto.getTc(), code);
// String bizId = (String) j.get("BizId");
// Integer type = entRegisterDto.getMessageType();
// 获取当前日期的字符串格式
String today = DateUtil.today();
// yyyy-MM-dd
......@@ -141,31 +140,64 @@ public class LoginController {
* @return
* @throws IOException
*//*
* @PostMapping(value = "/test")
*
* @ApiOperation(value = "3.测试", httpMethod = "POST", notes = "接口发布说明")
*
* @ApiOperationSupport(order = 3) public void test(HttpServletRequest request,
* HttpServletResponse res) throws IOException {
*
* res.setHeader("content-type","text/html;charset=UTF-8");
* res.setHeader("selfHeader","selfHeaderValue"); //
* res.addHeader("response_code", "123"); //
* res.setContentType("application/octet-stream"); //
* res.addHeader("Content-Length", "0");
*
* res.addHeader("response_code", "100"); res.addHeader("trans_id", "");
* res.addHeader("cmd_code", "NO com");
*
* res.setContentType("application/octet-stream");
* res.addHeader("Content-Length", "0");
*
* res.flushBuffer(); // response.addHeader("response_code",
* "ERROR_INVALID_LIB_NAME"); //
* response.setContentType("application/octet-stream"); //
* response.addHeader("Content-Length", "0"); // response.flushBuffer();
* System.out.println(111); }
*/
* @PostMapping(value = "/test")
*
* @ApiOperation(value = "3.测试", httpMethod = "POST", notes = "接口发布说明")
*
* @ApiOperationSupport(order = 3) public void test(HttpServletRequest request,
* HttpServletResponse res) throws IOException {
*
* res.setHeader("content-type","text/html;charset=UTF-8");
* res.setHeader("selfHeader","selfHeaderValue"); //
* res.addHeader("response_code", "123"); //
* res.setContentType("application/octet-stream"); //
* res.addHeader("Content-Length", "0");
*
* res.addHeader("response_code", "100"); res.addHeader("trans_id", "");
* res.addHeader("cmd_code", "NO com");
*
* res.setContentType("application/octet-stream");
* res.addHeader("Content-Length", "0");
*
* res.flushBuffer(); // response.addHeader("response_code",
* "ERROR_INVALID_LIB_NAME"); //
* response.setContentType("application/octet-stream"); //
* response.addHeader("Content-Length", "0"); // response.flushBuffer();
* System.out.println(111); }
*/
@PostMapping(value = "/updatePwd")
@ApiOperation(value = "4.修改密码(新)", httpMethod = "POST", notes = "接口发布说明")
@ApiOperationSupport(order = 4)
public Result<String> updatepwd(@RequestBody EntRegisterDto entRegisterDto) {
String oldPwd = entRegisterDto.getOldPwd();// 输入的原密码
String pw = entRegisterDto.getPw();// 输入的新密码
String phone = entRegisterDto.getPhone();// 手机号
String code = entRegisterDto.getCode();// 验证码
Integer type = entRegisterDto.getPwUpdateType();// 验证方式
QyzxEmpLogin qyzxEmpLogin = new LambdaQueryChainWrapper<QyzxEmpLogin>(qyzxEmpLoginMapper)
.eq(!StrUtil.hasBlank(phone), QyzxEmpLogin::getPhone, phone).one();// 员工登录表
String dbPwd = qyzxEmpLogin.getPw();// 数据库原密码
if (type == 1) {
if (!Md5.md5(oldPwd).equals(dbPwd)) {
return ResultUtil.error("原密码验证失败");
}
if (pw.equals(oldPwd)) {
return ResultUtil.error("新密码与原密码相同,请修改后重试!");
}
} else {
Object codeRedis = session.getAttribute(phone);
if (!code.equals(codeRedis.toString())) {
return ResultUtil.error("短信验证码错误");
}
if (Md5.md5(pw).equals(dbPwd)) {
return ResultUtil.error("新密码与原密码相同,请修改后重试!");
}
}
qyzxEmpLogin.setPw(Md5.md5(pw));
qyzxEmpLogin.updateById();
return ResultUtil.success("修改成功");
}
/**
* 修改密码
......@@ -181,13 +213,13 @@ public class LoginController {
String pw = entRegisterDto.getPw();
String code = entRegisterDto.getCode();
if (entRegisterDto.getPwUpdateType() != 2) {
// String codeRedis =redisTemplate.get(phone).toString();
String codeRedis = session.getAttribute(phone).toString();
if (code == null) {
return ResultUtil.error("请填写验证码");
}
if ( !code.toString().equals(codeRedis)) {
if (!code.toString().equals(codeRedis)) {
return ResultUtil.error("验证码不符");
}
QyzxEmpLogin qyzxEmpLogin = new LambdaQueryChainWrapper<QyzxEmpLogin>(qyzxEmpLoginMapper)
......@@ -197,10 +229,10 @@ public class LoginController {
qyzxEmpLogin.setPw(Md5.md5(pw));
qyzxEmpLogin.updateById();
return ResultUtil.success("修改密码成功");
}else {
} else {
return ResultUtil.error("修改密码失败,查找不到该人员!");
}
}else {
} else {
if (code == null) {
return ResultUtil.error("请填写原密码");
}
......@@ -208,21 +240,21 @@ public class LoginController {
return ResultUtil.error("新密码与原密码相同!请更改重试");
}
QyzxEmpLogin qyzxEmpLogin = new LambdaQueryChainWrapper<QyzxEmpLogin>(qyzxEmpLoginMapper)
.eq(!StrUtil.hasBlank(phone), QyzxEmpLogin::getPhone, phone).one();
.eq(!StrUtil.hasBlank(phone), QyzxEmpLogin::getPhone, phone).one();
if (qyzxEmpLogin != null) {
if (qyzxEmpLogin.getPw().equals(Md5.md5(pw))) {
qyzxEmpLogin.setPhone(phone);
qyzxEmpLogin.setPw(Md5.md5(code));
qyzxEmpLogin.updateById();
return ResultUtil.success("修改密码成功");
}else {
} else {
return ResultUtil.error("原密码有误!请核对重试");
}
}
return ResultUtil.error("修改密码失败,查找不到该人员!");
}
//return ResultUtil.error("修改密码失败");
// return ResultUtil.error("修改密码失败");
}
/**
......@@ -413,7 +445,7 @@ public class LoginController {
if (list != null && list.size() > 0) {
LambdaQueryWrapper<ZzglAuth> wp = new LambdaQueryWrapper<>();
wp.select(ZzglAuth::getMenuId).eq(ZzglAuth::getOrgCode, qyzxEmpLogin1.getOrgId())
.and(i -> i.in(ZzglAuth::getBmgwId, list.toArray()));
.and(i -> i.in(ZzglAuth::getBmgwId, list.toArray()));
List<ZzglAuth> zas = ZzglAuth.builder().build().selectList(wp);
List<String> menus = new ArrayList<>();
zas.stream().forEach(o -> menus.add(o.getMenuId()));
......
......@@ -31,6 +31,9 @@ public class EntRegisterDto implements Serializable {
@ApiModelProperty(value = "短信时间 ", example = "20191207")
private String sendDate;
@ApiModelProperty(value = "原密码", example = "666666")
private String oldPwd;
@ApiModelProperty(value = "验证码 ", example = "666666")
private String code;
......@@ -40,7 +43,7 @@ public class EntRegisterDto implements Serializable {
@ApiModelProperty(value = "短信模板:1.身份验证验证码 2.登录确认验证码 3.登录异常验证码 4.用户注册验证码 5.修改密码验证码 6.信息变更验证码 ", example = "1")
private Integer tc;
@ApiModelProperty(value = "1.验证码修改密码 2.原密码修改密码 ", example = "1")
@ApiModelProperty(value = "1.原密码修改 2.验证码修改 ", example = "1")
private Integer pwUpdateType;
}
package cn.timer.api.utils;
import org.springframework.web.bind.annotation.RequestParam;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
......@@ -20,6 +22,12 @@ import cn.timer.api.dto.qyzx.EntRegisterDto;
*/
public class AliyunSMS {
final String name = "TemplateCode";// 模板参数
final String regionId = "cn-shenzhen";// 地区参数
final String projectName = "8小时人事管家";// 项目名
final String accessKeyId = "LTAI4FuaShJWQ1dggsFWG5CC";
final String secret = "EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR";
/**
*
* @param phone
......@@ -27,9 +35,12 @@ public class AliyunSMS {
* 5."修改密码验证码" 6."信息变更验证码"
*/
@SuppressWarnings("deprecation")
public JSONObject yzm(EntRegisterDto entRegisterDto, Integer templateCode, Integer code) {
DefaultProfile profile = DefaultProfile.getProfile("cn-shenzhen", "LTAI4FuaShJWQ1dggsFWG5CC",
"EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR");
public JSONObject authCode(EntRegisterDto entRegisterDto,
@RequestParam(required = false, defaultValue = "1") Integer templateCode, Integer code) {
String phone = entRegisterDto.getPhone();
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
......@@ -37,37 +48,37 @@ public class AliyunSMS {
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("RegionId", "cn-shenzhen");
request.putQueryParameter("PhoneNumbers", entRegisterDto.getPhone());
request.putQueryParameter("SignName", "8小时人事管家");
request.putQueryParameter("RegionId", regionId);
request.putQueryParameter("PhoneNumbers", phone);
request.putQueryParameter("SignName", projectName);
switch (templateCode) {
// 1."身份验证验证码"
case 1:
request.putQueryParameter("TemplateCode", "SMS_178485364");
request.putQueryParameter(name, "SMS_178485364");
break;
// 2."登录确认验证码"
case 2:
request.putQueryParameter("TemplateCode", "SMS_178485363");
request.putQueryParameter(name, "SMS_178485363");
break;
// 3."登录异常验证码"
case 3:
request.putQueryParameter("TemplateCode", "SMS_178485362");
request.putQueryParameter(name, "SMS_178485362");
break;
// 4."用户注册验证码"
case 4:
request.putQueryParameter("TemplateCode", "SMS_178485361");
request.putQueryParameter(name, "SMS_178485361");
break;
// 5."修改密码验证码"
case 5:
request.putQueryParameter("TemplateCode", "SMS_178485360");
request.putQueryParameter(name, "SMS_178485360");
break;
// 6."信息变更验证码"
case 6:
request.putQueryParameter("TemplateCode", "SMS_178485359");
request.putQueryParameter(name, "SMS_178485359");
break;
default:
request.putQueryParameter("TemplateCode", "SMS_178485364");
request.putQueryParameter(name, "SMS_178485364");
}
// 【8小时人事管家】验证码934169,您正在尝试修改登录密码,请妥善保管账户信息。
request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
......
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