Browse Source

账户管理-支付密码

liusw 8 years ago
parent
commit
59f4f386fa

+ 63 - 0
src/main/java/com/uas/platform/b2c/common/account/controller/UserController.java

@@ -365,6 +365,69 @@ public class UserController {
 			throw new IllegalOperatorException("新手机号不能为空");
 	}
 
+	/**
+	 * 验证是否设置支付密码
+	 * @return
+	 */
+	@RequestMapping(value = "/checkHaveUserPay", method = RequestMethod.GET)
+	public ResponseEntity<Boolean> checkHaveUserPay() {
+		User sysUser = SystemSession.getUser();
+		User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
+		HttpHeaders headers = new HttpHeaders();
+		headers.add("Content-Type", "application/text; charset=utf-8");
+		if (!StringUtils.isEmpty(user.getUserPay())) {
+			assert logger != null;
+			logger.log("用户信息", "是否设置支付密码,UU:" + user.getUserUU());
+			return new ResponseEntity<>(true,headers,HttpStatus.OK);
+		}
+		return new ResponseEntity<>(false,headers,HttpStatus.OK);
+	}
+
+	/**
+	 * 验证用户支付密码
+	 * @param userPay 用户输入的支付密码
+	 * @return
+	 */
+	@RequestMapping(value = "/checkUserPay", method = RequestMethod.GET)
+	public ResponseEntity<String> checkUserPay(String userPay) {
+		User sysUser = SystemSession.getUser();
+		User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
+		if (!StringUtils.isEmpty(userPay)) {
+			boolean result = user.getUserPay().equals(Md5Utils.encode(userPay, user.getUserUU()));
+			if (result) {
+				return new ResponseEntity<>(HttpStatus.OK);
+			}
+			assert logger != null;
+			logger.log("用户信息", "验证用户支付密码,UU:" + user.getUserUU());
+		}
+		return new ResponseEntity<>(HttpStatus.EXPECTATION_FAILED);
+	}
+
+	/**
+	 * 修改用户支付密码
+	 * @param session
+	 * @param userPay
+	 * @param newUserPay
+	 * @return
+	 */
+	@RequestMapping(value = "/updateUserPay", method = RequestMethod.POST)
+	public ResponseEntity<String> updateUserPay(HttpSession session, String userPay, String newUserPay) {
+		if (userPay!=null && userPay.equals(newUserPay)){
+			throw new IllegalOperatorException("新密码与旧密码相同");
+		}
+		User sysUser = SystemSession.getUser();
+		User user = userService.findUserPwdByUserUU(sysUser.getUserUU());
+		if (!StringUtils.isEmpty(newUserPay)) {
+			user = userService.updateUserPay(user,userPay,newUserPay);
+			session.setAttribute("user", user);
+			SystemSession.setUser(user);
+			assert logger != null;
+			logger.log("用户信息", "修改用户支付密码,UU:" + user.getUserUU());
+			return new ResponseEntity<>(HttpStatus.OK);
+		} else
+			throw new IllegalOperatorException("新密码不能为空");
+	}
+
 	/**
 	 * 根据UU获取该企业所有人员信息
 	 * @param enuu 企业uu号

+ 14 - 0
src/main/java/com/uas/platform/b2c/common/account/model/User.java

@@ -115,6 +115,12 @@ public class User implements Serializable {
 	@Column(name = "user_type", length = 20)
 	private String userType;
 
+	/**
+	 * 支付密码
+	 */
+	@Column(name = "user_pay", length = 32)
+	private String userPay;
+
 	/**
 	 * 所属所有公司
 	 */
@@ -257,6 +263,14 @@ public class User implements Serializable {
 		this.userIdcode = userIdcode;
 	}
 
+	public String getUserPay() {
+		return userPay;
+	}
+
+	public void setUserPay(String userPay) {
+		this.userPay = userPay;
+	}
+
 	@JsonIgnore
 	@JSONField(serialize = false)
 	public Set<Enterprise> getEnterprises() {

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

@@ -103,4 +103,13 @@ public interface UserService {
 	public void removeUser(Long uu);
 	public boolean isEmailUseable(String email);
 	public boolean isTelUseable(String tel);
+
+	/**
+	 * 修改用户支付密码
+	 * @param user
+	 * @param userPay
+	 * @param newUserPay
+	 * @return
+	 */
+	User updateUserPay(User user, String userPay, String newUserPay);
 }

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

@@ -375,4 +375,26 @@ public class UserServiceImpl implements UserService {
 			throw new IllegalArgumentException();
 		}
 	}
+
+	@Override
+	public User updateUserPay(User user, String userPay, String newUserPay) {
+		boolean result =false;
+		User user1 = userDao.findOne(user.getUserUU());
+		//未设置则不需要验证密码
+		if(user1.getUserPay()!=null){
+			result = user.getUserPay().equals(Md5Utils.encode(userPay, user.getUserUU()));
+		}
+		//未设置和验证成功
+		if (user1.getUserPay()==null || result) {
+			user1.setUserPay(Md5Utils.encode(newUserPay, user1.getUserUU()));
+			try {
+				userDao.save(user1);
+			} catch (Exception e) {
+				throw new SystemException(e.getMessage());
+			}
+			return user1;
+		} else {
+			throw new IllegalOperatorException("原密码验证错误");
+		}
+	}
 }

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

@@ -115,6 +115,22 @@ define([ 'angular', 'ui-bootstrap', 'ngResource' ], function(angular) {
             validTelCheckCode:{
                 url: 'basic/user/validTelCheckCode',
                 method: 'GET'
+			},
+            updateUserTel:{
+                url: 'basic/user/updateUserTel',
+                method: 'POST'
+            },
+            checkHaveUserPay:{
+                url: 'basic/user/checkHaveUserPay',
+                method: 'GET'
+			},
+            checkUserPay:{
+                url: 'basic/user/checkUserPay',
+                method: 'GET'
+			},
+            updateUserPay:{
+                url: 'basic/user/updateUserPay',
+                method: 'POST'
 			}
 		});
 	}]);

+ 121 - 2
src/main/webapp/resources/js/usercenter/controllers/forstore/account_manager_ctrl.js

@@ -445,6 +445,21 @@ define(['app/app'], function(app) {
             }, function(){
             });
         };
+
+        $scope.updateUserPay = function(){
+            var modalInstance = $modal.open({
+                animation: true,
+                templateUrl: $rootScope.rootPath + '/static/view/vendor/modal/updateUserPay.html',
+                controller: 'UserPayCtrl',
+                resolve: {
+                    user: function(){return angular.copy($rootScope.userInfo);}
+                }
+            });
+
+            modalInstance.result.then(function(){
+            }, function(){
+            });
+        };
 	}]);
 
 	// 修改密码Controller
@@ -705,8 +720,8 @@ define(['app/app'], function(app) {
                 toaster.pop('error', '错误', '新手机号与旧手机号相同');
                 return;
             }
-            User.updateUserTel({newUserTel:$scope.user.newUserTel,userTel:$scope.userTel.userTel}, {}, function(){
-                toaster.pop('success', '成功', '修改邮箱成功。');
+            User.updateUserTel({newUserTel:$scope.user.newUserTel,userTel:$scope.user.userTel}, {}, function(){
+                toaster.pop('success', '成功', '手机验证成功。');
                 $scope.user.userTel = null;
                 $scope.user.newUserTel = null;
                 $scope.checking = false;
@@ -729,4 +744,108 @@ define(['app/app'], function(app) {
             $modalInstance.close();
         };
     }]);
+
+    // 设置支付密码Controller
+    app.register.controller('UserPayCtrl', ['$scope', '$modalInstance', 'user', 'User', 'toaster', function($scope, $modalInstance, user, User, toaster){
+    	//原密码框是否显示
+    	$scope.checking = true;
+    	//验证是否设置密码
+		$scope.checkHaveUserPay=function(){
+            $scope.userPayHidden = false;
+            $scope.isNewSuccess = false;
+            $scope.isNewFailed = true;
+			User.checkHaveUserPay(function(data){
+				var flag = data.data;
+				if(flag == "false"){
+					//隐藏原密码输入框
+                    angular.element(".oldUserPay").remove();
+					//修改新密码框内容
+					$scope.newUserPayLabel = "密码";
+                    $scope.isNewSuccess = true;
+                    $scope.isNewFailed = false;
+                    $scope.checking = false;
+				}
+			});
+		}
+
+		//校验原密码是否正确
+		$scope.checkUserPay = function (userPay) {
+			if(userPay!=null){
+				$scope.checkSuccess = false;
+				$scope.checkFailed = false;
+				User.checkUserPay({userPay:userPay},function(){
+					$scope.checkFailed = false;
+					$scope.checkSuccess = true;
+				},function(){
+					$scope.checkFailed = true;
+					$scope.checkSuccess = false;
+				});
+            }
+		}
+
+		//输入新密码,进行校验
+        $scope.checkSuccess1 = false;
+        $scope.checkFailed1 = false;
+		$scope.checkNewUserPay = function(newUserPay) {
+			if(newUserPay!=null){
+				//如果两者相同 则返回
+				if ($scope.checking  && ($scope.user.userPay == $scope.user.newUserPay)) {
+					toaster.pop('error', '错误', '新密码与原密码相同');
+					$scope.checkFailed1 = true;
+					$scope.checkSuccess1 = false;
+					return;
+				}
+				//正则校验
+				var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/;
+				if(!reg.test(newUserPay)){
+					$scope.checkFailed1 = true;
+					$scope.checkSuccess1 = false;
+					return;
+				}
+				$scope.checkFailed1 = false;
+				$scope.checkSuccess1 = true;
+            }
+        }
+
+        //校验确认密码是否与新密码相同
+        $scope.checkSuccess2 = false;
+        $scope.checkFailed2 = false;
+		$scope.checkNewUserPay1 = function(){
+			if($scope.checkSuccess1==true && ($scope.user.newUserPay == $scope.user.newUserPay1)){
+                $scope.checkSuccess2 = true;
+                $scope.checkFailed2 = false;
+                return;
+			}
+            $scope.checkSuccess2 = false;
+            $scope.checkFailed2 = true;
+		}
+
+        //支付密码
+        $scope.ok = function () {
+            if($scope.checking && ($scope.user.newUserPay == $scope.user.userPay)){
+                toaster.pop('error', '错误', '新密码与旧密码相同');
+                return;
+            }
+            User.updateUserPay({newUserPay:$scope.user.newUserPay,userPay:$scope.user.userPay}, {}, function(){
+                toaster.pop('success', '成功', '支付密码设置成功。');
+                $scope.user.userPay = null;
+                $scope.user.newUserPay = null;
+                $scope.checkSuccess = false;
+                $scope.checkFailed = false;
+                $scope.checkSuccess1 = false;
+                $scope.checkFailed1 = false;
+                $scope.checkSuccess2 = false;
+                $scope.checkFailed2 = false;
+                $scope.checking = true;
+                $modalInstance.close();
+            }, function(response){
+                toaster.pop('error', '错误', response.data);
+                $modalInstance.close();
+            });
+        };
+
+        $scope.cancel = function () {
+            $modalInstance.close();
+        };
+    }]);
 });

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

@@ -163,6 +163,14 @@
 				</span>
 				<a ng-click="updateUserTel()">修改</a>
 			</li>
+			<li>
+				<span>
+					<h5><img src="static/img/user/images/ok.png"/><p>已完成</p></h5>
+					<font>支付密码</font>
+					<span class="gray">在使用账户中余额或确认收货时,需输入支付密码。</span>
+				</span>
+				<a ng-click="updateUserPay()">立即设置</a>
+			</li>
 		</ul>
 	</div>
 

+ 1 - 1
src/main/webapp/resources/view/vendor/modal/updatePassword.html

@@ -25,7 +25,7 @@
 		<div class="row">
 			<label class="col-md-4 col-sm-4 col text-right">新密码:</label>
 			<div class="col-md-4 col-sm-4 col">
-				<input ng-model="user.newPassword" ng-pattern="/^([\w~!@#$%^&\*\(\)-_\+=,.;\[\]{}\<\>]){6,20}$/" class="form-control input-sm" type="password" required  placeholder="6~20位字母、数字、符号">
+				<input ng-model="user.newPassword" ng-pattern="/^([\w~!@#$%^&\*\(\)-_\+=,.;\[\]{}\<\>]){8,20}$/" class="form-control input-sm" type="password" required  placeholder="8~20位字母、数字、符号">
 				<!-- <div>密码复杂度</div> -->
 			</div>
 			<div class="col-md-4 col-sm-4 col">

+ 51 - 0
src/main/webapp/resources/view/vendor/modal/updateUserPay.html

@@ -0,0 +1,51 @@
+<style>
+    .userPay .modal-body .row {
+        line-height: 34px;
+        font-size: 14px;
+    }
+</style>
+<div class="modal-header">
+    <h3 class="f14 modal-title"><i class="fa fa-lock fa-fw"></i>支付密码</h3>
+</div>
+<form class="userPay" name="sampleSendForm" ng-submit="ok()" ng-init="checkHaveUserPay()">
+    <div class="modal-body">
+        <div class="row line oldUserPay">
+            <label class="col-md-4 col-sm-4 col text-right">原密码:</label>
+            <div class="col-md-4 col-sm-4 col"><input ng-model="user.userPay" class="form-control input-sm"
+                                                      type="password" name="userPay" ng-blur="checkUserPay(user.userPay)" required
+                                                      ></div>
+            <div class="col-md-4 col-sm-4 col">
+                <i ng-show="checkSuccess" class="fa fa-check" style="color:#339933"></i>
+                <i ng-show="checkFailed" class="fa fa-close" style="color:#CC3333;"></i>
+            </div>
+        </div>
+        <div class="row">
+            <label class="col-md-4 col-sm-4 col text-right" ng-hide="!isNewFailed">新密码:</label>
+            <label class="col-md-4 col-sm-4 col text-right" ng-hide="!isNewSuccess">密码:</label>
+            <div class="col-md-4 col-sm-4 col">
+                <input ng-model="user.newUserPay"
+                       class="form-control input-sm" type="password" name="newUserPay" ng-keyup="checkNewUserPay(user.newUserPay)" required>
+                <!-- <div>密码复杂度</div> -->
+            </div>
+            <div class="col-md-4 col-sm-4 col">
+                <i ng-show="checkSuccess1" class="fa fa-check" style="color:#339933"></i>
+                <i ng-show="checkFailed1" class="fa fa-close" style="color:#CC3333;"></i>
+            </div>
+        </div>
+        <div class="row">
+            <label class="col-md-4 col-sm-4 col text-right">确认密码:</label>
+            <div class="col-md-4 col-sm-4 col">
+                <input ng-model="user.newUserPay1"
+                       class="form-control input-sm" name="newUserPay1"  type="password" ng-keyup="checkNewUserPay1()" required>
+            </div>
+            <div class="col-md-4 col-sm-4 col">
+                <i ng-show="checkSuccess2" class="fa fa-check" style="color:#339933"></i>
+                <i ng-show="checkFailed2" class="fa fa-close" style="color:#CC3333;"></i>
+            </div>
+        </div>
+    </div>
+    <div class="modal-footer">
+        <button class="btn btn-primary" ng-disabled="(!checkSuccess && !checkSuccess1 && !checkSuccess2)" type="submit">确认修改</button>
+        <button class="btn btn-default" ng-click="cancel()" type="button">取消</button>
+    </div>
+</form>

+ 2 - 2
src/main/webapp/resources/view/vendor/modal/updateUserTel.html

@@ -13,7 +13,7 @@
         <div class="row line" ng-class="{'has-success': checkSuccess, 'has-error': checkFailed}">
             <label class="col-md-4 col-sm-4 col text-right">原手机号:</label>
             <div class="col-md-4 col-sm-4 col"><input ng-model="user.userTel" class="form-control input-sm"
-                                                      type="userTel" ng-init="user.userTel=18665845725" ng-blur="checkUserTel(user.userTel)" required
+                                                      type="userTel"  ng-blur="checkUserTel(user.userTel)" required
                                                       ></div>
             <div class="col-md-4 col-sm-4 col">
                 <span ng-show="checking">验证手机号...</span>
@@ -25,7 +25,7 @@
             <label class="col-md-4 col-sm-4 col text-right">新手机号:</label>
             <div class="col-md-4 col-sm-4 col">
                 <input ng-model="user.newUserTel"
-                       class="form-control input-sm" ng-init="user.newUserTel=13828830127" type="newUserTel" required ng-blur="telEnable(user.newUserTel)">
+                       class="form-control input-sm" type="newUserTel" required ng-blur="telEnable(user.newUserTel)">
                 <!-- <div>密码复杂度</div> -->
             </div>
             <div class="col-md-4 col-sm-4 col">