if (StringUtils.isEmpty(name) || StringUtils.isEmpty(email)) {
addActionError("error.parameters.needed");
return (ERROR);
}
List<User> userList = entityDao.get(User.class, "name", name);
User user = null;
if (userList.isEmpty()) {
return goErrorWithMessage("error.user.notExist");
} else {
user = userList.get(0);
}
if (!StringUtils.equals(email, user.getMail())) {
return goErrorWithMessage("error.email.notEqualToOrign");
} else {
String longinName = user.getName();
String password = RandomStringUtils.randomNumeric(6);
user.setRemark(password);
user.setPassword(EncryptUtil.encode(password));
String title = getText("user.password.sendmail.title");
List<Object> values = CollectUtils.newArrayList();
values.add(longinName);
values.add(password);
String body = getText("user.password.sendmail.body", values);
try {
SimpleMailMessage msg = new SimpleMailMessage(message);
msg.setTo(user.getMail());
msg.setSubject(title);
msg.setText(body.toString());
mailSender.send(msg);
} catch (Exception e) {
e.printStackTrace();
logger.info("reset password error for user:" + user.getName() + " with email :"
+ user.getMail());
return goErrorWithMessage("error.email.sendError");
}
}
entityDao.saveOrUpdate(user);
return forward("sendResult");