From b14ca14a36298f48708393d9d7e2131d91e2fb05 Mon Sep 17 00:00:00 2001 From: TomQ Date: Wed, 14 Jun 2017 15:07:29 +0800 Subject: [PATCH] bug fix --- .../controller/protal/userController.java | 45 +++++++++---------- .../mmall/service/impl/UserServiceImpl.java | 26 +++++------ src/main/resources/logback.xml | 8 ++-- src/main/resources/mappers/UserMapper.xml | 28 ++++-------- 4 files changed, 45 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/mmall/controller/protal/userController.java b/src/main/java/com/mmall/controller/protal/userController.java index 39d3a00..1f18c96 100644 --- a/src/main/java/com/mmall/controller/protal/userController.java +++ b/src/main/java/com/mmall/controller/protal/userController.java @@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.mmall.common.Const; @@ -36,9 +35,7 @@ public class userController { @ResponseBody @RequestMapping(value = "login.do", method = RequestMethod.POST) - public ServerResponse login(@RequestParam("username") String username, - @RequestParam("password") String password, - @RequestParam("session") HttpSession session) { + public ServerResponse login(String username, String password, HttpSession session) { ServerResponse response = iUserService.login(username, password); if (response.isSuccess()) { session.setAttribute(Const.CURRENT_USER, response.getData()); @@ -54,9 +51,9 @@ public class userController { @ResponseBody @RequestMapping(value = "logout.do", method = RequestMethod.POST) - public ServerResponse logout(@RequestParam HttpSession session) { + public ServerResponse logout(HttpSession session) { session.removeAttribute(Const.CURRENT_USER); - return ServerResponse.createBySuccess(); + return ServerResponse.createBySuccessMessage("退出登录"); } /** @@ -67,7 +64,7 @@ public class userController { @ResponseBody @RequestMapping(value = "register.do", method = RequestMethod.POST) - public ServerResponse register(@RequestParam User user) { + public ServerResponse register(User user) { ServerResponse response = iUserService.register(user); return response; } @@ -81,8 +78,7 @@ public class userController { @ResponseBody @RequestMapping(value = "check_valid.do", method = RequestMethod.POST) - public ServerResponse checkValid(@RequestParam("str") String str, - @RequestParam("type") String type) { + public ServerResponse checkValid(String str, String type) { ServerResponse response = iUserService.checkValid(str, type); return response; } @@ -95,7 +91,7 @@ public class userController { @ResponseBody @RequestMapping(value = "get_user_info.do", method = RequestMethod.POST) - public ServerResponse getUserInfo(@RequestParam HttpSession session) { + public ServerResponse getUserInfo(HttpSession session) { User user = (User) session.getAttribute(Const.CURRENT_USER); if (user != null) { return ServerResponse.createBySuccess(user); @@ -110,7 +106,7 @@ public class userController { */ @ResponseBody @RequestMapping(value = "forget_get_question.do", method = RequestMethod.POST) - public ServerResponse forgetGetQuestion(@RequestParam String username) { + public ServerResponse forgetGetQuestion(String username) { return iUserService.selectQuestion(username); } @@ -123,9 +119,8 @@ public class userController { */ @ResponseBody @RequestMapping(value = "forget_check_answer.do", method = RequestMethod.POST) - public ServerResponse forgetCheckAnswer(@RequestParam String username, - @RequestParam String question, - @RequestParam String answer) { + public ServerResponse forgetCheckAnswer(String username, String question, + String answer) { return iUserService.checkAnswer(username, question, answer); } @@ -137,10 +132,9 @@ public class userController { * @return */ @ResponseBody - @RequestMapping(value = "forget_rest_password.do", method = RequestMethod.POST) - public ServerResponse forgetRestPassword(@RequestParam String username, - @RequestParam String passwordNew, - @RequestParam String forgetToken) { + @RequestMapping(value = "forget_reset_password.do", method = RequestMethod.POST) + public ServerResponse forgetRestPassword(String username, String passwordNew, + String forgetToken) { return iUserService.forgetRestPassword(username, passwordNew, forgetToken); } @@ -153,9 +147,8 @@ public class userController { */ @ResponseBody @RequestMapping(value = "reset_password.do", method = RequestMethod.POST) - public ServerResponse resetPassword(@RequestParam("session") HttpSession session, - @RequestParam("passwordOld") String passwordOld, - @RequestParam("passwordNew") String passwordNew) { + public ServerResponse resetPassword(HttpSession session, String passwordOld, + String passwordNew) { User user = (User) session.getAttribute(Const.CURRENT_USER); if (user == null) { return ServerResponse.createByErrorMessage("用户未登录"); @@ -171,8 +164,7 @@ public class userController { */ @ResponseBody @RequestMapping(value = "update_information.do", method = RequestMethod.POST) - public ServerResponse updateInformation(@RequestParam("session") HttpSession session, - @RequestParam("user") User user) { + public ServerResponse updateInformation(HttpSession session, User user) { User currentUser = (User) session.getAttribute(Const.CURRENT_USER); if (currentUser == null) { return ServerResponse.createByErrorMessage("用户未登录"); @@ -187,9 +179,14 @@ public class userController { return response; } + /** + * 获取用户详细信息 + * @param session + * @return + */ @ResponseBody @RequestMapping(value = "get_information.do", method = RequestMethod.POST) - public ServerResponse getInformation(@RequestParam("session") HttpSession session) { + public ServerResponse getInformation(HttpSession session) { User currentUser = (User) session.getAttribute(Const.CURRENT_USER); if (currentUser == null) { return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), diff --git a/src/main/java/com/mmall/service/impl/UserServiceImpl.java b/src/main/java/com/mmall/service/impl/UserServiceImpl.java index a35ca6b..469c99d 100644 --- a/src/main/java/com/mmall/service/impl/UserServiceImpl.java +++ b/src/main/java/com/mmall/service/impl/UserServiceImpl.java @@ -2,11 +2,8 @@ package com.mmall.service.impl; import java.util.UUID; -import ch.qos.logback.classic.gaffer.PropertyUtil; -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.io.CopyUtils; + import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.PropertyAccessorUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -33,10 +30,8 @@ public class UserServiceImpl implements IUserService { if (exist == 0) { return ServerResponse.createByErrorMessage("用户名不存在"); } - - //TODO 密码登录MD5 - - User user = userMapper.selectLogin(username, password); + String md5Password = MD5Util.MD5EncodeUtf8(password); + User user = userMapper.selectLogin(username, md5Password); if (user == null) { return ServerResponse.createByErrorMessage("密码或用户名错误"); } @@ -69,13 +64,13 @@ public class UserServiceImpl implements IUserService { if (Const.EMAIL.equals(type)) { int resultCount = userMapper.checkEmail(str); if (resultCount > 0) { - ServerResponse.createByErrorMessage("email已存在"); + return ServerResponse.createByErrorMessage("email已存在"); } } if (Const.USERNAME.equals(type)) { int resultCount = userMapper.checkUserName(str); if (resultCount > 0) { - ServerResponse.createByErrorMessage("用户名已存在"); + return ServerResponse.createByErrorMessage("用户名已存在"); } } } else { @@ -86,7 +81,7 @@ public class UserServiceImpl implements IUserService { public ServerResponse selectQuestion(String username) { ServerResponse validResponse = this.checkValid(username, Const.USERNAME); - if (!validResponse.isSuccess()) { + if (validResponse.isSuccess()) { return ServerResponse.createByErrorMessage("用户不存在"); } String question = userMapper.selectQuestionByUsername(username); @@ -107,15 +102,15 @@ public class UserServiceImpl implements IUserService { } public ServerResponse forgetRestPassword(String username, String passwordNew, String forgetToken) { - if(StringUtils.isNotBlank(forgetToken)){ + if(StringUtils.isBlank(forgetToken)){ return ServerResponse.createByErrorMessage("参数错误,token需要传递"); } ServerResponse validResponse = this.checkValid(username, Const.USERNAME); - if (!validResponse.isSuccess()) { + if (validResponse.isSuccess()) { return ServerResponse.createByErrorMessage("用户不存在"); } String token = TokenCache.getKey(TokenCache.TOKEN_PREFIX + username); - if(StringUtils.isNotBlank(token)){ + if(StringUtils.isBlank(token)){ return ServerResponse.createByErrorMessage("token无效或过期"); } if(StringUtils.equals(forgetToken,token)){ @@ -131,7 +126,8 @@ public class UserServiceImpl implements IUserService { } public ServerResponse resetPassword(String passwordOld,String passwordNew,User user){ - int resultCount = userMapper.checkPassword(user.getId(),passwordOld); + String md5PasswordOld = MD5Util.MD5EncodeUtf8(passwordOld); + int resultCount = userMapper.checkPassword(user.getId(),md5PasswordOld); if(resultCount == 0){ return ServerResponse.createByErrorMessage("旧密码错误"); } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index fe13a5e..890bd79 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -12,9 +12,9 @@ - /developer/apache-tomcat-7.0.73/logs/mmall.log + D:/apache-tomcat-9.0.0.M4-windows-x64/apache-tomcat-9.0.0.M4/logs/mmall.log - /developer/apache-tomcat-7.0.73/logs/mmall.log.%d{yyyy-MM-dd}.gz + D:/apache-tomcat-9.0.0.M4-windows-x64/apache-tomcat-9.0.0.M4/logs/mmall.log.%d{yyyy-MM-dd}.gz true 10 @@ -26,9 +26,9 @@ - /developer/apache-tomcat-7.0.73/logs/error.log + D:/apache-tomcat-9.0.0.M4-windows-x64/apache-tomcat-9.0.0.M4/logs/error.log - /devsoft/apache-tomcat-7.0.73/logs/error.log.%d{yyyy-MM-dd}.gz + D:/apache-tomcat-9.0.0.M4-windows-x64/apache-tomcat-9.0.0.M4/logs/error.log.%d{yyyy-MM-dd}.gz true 10 diff --git a/src/main/resources/mappers/UserMapper.xml b/src/main/resources/mappers/UserMapper.xml index 85a2c89..5002b9d 100644 --- a/src/main/resources/mappers/UserMapper.xml +++ b/src/main/resources/mappers/UserMapper.xml @@ -66,10 +66,10 @@ - + delete from mmall_user @@ -128,12 +128,8 @@ role, - create_time, - - update_time, - @@ -160,12 +156,8 @@ #{role,jdbcType=INTEGER}, - - #{createTime,jdbcType=TIMESTAMP}, - - - #{updateTime,jdbcType=TIMESTAMP}, - + now(), + now(), @@ -195,9 +187,7 @@ create_time = #{createTime,jdbcType=TIMESTAMP}, - - update_time = #{updateTime,jdbcType=TIMESTAMP}, - + update_time = now(), where id = #{id,jdbcType=INTEGER} @@ -211,7 +201,7 @@ answer = #{answer,jdbcType=VARCHAR}, role = #{role,jdbcType=INTEGER}, create_time = #{createTime,jdbcType=TIMESTAMP}, - update_time = #{updateTime,jdbcType=TIMESTAMP} + update_time = now() where id = #{id,jdbcType=INTEGER} \ No newline at end of file -- Gitee