|
|
@@ -9,6 +9,7 @@ import com.uas.platform.b2bManage.model.Constant;
|
|
|
import com.uas.platform.b2bManage.model.SecretKeyRecord;
|
|
|
import com.uas.platform.b2bManage.model.User;
|
|
|
import com.uas.platform.b2bManage.service.UserService;
|
|
|
+import com.uas.platform.b2bManage.support.SecurityConstant;
|
|
|
import com.uas.platform.b2bManage.support.StringUtil;
|
|
|
import com.uas.platform.core.util.encry.Md5Utils;
|
|
|
import javassist.NotFoundException;
|
|
|
@@ -37,21 +38,6 @@ public class UserServiceImpl implements UserService {
|
|
|
@Autowired
|
|
|
private MailService mailService;
|
|
|
|
|
|
- /**
|
|
|
- * 找回密码邮件模板地址
|
|
|
- */
|
|
|
- private final String RESETPWDURL = "276896ec-e480-4c32-b6d4-a6c07c6e0d21";
|
|
|
-
|
|
|
- /**
|
|
|
- * 管理平台地址
|
|
|
- */
|
|
|
- private final String MANAGEURL = "http://192.168.253.12:23396";
|
|
|
-
|
|
|
- /**
|
|
|
- * 失效链接地址
|
|
|
- */
|
|
|
- private final String INVALIDURL = "/invalid";
|
|
|
-
|
|
|
@Autowired
|
|
|
private SecretKeyRecordDao recordDao;
|
|
|
|
|
|
@@ -128,6 +114,7 @@ public class UserServiceImpl implements UserService {
|
|
|
public User register(User user) {
|
|
|
String name = user.getEmail().substring(0, user.getEmail().indexOf("@"));
|
|
|
user.setPassword(Md5Utils.encode(user.getPassword(), name));
|
|
|
+ user.setEmail(user.getEmail() + Constant.EMAIL_SUFFIX);
|
|
|
user.setName(name);
|
|
|
return userDao.save(user);
|
|
|
}
|
|
|
@@ -148,11 +135,11 @@ public class UserServiceImpl implements UserService {
|
|
|
} else {
|
|
|
record = recordDao.save(new SecretKeyRecord(email, StringUtil.uuid()));
|
|
|
}
|
|
|
- String url = MANAGEURL + "/restPwd?secretKey=" + record.getSecretKey();
|
|
|
+ String url = Constant.MANAGEURL + "/resetPwd/url?secretKey=" + record.getSecretKey();
|
|
|
ModelMap map = new ModelMap();
|
|
|
map.put("resetPwdUrl", url);
|
|
|
try {
|
|
|
- mailService.send(RESETPWDURL, email, map);
|
|
|
+ mailService.send(Constant.RESETPWD_MOULD_URL, email, map);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -168,24 +155,41 @@ public class UserServiceImpl implements UserService {
|
|
|
@Override
|
|
|
public User resetPwd(String secretKey, HttpServletResponse response) throws IOException, NotFoundException {
|
|
|
if (StringUtils.isEmpty(secretKey)) {
|
|
|
- response.sendRedirect(INVALIDURL);
|
|
|
+ response.sendRedirect(Constant.INVALIDURL);
|
|
|
}
|
|
|
SecretKeyRecord record = recordDao.findBySecretKey(secretKey);
|
|
|
if (null == record) {
|
|
|
- response.sendRedirect(INVALIDURL);
|
|
|
+ response.sendRedirect(Constant.INVALIDURL);
|
|
|
} else {
|
|
|
if (System.currentTimeMillis() - record.getTime() > Constant.SECRECTTIME) {
|
|
|
recordDao.delete(record);
|
|
|
- response.sendRedirect(INVALIDURL);
|
|
|
+ response.sendRedirect(Constant.INVALIDURL);
|
|
|
} else {
|
|
|
- List<User> users = userDao.findByEmail(record.getEmail());
|
|
|
- if (!CollectionUtils.isEmpty(users)) {
|
|
|
+ List<User> users = userDao.findByEmail(record.getEmail().trim());
|
|
|
+ if (CollectionUtils.isEmpty(users)) {
|
|
|
throw new NotFoundException("未找到该邮箱用户信息");
|
|
|
} else {
|
|
|
- return users.get(0);
|
|
|
+ SystemSession.setUser(users.get(0));
|
|
|
+ recordDao.delete(record);
|
|
|
+ response.sendRedirect(Constant.RESETPWD_URL);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改密码
|
|
|
+ *
|
|
|
+ * @param id 用户id
|
|
|
+ * @param password 密码
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void resetPassword(Long id, String password, HttpServletResponse response) throws IOException {
|
|
|
+ User user = userDao.findOne(id);
|
|
|
+ user.setPassword(Md5Utils.encode(password, user.getName()));
|
|
|
+ userDao.save(user);
|
|
|
+ SystemSession.clear();
|
|
|
+ response.sendRedirect(SecurityConstant.LOGIN_URL);
|
|
|
+ };
|
|
|
}
|