Browse Source

初步完成账户管理-修改邮箱功能

liusw 8 years ago
parent
commit
54f44215fc

+ 88 - 1
src/main/java/com/uas/platform/b2c/common/account/controller/UserController.java

@@ -29,6 +29,8 @@ import javax.persistence.criteria.Root;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSession;
 import java.util.List;
 import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
 
 
 /**
 /**
  * 用户信息的请求
  * 用户信息的请求
@@ -119,6 +121,64 @@ public class UserController {
 			throw new IllegalOperatorException("新密码不能为空");
 			throw new IllegalOperatorException("新密码不能为空");
 	}
 	}
 
 
+	/**
+	 * 验证用户输入的邮箱地址是否正确
+	 *
+	 * @param userEmail 用户输入邮箱地址
+	 */
+	@RequestMapping(value = "/checkUserEmail", method = RequestMethod.GET)
+	public ResponseEntity<String> checkUserEmail(String userEmail) {
+		User sysUser = SystemSession.getUser();
+		User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
+		if (!StringUtils.isEmpty(userEmail)) {
+
+			boolean result = user.getUserEmail().equals(userEmail);
+			if (result) {
+				return new ResponseEntity<>(HttpStatus.OK);
+			}
+			assert logger != null;
+			logger.log("用户信息", "验证用户邮箱地址,UU:" + user.getUserUU());
+		}
+		return new ResponseEntity<>(HttpStatus.EXPECTATION_FAILED);
+	}
+
+	/**
+	 * 发送验证码
+	 *
+	 * @param newUserEmail 用户输入新邮箱地址
+	 */
+	@RequestMapping(value = "/sendCheckCode", method = RequestMethod.GET)
+	public ResponseEntity<String> sendCheckCode(String newUserEmail,final HttpServletRequest request) {
+		User sysUser = SystemSession.getUser();
+		User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
+		if (!StringUtils.isEmpty(newUserEmail)) {
+			//检查是否已经发送
+			final HttpSession session = request.getSession();
+			if(session.getAttribute(String.valueOf(user.getUserUU()))!=null){
+				return new ResponseEntity<>(HttpStatus.EXPECTATION_FAILED);
+			}
+			//发送邮件
+			String result = userService.sendCheckCode(newUserEmail);
+			System.out.println(result);
+			if (result!=null && !result.equals("")){
+				/*
+				final Timer timer=new Timer();
+				timer.schedule(new TimerTask() {
+					@Override
+					public void run() {
+						session.removeAttribute(String.valueOf(user.getUserUU()));
+						timer.cancel();
+					}
+				},10*60*1000);
+				*/
+				return new ResponseEntity<>(HttpStatus.OK);
+			}
+			assert logger != null;
+			logger.log("用户信息", "验证用户邮箱地址,UU:" + user.getUserUU());
+		}
+		return new ResponseEntity<>(HttpStatus.EXPECTATION_FAILED);
+	}
+
 	/**
 	/**
 	 * 根据UU获取该企业所有人员信息
 	 * 根据UU获取该企业所有人员信息
 	 * @param enuu 企业uu号
 	 * @param enuu 企业uu号
@@ -129,6 +189,7 @@ public class UserController {
 		PageInfo pageInfo = new PageInfo(params);
 		PageInfo pageInfo = new PageInfo(params);
 		return userService.findUsersPageByEnUU(pageInfo,enuu);
 		return userService.findUsersPageByEnUU(pageInfo,enuu);
 	}
 	}
+
 	/**
 	/**
 	 * 通过关键词获取该企业所有人员信息
 	 * 通过关键词获取该企业所有人员信息
 	 * @param enuu 企业uu号
 	 * @param enuu 企业uu号
@@ -139,7 +200,6 @@ public class UserController {
 		PageInfo pageInfo = new PageInfo(params);
 		PageInfo pageInfo = new PageInfo(params);
 		return userService.findUsersPageByEnUUAndKeyword(pageInfo,enuu,keyword);
 		return userService.findUsersPageByEnUUAndKeyword(pageInfo,enuu,keyword);
 	}
 	}
-
 	/**
 	/**
 	 * 新增用户
 	 * 新增用户
 	 *
 	 *
@@ -155,6 +215,33 @@ public class UserController {
 		}
 		}
 		return new ResponseEntity<String>(HttpStatus.OK);
 		return new ResponseEntity<String>(HttpStatus.OK);
 	}
 	}
+
+	/**
+	 * 修改用户邮箱
+	 * @param session
+	 * @param userEmail
+	 * @param newUserEmail
+	 * @return
+	 */
+	@RequestMapping(value = "/updateUserEmail", method = RequestMethod.POST)
+	public ResponseEntity<String> updateUserEmail(HttpSession session, String userEmail, String newUserEmail) {
+		if (userEmail.equals(newUserEmail)){
+			throw new IllegalOperatorException("新邮箱地址与旧邮箱地址相同");
+		}
+		User sysUser = SystemSession.getUser();
+		User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
+		Enterprise enterprise = user.getEnterprise();
+		if (!StringUtils.isEmpty(newUserEmail)) {
+			user = userService.updatePassword(user, userEmail, newUserEmail);
+			user.setEnterprise(enterprise);
+			session.setAttribute("user", user);
+			SystemSession.setUser(user);
+			assert logger != null;
+			logger.log("用户信息", "修改用户邮箱地址,UU:" + user.getUserUU());
+			return new ResponseEntity<>(HttpStatus.OK);
+		} else
+			throw new IllegalOperatorException("新邮箱地址不能为空");
+	}
 	/**
 	/**
 	 * 删除用户
 	 * 删除用户
 	 *
 	 *

+ 16 - 0
src/main/java/com/uas/platform/b2c/common/account/service/UserService.java

@@ -103,4 +103,20 @@ public interface UserService {
 	public void removeUser(Long uu);
 	public void removeUser(Long uu);
 	public boolean isEmailUseable(String email);
 	public boolean isEmailUseable(String email);
 	public boolean isTelUseable(String tel);
 	public boolean isTelUseable(String tel);
+
+	/**
+	 * 发送验证码
+	 * @param newEmail 用户输入的新验证码
+	 * @return
+	 */
+	public String sendCheckCode(String newEmail);
+
+	/**
+	 * 修改用户邮箱地址
+	 * @param user 用户
+	 * @param userEmail 用户旧邮箱地址
+	 * @param newUserEmail 用户新邮箱地址
+	 * @return
+	 */
+	User updateUserEmail(User user, String userEmail, String newUserEmail);
 }
 }

+ 37 - 0
src/main/java/com/uas/platform/b2c/common/account/service/impl/UserServiceImpl.java

@@ -373,4 +373,41 @@ public class UserServiceImpl implements UserService {
 		}
 		}
 	}
 	}
 
 
+	@Override
+	public String sendCheckCode(String newEmail) {
+		Map<String, Object> model = new HashMap<String, Object>();
+		model.put("userName", SystemSession.getUser().getUserName());
+		model.put("adminName", SystemSession.getUser().getUserName());
+		SimpleDateFormat timeFormat = new SimpleDateFormat("MM月dd日 HH:mm:ss");
+		model.put("dateTime", timeFormat.format(new Date()));
+		model.put("userTel", SystemSession.getUser().getUserTel());
+		String checkCode = String.valueOf((int)((Math.random()*9+1)*100000));
+		if(newEmail!=null && !newEmail.equals("")){
+			mailService.send("您的验证码是"+checkCode,newEmail,model);
+			return checkCode;
+		}
+		return null;
+	}
+
+	@Override
+	public User updateUserEmail(User user, String userEmail, String newUserEmail) {
+		boolean result = user.getUserEmail().equals(userEmail);
+		if (result) {
+			User user1 = userDao.findOne(user.getUserUU());
+			user1.setUserPwd(newUserEmail);
+			if (user1.getEnterprise() == null)
+				user1.setCurrentEnterprise();// 随便绑定一个用户所属企业
+			Enterprise enterprise = user1.getEnterprise();
+			try {
+				//判断是否为个人账户
+				//user1 = userDao.save(user1);
+				//修改用户信息
+			} catch (Exception e) {
+				throw new SystemException(e.getMessage());
+			}
+			return user1;
+		} else {
+			throw new IllegalOperatorException("原邮箱地址错误");
+		}
+	}
 }
 }

+ 12 - 0
src/main/webapp/resources/js/common/query/user.js

@@ -75,6 +75,18 @@ define([ 'angular', 'ui-bootstrap', 'ngResource' ], function(angular) {
 			updatePassword: {
 			updatePassword: {
 				url: 'basic/user/updatePassword',
 				url: 'basic/user/updatePassword',
 				method: 'POST'
 				method: 'POST'
+			},
+            checkUserEmail: {
+                url: 'basic/user/checkUserEmail',
+                method: 'GET'
+            },
+            sendCheckCode:{
+                url: 'basic/user/sendCheckCode',
+                method: 'GET'
+            },
+            emailEnable:{
+                url: 'basic/user/emailEnable',
+                method: 'GET'
 			}
 			}
 		});
 		});
 	}]);
 	}]);

+ 101 - 0
src/main/webapp/resources/js/usercenter/controllers/forstore/account_manager_ctrl.js

@@ -415,6 +415,21 @@ define(['app/app'], function(app) {
 			}, function(){
 			}, function(){
 			});
 			});
 		};
 		};
+
+        $scope.updateUserEmail = function(){
+            var modalInstance = $modal.open({
+                animation: true,
+                templateUrl: $rootScope.rootPath + '/static/view/vendor/modal/updateUserEmail.html',
+                controller: 'UserEmailCtrl',
+                resolve: {
+                    user: function(){return angular.copy($rootScope.userInfo);}
+                }
+            });
+
+            modalInstance.result.then(function(){
+            }, function(){
+            });
+        };
 	}]);
 	}]);
 
 
 	// 修改密码Controller
 	// 修改密码Controller
@@ -466,4 +481,90 @@ define(['app/app'], function(app) {
 			$modalInstance.close();
 			$modalInstance.close();
 		};
 		};
 	}]);
 	}]);
+
+    // 修改密码Controller
+    app.register.controller('UserEmailCtrl', ['$scope', '$modalInstance', 'user', 'User', 'toaster', function($scope, $modalInstance, user, User, toaster){
+        $scope.user = user;
+        $scope.checking = false;
+        //验证用户输入的邮箱地址是否正确
+        $scope.checkUserEmail = function(userEmail) {
+            $scope.checking = true;
+            $scope.checkSuccess = false;
+            $scope.checkFailed = false;
+            User.checkUserEmail({userEmail: userEmail}, function(){
+                $scope.checkSuccess = true;
+                $scope.checking = false;
+                $scope.checkFailed = false;
+            }, function(){
+                $scope.checkFailed = true;
+                $scope.checking = false;
+                $scope.checkSuccess = false;
+            });
+        };
+
+        //验证邮箱是否可用
+        $scope.checkUserEmail = function(userEmail) {
+            $scope.checking = true;
+            $scope.checkSuccess = false;
+            $scope.checkFailed = false;
+            User.checkUserEmail({userEmail: userEmail}, function(){
+                $scope.checkSuccess = true;
+                $scope.checking = false;
+                $scope.checkFailed = false;
+            }, function(){
+                $scope.checkFailed = true;
+                $scope.checking = false;
+                $scope.checkSuccess = false;
+            });
+        };
+
+        $scope.emailEnable = function(newUserEmail) {
+            $scope.emailSuccess = false;
+            $scope.emailFailed = false;
+            User.checkUserEmail({userEmail: newUserEmail}, function(){
+                $scope.emailSuccess = true;
+                $scope.emailFailed = false;
+            }, function(){
+                $scope.emailFailed = true;
+                $scope.emailSuccess = false;
+            });
+        };
+
+        $scope.sendCheckCode = function(newUserEmail) {
+            User.sendCheckCode({newUserEmail: newUserEmail}, function(){
+
+            }, function(){
+
+            });
+        };
+
+        //修改密码
+        $scope.ok = function () {
+            if($scope.user.newPassword == $scope.user.password){
+                toaster.pop('error', '错误', '新密码与原密码相同');
+                return;
+            }
+            if($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
+                User.updatePassword({password: $scope.user.password, newPassword: $scope.user.newPassword}, {}, function(){
+                    toaster.pop('success', '成功', '修改密码成功,请牢记您的新密码。');
+                    $scope.user.password = null;
+                    $scope.user.newPassword = null;
+                    $scope.user.newPassword1 = null;
+                    $scope.checking = false;
+                    $scope.checkSuccess = false;
+                    $scope.checkFailed = false;
+                    $modalInstance.close();
+                }, function(response){
+                    toaster.pop('error', '错误', response.data);
+                    $modalInstance.close();
+                });
+            } else {
+                toaster.pop('error', '错误', '重复密码不一致');
+            }
+        };
+
+        $scope.cancel = function () {
+            $modalInstance.close();
+        };
+    }]);
 });
 });

+ 8 - 0
src/main/webapp/resources/view/usercenter/forstore/account_manager.html

@@ -139,6 +139,14 @@
 				</span>
 				</span>
 				<a ng-click="updatePassword()">修改</a>
 				<a ng-click="updatePassword()">修改</a>
 			</li>
 			</li>
+			<li>
+				<span>
+					<h5><img src="static/img/user/images/ok.png"/><p>已完成</p></h5>
+					<font>邮箱认证</font>
+					<span class="gray">您当前的邮箱:529010777@qq.com</span>
+				</span>
+				<a ng-click="updateUserEmail()">修改</a>
+			</li>
 			<li>
 			<li>
 				<span>
 				<span>
 					<h5><img src="static/img/user/images/ok.png"/><p>已完成</p></h5>
 					<h5><img src="static/img/user/images/ok.png"/><p>已完成</p></h5>