angular.module('push') .controller('FortPasdCtrl', function ($scope, ConfigService, $ionicPopup, RegisterService, UtilService, UserService, $timeout, SqliteStorageService, ConstantService, CommonService) { //TODO if ($scope.app) { $scope.setStatusBar(0); } $scope.defaultLan = UserService.defaultLan; $scope.loginLogo = 'img/push_login.png'; if ($scope.isLiyangApp) { $scope.loginLogo = 'img/liyang_login.jpg'; } $scope.user = { name: '', captcha:'', password: '', repeat_password: '' }; $scope.ifcta="" $scope.show_psd = false; $scope.show_psd1 = false; $scope.showPassword = function () { $scope.show_psd = !$scope.show_psd; //$scope.show_psd = false; }; $scope.showPassword1 = function () { $scope.show_psd1 = !$scope.show_psd1; //$scope.show_psd1 = false; }; $scope.isIncludeSChar = function (strData) { if (strData == "") { return false; } // 全部特殊字符 var reg = new RegExp("[`~!@#$^&*%()_+=|{}':;',\\-\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]") return reg.test(strData); } $scope.isIncludeNumber = function (strData) { if (!strData) { return false; } var reg = /[0-9]/; if (!reg.test(strData)) { return false; } return true; } $scope.isIncludeLiter = function (strData) { if (!strData) { return false; } var reg = /[a-z]/i; if (!reg.test(strData)) { return false; } return true; } $scope.GetStrLen = function (strData) { if (!strData) { return 0; } var length = 0; for (var i = 0; i < strData.length; i++) { var char = strData.charCodeAt(i); //单字节加1 if ((char >= 0x0001 && char <= 0x007e) || (0xff60 <= char && char <= 0xff9f)) { length++; } else { length += 2; } } return length; } //获取验证码 $scope.time=60 $scope.captcha=function(){ var myVa=setInterval(function(){ if($scope.time==0){ clearInterval(myVa) $scope.$apply(function () { $scope.time=60 }); }else { $scope.$apply(function () { $scope.time-- }); } },1000); var params={ node:localStorage.node, mobile:$scope.user.name } RegisterService.getcaptcha(params).then(function (res) { if(res.code==3350){ if ($scope.app) { if ($scope.defaultLan == 'Chinese') { UtilService.showMess("验证码已发送"); } else { UtilService.showMess("Verification code sent"); } } else { if ($scope.defaultLan == 'Chinese') { CommonService.showMessage('验证码已发送', $scope); } else { CommonService.showMessage('Verification code sent', $scope); } } }else if(res.code==3352){ // clearInterval(myVa) // $scope.time=60 if ($scope.app) { if ($scope.defaultLan == 'Chinese') { UtilService.showMess(" 短信验证码已发送至您的手机,有效时长10分钟,请勿重复获取。"); } else { UtilService.showMess("SMS verification code has been sent to your mobile phone, valid for 10 minutes, please do not get it again."); } } else { if ($scope.defaultLan == 'Chinese') { CommonService.showMessage('短信验证码已发送至您的手机,有效时长10分钟,请勿重复获取。', $scope); } else { CommonService.showMessage('SMS verification code has been sent to your mobile phone, valid for 10 minutes, please do not get it again.', $scope); } } } else { clearInterval(myVa) $scope.time=60 if ($scope.app) { if ($scope.defaultLan == 'Chinese') { UtilService.showMess(res.message); } else { UtilService.showMess("error"); } } else { if ($scope.defaultLan == 'Chinese') { CommonService.showMessage(res.message, $scope); } else { CommonService.showMessage('error', $scope); } } } }) } //确认 $scope.confirm = function () { /** * 起码强度(强中弱)判断 */ if(UserService.node == 320481000) { var len = $scope.GetStrLen($scope.user.password); // 获取字符串长度 // 条件1 判断 $scope.newPswdValidOne = (len >= 8 && len <= 20); // 条件2 判断 $scope.newPswdValidTwo = $scope.isIncludeSChar($scope.user.password); // 包含字母 $scope.newPswdHasLiter = $scope.isIncludeLiter($scope.user.password); // 包含数字 $scope.newPswdHasNumber = $scope.isIncludeNumber($scope.user.password); // 条件3 判断 $scope.newPswdValidThree = ($scope.newPswdHasNumber && $scope.newPswdHasLiter) || // 数字和字母 ($scope.newPswdHasNumber && $scope.newPswdValidTwo) || // 数字和特殊字符 ($scope.newPswdHasLiter && $scope.newPswdValidTwo); // 数字、字母和特殊字符 // 密码等级判断 // 3.密码中包含数字、字母和多个特殊字符时,密码强度强 if ($scope.newPswdValidOne && $scope.newPswdHasNumber && $scope.newPswdHasLiter && $scope.newPswdValidTwo) { $scope.newPswdRank = 3; $scope.newPswdRankText = "强"; $ionicPopup.alert({ title: '提示', template: '密码强度强,欢迎注册!' }) } // 2.密码中包含数字、字母和任一特殊字符时,密码强度中; else if ($scope.newPswdValidOne && $scope.newPswdValidThree ) { $scope.newPswdRank = 2; $scope.newPswdRankText = "中"; $ionicPopup.alert({ title: '提示', template: '密码强度中,必须包含数字、字母和特殊字符,请重新输入密码!' }) return; } // 1.密码中仅包含数字、字母时,密码强度弱; else { $scope.newPswdRank = 1; $scope.newPswdRankText = "弱"; $ionicPopup.alert({ title: '提示', template: '密码强度弱,必须包含数字、字母和特殊字符,且至少输入8位密码,请重新输入密码!' }) return; } } $scope.showLoadingToast(); $scope.register_finish = 'colorName'; $scope.inputuser = { node:localStorage.node, smsVerCode: $scope.user.captcha, mobile: $scope.user.name, newPwd: $scope.user.password, }; RegisterService.PwdReset($scope.inputuser).then(function (response) { $scope.hideLoadingToast(); if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) { if ($scope.app) { if ($scope.defaultLan == 'Chinese') { UtilService.showMess("重置成功"); } else { UtilService.showMess("Reset successful"); } } else { if ($scope.defaultLan == 'Chinese') { CommonService.showMessage('重置成功', $scope); } else { CommonService.showMessage('Reset successful', $scope); } } localStorage.setItem("mobile", $scope.user.name); localStorage.setItem("password", $scope.user.password); UserService.id = response.data; $timeout(function () { $scope.go('login'); }, 3000); } else{ if ($scope.app) { if ($scope.defaultLan == 'Chinese') { UtilService.showMess(response.message); } else { UtilService.showMess("error"); } } else { if ($scope.defaultLan == 'Chinese') { CommonService.showMessage(response.message, $scope); } else { CommonService.showMessage('error', $scope); } } } }, function () { $scope.hideLoadingToast(); if ($scope.app) { UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); } else { CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR, $scope) } }); } });