日期:2014-05-17 浏览次数:20714 次
$("#rt-submit").click(function () { //“登录”按钮单击事件
var jsonObj={user:{username : $("#rt-name").val()
, email: $("#rt-email").val()}
,msg:"test"};
var jsonStr=JSON.stringify(jsonObj);
var url="<%=basePath %>ajax/forget.action";
$.post(url
, {json:jsonStr}
,function(data){
alert(data.msg);
});
});
public class forgetAction extends ActionSupport {
private User user;
private UserService userService = new UserService();
private String msg;
private String json;
/*省略getter setter*/
public String forget() throws Exception {
System.out.println(json);
System.out.println(msg);
if (user !=null ){
//查找数据库
user = userService.loadUserByNameAndEmial(user.getUsername(),user.getEmail());
}
boolean isSend = false;
Random r = new Random();
int num = r.nextInt(999999);
//发送随即生成的六位数字保存为新的密码并发送邮件
if (user !=null && !"".equals(user.getEmail())) {
user.setPassword(num+"");
userService.update(user);
String content = "恭喜忘记密码申请成功~ 已生成随机密码:"+num;
MailSenderInfo mailInfo = new MailSenderInfo();
mailInfo.setMailServerHost("smtp.qq.com");
mailInfo.setMailServerPort("25");
mailInfo.setValidate(true);
mailInfo.setFromAddress("16546145646" + "@qq.com");
mailInfo.setToAddress(user.getEmail());
mailInfo.setUserName("13465984654" + "@qq.com");
mailInfo.setPassword("111111");
mailInfo.setSubject("忘记密码申请");
mailInfo.setContent(content);
isSend = SimpleMailSender.sendTextMail(mailInfo);
}
if (isSend){
msg="申请成功,新密码已经发送到您的邮箱";
return SUCCESS;
}
addActionError("发送失败!请检查信息是否输入正确!");
msg="发送失败!请检查信息是否输入正确!";
return SUCCESS;
}