提交 54bc8ca7 编写于 作者: 爱吃血肠's avatar 爱吃血肠

找回密码模块完成

上级 b8089610
......@@ -88,4 +88,12 @@ public interface UserService {
* @return
*/
public User queryUserByEmail(String email);
/**
* 根据邮箱修改用户密码
* @param user 用户信息
* @param code 验证码
* @param session 存储系统发送的验证码
*/
public void updatePasswordByEmail(User user, String code, HttpSession session);
}
\ No newline at end of file
......@@ -139,4 +139,39 @@ public class UserServiceImpl implements UserService {
return userDao.queryUserByEmail(email);
}
/**
* 根据邮箱修改当前登录用户的密码
* @param user 用户信息
* @param code 验证码
* @param session session存储系统发送的验证码
*/
@Transactional(propagation= Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED,rollbackFor=Throwable.class)
@Override
public void updatePasswordByEmail(User user, String code, HttpSession session) {
try{
User userFind = queryUserByEmail(user.getEmail());
if(userFind == null){
throw new BizException("用户不存在");
}
String emailCode = (String)session.getAttribute("code");
if(!emailCode.equals(code)){
throw new BizException("验证码错误");
}
//加密密码
if(user!=null){
user.setPassword(Md5Util.md5Password(user.getPassword()));
}else{
return;
}
user.setId(userFind.getId());
if(1 != userDao.updateTUserById(user)){
throw new Exception("插入数据影响函数不唯一");
}
}catch (BizException biz){
throw new BizException(biz.getMessage(),biz);
}catch (Exception e){
throw new RuntimeException("插入数据影响函数不唯一",e);
}
}
}
\ No newline at end of file
......@@ -47,14 +47,16 @@ public class FindPwdController {
*/
@ResponseBody
@RequestMapping(value = "/findPwd",produces = {"application/json;charset=UTF-8"})
public BaseResult<Object> userLogin() {
public BaseResult<Object> userLogin(User user,String code,HttpSession session) {
try {
LOG.info("用户信息 " + user);
LOG.info("用户输入的验证码 " + code);
userService.updatePasswordByEmail(user,code,session);
} catch (BizException e) {
return new BaseResult<>(false, e.getMessage());
} catch (Exception e) {
return new BaseResult<>(false, ResultEnum.INVALID_USER.getMsg());
}
return new BaseResult<>(true, "登陆成功");
return new BaseResult<>(true, "修改成功");
}
}
......@@ -45,19 +45,20 @@
</div>
<div class="findPwd">
<div class="contentInfo">
<form action="/find/findPwd" id="findPwdForm" name="findPwdForm">
<ul class="getInfo margin-t-49 margin-l-40">
<li class="margin-b-19">
<label class="infoName1 inputDes" for="tel">登录邮箱号:</label>
<input class="info2" type="text" name="email" id="tel" value="" placeholder=""/>
<label class="infoName1 inputDes" for="email">登录邮箱号:</label>
<input class="info2" type="text" name="email" id="email" value="" placeholder=""/>
</li>
<li class="margin-b-19">
<label class="infoName1 inputDes" for="code">验证码:</label>
<input class="info2" type="text" name="code" id="code" value="" placeholder=""/>
<span class="bounceBtn" id="getCode" onclick="settime(this)"><a class="count" href="javascript:void(0)">获取验证码</a></span>
<span class="bounceBtn" id="getCode" onclick="setTime(this)"><a class="count" href="javascript:void(0)">获取验证码</a></span>
</li>
<li class="margin-b-19">
<label class="infoName1 inputDes" for="newPwd">新登录密码:</label>
<input class="info write-n" type="text" name="newPwd" id="newPwd" value="" placeholder=""/>
<input class="info write-n" type="text" name="password" id="newPwd" value="" placeholder=""/>
</li>
<li class="margin-b-19">
<label class="infoName1 inputDes" for="pwd-a">再次输入新密码:</label>
......@@ -67,6 +68,7 @@
<div class="btn-bounce" onclick="sure()">
<a class="width-206" href="javascript:void(0)">确定</a>
</div>
</form>
</div>
</div>
</div>
......
......@@ -42,25 +42,43 @@ function addReceive(){
function closeBounce(){
$(".bounces").addClass('hide');
}
function settime(val) {
// 获取验证码
var countdown = 60;
function setTime(val) {
var $val = $(val);
if (countdown == 0) {
if (countdown == 60){
//异步发送验证码
$.ajax({
type: 'POST',
data: $('#findPwdForm').serialize(),
dataType: "json",
url: '/user/getEmailCode',
success: function (data) {
if (data.success) {
} else {
}
}
});
}
if (countdown == 0) {
$('#getCode').removeClass('countBtn');
$('#getCode').addClass('bounceBtn');
val.removeAttribute("disabled");
val.removeAttribute("disabled");
$val.children().html("获取验证码")
countdown = 60;
} else {
countdown = 60;
} else {
$('#getCode').removeClass('bounceBtn');
$('#getCode').addClass('countBtn');
val.setAttribute("disabled", true);
val.setAttribute("disabled", true);
$val.children().html("重新发送" + countdown + "s")
countdown--;
setTimeout(function() {
settime(val)
},1000)
}
}
countdown--;
setTimeout(function() {
settime(val)
},1000)
}
}
function sure(){
var $newPwd = $("#newPwd").val();
var $pwda = $("#pwd-a").val();
......@@ -69,4 +87,19 @@ function sure(){
$("#pwd-a").addClass('noPass')
$("#pwd-a").after('<span class="noPassImg-bounce"><img src="img/refuse.png"/>输入不一致</span>')
}
$.ajax({
type: 'POST',
data: $('#findPwdForm').serialize(),
dataType: "json",
url: '/find/findPwd',
success: function (data) {
if(data.success){
alert("修改成功");
window.location.href="/user/login";
}else{
alert(data.error);
}
}
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册