Commit 19cdac75 by 邓实川 Committed by chenzg

密码修改,短信验证优化

parent 4131e0f0
...@@ -6,7 +6,6 @@ import java.util.List; ...@@ -6,7 +6,6 @@ import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -84,9 +83,9 @@ public class LoginController { ...@@ -84,9 +83,9 @@ public class LoginController {
phone = entRegisterDto.getUsername(); phone = entRegisterDto.getUsername();
entRegisterDto.setPhone(phone); entRegisterDto.setPhone(phone);
} }
JSONObject j = aliyunSMS.yzm(entRegisterDto, entRegisterDto.getTc(), code); JSONObject j = aliyunSMS.authCode(entRegisterDto, entRegisterDto.getTc(), code);
// String bizId = (String) j.get("BizId"); // String bizId = (String) j.get("BizId");
// Integer type = entRegisterDto.getMessageType(); // Integer type = entRegisterDto.getMessageType();
// 获取当前日期的字符串格式 // 获取当前日期的字符串格式
String today = DateUtil.today(); String today = DateUtil.today();
// yyyy-MM-dd // yyyy-MM-dd
...@@ -167,6 +166,39 @@ public class LoginController { ...@@ -167,6 +166,39 @@ public class LoginController {
* System.out.println(111); } * 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("修改成功");
}
/** /**
* 修改密码 * 修改密码
* *
...@@ -187,7 +219,7 @@ public class LoginController { ...@@ -187,7 +219,7 @@ public class LoginController {
if (code == null) { if (code == null) {
return ResultUtil.error("请填写验证码"); return ResultUtil.error("请填写验证码");
} }
if ( !code.toString().equals(codeRedis)) { if (!code.toString().equals(codeRedis)) {
return ResultUtil.error("验证码不符"); return ResultUtil.error("验证码不符");
} }
QyzxEmpLogin qyzxEmpLogin = new LambdaQueryChainWrapper<QyzxEmpLogin>(qyzxEmpLoginMapper) QyzxEmpLogin qyzxEmpLogin = new LambdaQueryChainWrapper<QyzxEmpLogin>(qyzxEmpLoginMapper)
...@@ -197,10 +229,10 @@ public class LoginController { ...@@ -197,10 +229,10 @@ public class LoginController {
qyzxEmpLogin.setPw(Md5.md5(pw)); qyzxEmpLogin.setPw(Md5.md5(pw));
qyzxEmpLogin.updateById(); qyzxEmpLogin.updateById();
return ResultUtil.success("修改密码成功"); return ResultUtil.success("修改密码成功");
}else { } else {
return ResultUtil.error("修改密码失败,查找不到该人员!"); return ResultUtil.error("修改密码失败,查找不到该人员!");
} }
}else { } else {
if (code == null) { if (code == null) {
return ResultUtil.error("请填写原密码"); return ResultUtil.error("请填写原密码");
} }
...@@ -215,14 +247,14 @@ public class LoginController { ...@@ -215,14 +247,14 @@ public class LoginController {
qyzxEmpLogin.setPw(Md5.md5(code)); qyzxEmpLogin.setPw(Md5.md5(code));
qyzxEmpLogin.updateById(); qyzxEmpLogin.updateById();
return ResultUtil.success("修改密码成功"); return ResultUtil.success("修改密码成功");
}else { } else {
return ResultUtil.error("原密码有误!请核对重试"); return ResultUtil.error("原密码有误!请核对重试");
} }
} }
return ResultUtil.error("修改密码失败,查找不到该人员!"); return ResultUtil.error("修改密码失败,查找不到该人员!");
} }
//return ResultUtil.error("修改密码失败"); // return ResultUtil.error("修改密码失败");
} }
/** /**
......
...@@ -31,6 +31,9 @@ public class EntRegisterDto implements Serializable { ...@@ -31,6 +31,9 @@ public class EntRegisterDto implements Serializable {
@ApiModelProperty(value = "短信时间 ", example = "20191207") @ApiModelProperty(value = "短信时间 ", example = "20191207")
private String sendDate; private String sendDate;
@ApiModelProperty(value = "原密码", example = "666666")
private String oldPwd;
@ApiModelProperty(value = "验证码 ", example = "666666") @ApiModelProperty(value = "验证码 ", example = "666666")
private String code; private String code;
...@@ -40,7 +43,7 @@ public class EntRegisterDto implements Serializable { ...@@ -40,7 +43,7 @@ public class EntRegisterDto implements Serializable {
@ApiModelProperty(value = "短信模板:1.身份验证验证码 2.登录确认验证码 3.登录异常验证码 4.用户注册验证码 5.修改密码验证码 6.信息变更验证码 ", example = "1") @ApiModelProperty(value = "短信模板:1.身份验证验证码 2.登录确认验证码 3.登录异常验证码 4.用户注册验证码 5.修改密码验证码 6.信息变更验证码 ", example = "1")
private Integer tc; private Integer tc;
@ApiModelProperty(value = "1.验证码修改密码 2.原密码修改密码 ", example = "1") @ApiModelProperty(value = "1.原密码修改 2.验证码修改 ", example = "1")
private Integer pwUpdateType; private Integer pwUpdateType;
} }
package cn.timer.api.utils; package cn.timer.api.utils;
import org.springframework.web.bind.annotation.RequestParam;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest; import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse; import com.aliyuncs.CommonResponse;
...@@ -20,6 +22,12 @@ import cn.timer.api.dto.qyzx.EntRegisterDto; ...@@ -20,6 +22,12 @@ import cn.timer.api.dto.qyzx.EntRegisterDto;
*/ */
public class AliyunSMS { 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 * @param phone
...@@ -27,9 +35,12 @@ public class AliyunSMS { ...@@ -27,9 +35,12 @@ public class AliyunSMS {
* 5."修改密码验证码" 6."信息变更验证码" * 5."修改密码验证码" 6."信息变更验证码"
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public JSONObject yzm(EntRegisterDto entRegisterDto, Integer templateCode, Integer code) { public JSONObject authCode(EntRegisterDto entRegisterDto,
DefaultProfile profile = DefaultProfile.getProfile("cn-shenzhen", "LTAI4FuaShJWQ1dggsFWG5CC", @RequestParam(required = false, defaultValue = "1") Integer templateCode, Integer code) {
"EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR");
String phone = entRegisterDto.getPhone();
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
IAcsClient client = new DefaultAcsClient(profile); IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest(); CommonRequest request = new CommonRequest();
...@@ -37,37 +48,37 @@ public class AliyunSMS { ...@@ -37,37 +48,37 @@ public class AliyunSMS {
request.setDomain("dysmsapi.aliyuncs.com"); request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25"); request.setVersion("2017-05-25");
request.setAction("SendSms"); request.setAction("SendSms");
request.putQueryParameter("RegionId", "cn-shenzhen"); request.putQueryParameter("RegionId", regionId);
request.putQueryParameter("PhoneNumbers", entRegisterDto.getPhone()); request.putQueryParameter("PhoneNumbers", phone);
request.putQueryParameter("SignName", "8小时人事管家"); request.putQueryParameter("SignName", projectName);
switch (templateCode) { switch (templateCode) {
// 1."身份验证验证码" // 1."身份验证验证码"
case 1: case 1:
request.putQueryParameter("TemplateCode", "SMS_178485364"); request.putQueryParameter(name, "SMS_178485364");
break; break;
// 2."登录确认验证码" // 2."登录确认验证码"
case 2: case 2:
request.putQueryParameter("TemplateCode", "SMS_178485363"); request.putQueryParameter(name, "SMS_178485363");
break; break;
// 3."登录异常验证码" // 3."登录异常验证码"
case 3: case 3:
request.putQueryParameter("TemplateCode", "SMS_178485362"); request.putQueryParameter(name, "SMS_178485362");
break; break;
// 4."用户注册验证码" // 4."用户注册验证码"
case 4: case 4:
request.putQueryParameter("TemplateCode", "SMS_178485361"); request.putQueryParameter(name, "SMS_178485361");
break; break;
// 5."修改密码验证码" // 5."修改密码验证码"
case 5: case 5:
request.putQueryParameter("TemplateCode", "SMS_178485360"); request.putQueryParameter(name, "SMS_178485360");
break; break;
// 6."信息变更验证码" // 6."信息变更验证码"
case 6: case 6:
request.putQueryParameter("TemplateCode", "SMS_178485359"); request.putQueryParameter(name, "SMS_178485359");
break; break;
default: default:
request.putQueryParameter("TemplateCode", "SMS_178485364"); request.putQueryParameter(name, "SMS_178485364");
} }
// 【8小时人事管家】验证码934169,您正在尝试修改登录密码,请妥善保管账户信息。 // 【8小时人事管家】验证码934169,您正在尝试修改登录密码,请妥善保管账户信息。
request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}"); 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