|
@@ -9,17 +9,20 @@ import com.jeesite.modules.report.entity.WebsiteUser;
|
|
|
import com.jeesite.modules.report.service.WebsiteUserService;
|
|
|
import com.jeesite.modules.report.util.JwtUtil;
|
|
|
import com.jeesite.modules.report.util.PasswordUtil;
|
|
|
-import com.jeesite.modules.sys.utils.RedisUtil;
|
|
|
import com.jeesite.modules.report.util.oConvertUtils;
|
|
|
import com.jeesite.modules.sys.annotation.WebsiteAuth;
|
|
|
import com.jeesite.modules.sys.utils.R;
|
|
|
+import com.jeesite.modules.sys.utils.RedisUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -32,6 +35,9 @@ public class WebsiteUserControllerApi extends AbstractController {
|
|
|
private RedisUtil redisUtil;
|
|
|
@Resource
|
|
|
private WebsiteUserService websiteUserService;
|
|
|
+ @Value("${token.expiretime}")
|
|
|
+ private int EXPIRE;
|
|
|
+
|
|
|
/**
|
|
|
* 登录页面
|
|
|
*/
|
|
@@ -69,7 +75,7 @@ public class WebsiteUserControllerApi extends AbstractController {
|
|
|
String token = JwtUtil.sign(loginCode, password);
|
|
|
// 设置token缓存有效时间
|
|
|
redisUtil.set(Constants.PREFIX_USER_TOKEN + token, oldUser.getId());
|
|
|
- redisUtil.expire(Constants.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
|
|
|
+ redisUtil.expire(Constants.PREFIX_USER_TOKEN + token, EXPIRE);
|
|
|
//TODO 单点登录,缓存登录用户的Token
|
|
|
redisUtil.lSet(Constants.PREFIX_USER_TOKEN_LIST + loginCode, token);
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
@@ -113,33 +119,46 @@ public class WebsiteUserControllerApi extends AbstractController {
|
|
|
*/
|
|
|
@WebsiteAuth
|
|
|
@PostMapping(value = "updatePwd")
|
|
|
- public String infoSavePwd(String newPassword,
|
|
|
+ public String updatePwd(String newPassword,
|
|
|
String confirmNewPassword) {
|
|
|
String userId = getUserIdByRequest();
|
|
|
WebsiteUser websiteUser = websiteUserService.get(userId);
|
|
|
// 登录密码解密(解决密码明文传输安全问题)
|
|
|
String secretKey = Global.getProperty("shiro.loginSubmit.secretKey");
|
|
|
-// if (StringUtils.isNotBlank(secretKey)){
|
|
|
-// oldPassword = DesUtils.decode(oldPassword, secretKey);
|
|
|
-// newPassword = DesUtils.decode(newPassword, secretKey);
|
|
|
-// confirmNewPassword = DesUtils.decode(confirmNewPassword, secretKey);
|
|
|
-// }
|
|
|
-// // 验证旧密码
|
|
|
-// if(!PwdUtils.validatePassword(oldPassword, currentUser.getPassword())){
|
|
|
-// return renderResult(Global.FALSE, text("sys.user.oldPasswordError"));
|
|
|
-// }
|
|
|
-// // 验证新密码和确认密码
|
|
|
-// if(!StringUtils.equals(newPassword, confirmNewPassword)){
|
|
|
-// return renderResult(Global.FALSE, text("sys.user.confirmPasswrodError"));
|
|
|
-// }
|
|
|
-// // 更新密码
|
|
|
-// try{
|
|
|
-// userService.updatePassword(currentUser.getUserCode(), confirmNewPassword);
|
|
|
-// return renderResult(Global.TRUE, text("sys.user.passwordModifySuccess"));
|
|
|
-// }catch(ServiceException se){
|
|
|
-// return renderResult(Global.FALSE, se.getMessage());
|
|
|
-// }
|
|
|
- return null;
|
|
|
+ if (StringUtils.isNotBlank(secretKey)){
|
|
|
+ newPassword = DesUtils.decode(newPassword, secretKey);
|
|
|
+ confirmNewPassword = DesUtils.decode(confirmNewPassword, secretKey);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(newPassword)) {
|
|
|
+ return "密码为空";
|
|
|
+ }
|
|
|
+ // 验证新密码和确认密码
|
|
|
+ if(!StringUtils.equals(newPassword, confirmNewPassword)){
|
|
|
+ return "两次密码不一致";
|
|
|
+ }
|
|
|
+ // 更新密码
|
|
|
+ String passwordEncode = PasswordUtil.encrypt(websiteUser.getLoginCode(), newPassword, websiteUser.getSalt());
|
|
|
+ websiteUser.setPassword(passwordEncode);
|
|
|
+ websiteUserService.updatePass(websiteUser);
|
|
|
+ return "成功";
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 退出登录
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/logout")
|
|
|
+ public String logout(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ //用户退出逻辑
|
|
|
+ String token = request.getHeader(Constants.WEBSITE_TOKEN);
|
|
|
+ if (oConvertUtils.isEmpty(token)) {
|
|
|
+ return "退出登录失败!";
|
|
|
+ }
|
|
|
+ //清空用户登录Token缓存
|
|
|
+ redisUtil.del(Constants.PREFIX_USER_TOKEN + token);
|
|
|
+ return "退出登录成功!";
|
|
|
+ }
|
|
|
}
|