Browse Source

用户修改密码

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@759 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
suntg 11 years ago
parent
commit
1d163cd494

+ 18 - 2
src/main/java/com/uas/platform/b2b/controller/UserController.java

@@ -20,6 +20,7 @@ import com.uas.platform.b2b.model.User;
 import com.uas.platform.b2b.service.UserService;
 import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.b2b.support.UsageBufferedLogger;
+import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import com.uas.platform.core.util.encry.Md5Utils;
 import com.uas.platform.core.util.serializer.FlexJsonUtils;
@@ -110,14 +111,13 @@ public class UserController {
 	}
 
 	/**
-	 * 修改用户基本信息
+	 * 验证用户输入的密码是否正确
 	 * @param email
 	 * @return
 	 */
 	@RequestMapping(value = "/checkPassword", method = RequestMethod.GET)
 	public ResponseEntity<String> checkPassword(String password) {
 		User user = SystemSession.getUser();
-		System.out.println(user.getUserPwd());
 		if(!StringUtils.isEmpty(password)) {
 			boolean result = user.getUserPwd().equals(Md5Utils.encode(password, user.getUserUU()));
 			if(result) {
@@ -128,4 +128,20 @@ public class UserController {
 		return new ResponseEntity<String>(HttpStatus.EXPECTATION_FAILED);
 	}
 
+	/**
+	 * 修改用户密码
+	 * @param email
+	 * @return
+	 */
+	@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
+	public ResponseEntity<String> updatePassword(String password, String newPassword) {
+		User user = SystemSession.getUser();
+		if(!StringUtils.isEmpty(newPassword)) {
+			userService.updatePassword(user, password, newPassword);
+			logger.log("用户信息", "修改用户密码,UU:" + user.getUserUU());
+			return new ResponseEntity<String>(HttpStatus.OK);
+		}else 
+			throw new IllegalOperatorException("新密码不能为空");
+	}
+
 }

+ 9 - 0
src/main/java/com/uas/platform/b2b/service/UserService.java

@@ -77,4 +77,13 @@ public interface UserService {
 	 */
 	public List<User> findAll();
 
+	/**
+	 * 修改用户密码
+	 * @param user 用户
+	 * @param password 原密码
+	 * @param newPassword 新密码
+	 * @return
+	 */
+	public User updatePassword(User user, String password, String newPassword);
+
 }

+ 13 - 0
src/main/java/com/uas/platform/b2b/service/impl/UserServiceImpl.java

@@ -101,5 +101,18 @@ public class UserServiceImpl implements UserService {
 			throw new IllegalOperatorException("修改的用户不存在");
 		}
 	}
+	
+	@Override
+	public User updatePassword(User user, String password, String newPassword) {
+		boolean result = user.getUserPwd().equals(Md5Utils.encode(password, user.getUserUU()));
+		if(result) {
+			User user1 = userDao.findOne(user.getUserUU());
+			user1.setUserPwd(Md5Utils.encode(newPassword, user1.getUserUU()));
+			userDao.save(user1);
+			return user1;
+		} else {
+			throw new IllegalOperatorException("原密码验证错误");
+		}
+	}
 
 }