Browse Source

账户中心配置

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@5924 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
yingp 9 years ago
parent
commit
2ae7bf5ea7

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

@@ -3,6 +3,7 @@ package com.uas.platform.b2b.controller;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpHeaders;
@@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import com.uas.platform.b2b.model.Enterprise;
 import com.uas.platform.b2b.model.User;
 import com.uas.platform.b2b.model.UserInfo;
 import com.uas.platform.b2b.model.Vendor;
@@ -133,10 +135,14 @@ public class UserController {
 	 * @return
 	 */
 	@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
-	public ResponseEntity<String> updatePassword(String password, String newPassword) {
+	public ResponseEntity<String> updatePassword(HttpSession session, String password, String newPassword) {
 		User user = SystemSession.getUser();
+		Enterprise enterprise = user.getEnterprise();
 		if (!StringUtils.isEmpty(newPassword)) {
-			userService.updatePassword(user, password, newPassword);
+			user = userService.updatePassword(user, password, newPassword);
+			user.setEnterprise(enterprise);
+			session.setAttribute("user", user);
+			SystemSession.setUser(user);
 			logger.log("用户信息", "修改用户密码,UU:" + user.getUserUU());
 			return new ResponseEntity<String>(HttpStatus.OK);
 		} else

+ 46 - 7
src/main/java/com/uas/platform/b2b/model/User.java

@@ -19,6 +19,7 @@ import javax.persistence.OrderBy;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 import javax.persistence.Transient;
+
 import org.codehaus.jackson.annotate.JsonIgnore;
 import org.hibernate.annotations.Cache;
 import org.hibernate.annotations.CacheConcurrencyStrategy;
@@ -75,7 +76,7 @@ public class User implements Serializable {
 	private Short enable;
 
 	private Short issys;
-	
+
 	@Column(name = "user_imid")
 	private Long userIMId;
 
@@ -124,7 +125,7 @@ public class User implements Serializable {
 	@Transient
 	@NotFound(action = NotFoundAction.IGNORE)
 	private String ip;
-	
+
 	/**
 	 * 判断是否被分配
 	 */
@@ -259,9 +260,9 @@ public class User implements Serializable {
 		if (this.enterprise == null)
 			setCurrentEnterprise();
 	}
-	
+
 	public void setCurrentEnterprise(Enterprise enterprise) {
-		if(!CollectionUtils.isEmpty(SystemSession.getUser().getEnterprises())) {
+		if (!CollectionUtils.isEmpty(SystemSession.getUser().getEnterprises())) {
 			Set<Enterprise> enterprises = new HashSet<Enterprise>();
 			for (Enterprise en : SystemSession.getUser().getEnterprises()) {
 				if (en.equals(enterprise)) {
@@ -313,7 +314,7 @@ public class User implements Serializable {
 	public void setIp(String ip) {
 		this.ip = ip;
 	}
-	
+
 	public boolean getDistribute() {
 		return distribute;
 	}
@@ -324,18 +325,56 @@ public class User implements Serializable {
 
 	/**
 	 * 获取用户所属企业UU号
+	 * 
 	 * @return
 	 */
 	@JSONField(serialize = false)
 	@JsonIgnore
 	public Set<Long> getEnUUs() {
 		Set<Long> enUUs = new HashSet<Long>();
-		if( ! CollectionUtils.isEmpty(enterprises)) {
-			for(Enterprise en : enterprises) {
+		if (!CollectionUtils.isEmpty(enterprises)) {
+			for (Enterprise en : enterprises) {
 				enUUs.add(en.getUu());
 			}
 		}
 		return enUUs;
 	}
 
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((userEmail == null) ? 0 : userEmail.hashCode());
+		result = prime * result + ((userTel == null) ? 0 : userTel.hashCode());
+		result = prime * result + ((userUU == null) ? 0 : userUU.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		User other = (User) obj;
+		if (userEmail == null) {
+			if (other.userEmail != null)
+				return false;
+		} else if (!userEmail.equals(other.userEmail))
+			return false;
+		if (userTel == null) {
+			if (other.userTel != null)
+				return false;
+		} else if (!userTel.equals(other.userTel))
+			return false;
+		if (userUU == null) {
+			if (other.userUU != null)
+				return false;
+		} else if (!userUU.equals(other.userUU))
+			return false;
+		return true;
+	}
+
 }

+ 4 - 2
src/main/java/com/uas/platform/b2b/service/impl/UserServiceImpl.java

@@ -37,6 +37,7 @@ import com.uas.platform.b2b.support.SysConf;
 import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.b2b.support.TokenService;
 import com.uas.platform.core.exception.IllegalOperatorException;
+import com.uas.platform.core.exception.SystemException;
 import com.uas.platform.core.model.Constant;
 import com.uas.platform.core.model.Status;
 import com.uas.platform.core.util.AgentUtils;
@@ -208,6 +209,7 @@ public class UserServiceImpl implements UserService {
 			user1.setUserPwd(Md5Utils.encode(newPassword, user1.getUserUU()));
 			if (user1.getEnterprise() == null)
 				user1.setCurrentEnterprise();// 随便绑定一个用户所属企业
+			Enterprise enterprise = user1.getEnterprise();
 			try {
 				// if (isNotSaas(SystemSession.getUser().getEnterprise().getUu())) {
 				// if (user.getEnterprise() != null) {
@@ -223,9 +225,9 @@ public class UserServiceImpl implements UserService {
 				// user1 = userDao.save(user1);
 				// }
 				user1 = userDao.save(user1);
-				AccountUtils.resetPassword(user1.getUserUU(), user1.getEnterprise().getUu(), newPassword);
+				AccountUtils.resetPassword(user1.getUserUU(), enterprise.getUu(), newPassword);
 			} catch (Exception e) {
-				throw new RuntimeException(e.getMessage());
+				throw new SystemException(e.getMessage());
 			}
 			return user1;
 		} else {