angular.module('push') .controller('RegisterCtrl', function ($scope, ConfigService, $ionicPopup, RegisterService, UtilService, UserService, $timeout, SqliteStorageService, ConstantService, CommonService) { //TODO if ($scope.app) { $scope.setStatusBar(0); } $scope.defaultLan = UserService.defaultLan; $scope.titleLogo = 'img/wel_push.png'; if ($scope.isLiyangApp) { $scope.titleLogo = 'img/wel_liyang.png'; } $scope.user = { name: '', password: '', repeat_password: '' }; $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.readCommit = false; $scope.readCommition = function () { $scope.readCommit = !$scope.readCommit; } $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.register = 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; } } // if ($scope.readCommit == false) { // if ($scope.app) { // UtilService.showMess("您尚未接受《平台注册协议》,请勾选后再注册!"); // return; // } else { // CommonService.showMessage('您尚未接受《平台注册协议》,请勾选后再注册!', $scope); // return; // } // } // if(!UtilService.isDefined($scope.user.name)){ // UtilService.showMess("手机号不能为空"); // return; // } // if(!(/^1[3|4|5|7|8|][0-9]{9}$/.test($scope.user.name))){ // UtilService.showMess("手机号不正确"); // return; // } // if(!UtilService.isDefined($scope.user.password)){ // UtilService.showMess("密码请填写完整"); // return; // } // if(!UtilService.isDefined($scope.user.repeat_password)){ // UtilService.showMess("确认密码请填写完整"); // return; // } // if($scope.user.password !=$scope.user.repeat_password){ // UtilService.showMess("密码和确认密码不一致"); // return; // } $scope.showLoadingToast(); $scope.register_finish = 'colorName'; $scope.inputuser = { mobile: $scope.user.name, password: $scope.user.password, comefrom: ConfigService.comefrom }; console.log( $scope.inputuser) RegisterService.register($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("login successfully"); } } else { if ($scope.defaultLan == 'Chinese') { CommonService.showMessage('注册成功', $scope); } else { CommonService.showMessage('login successfully', $scope); } } //存储用户信息--自动登录 //用户手机号作为用户的唯一的表示,用作全局变量 localStorage.setItem("mobile", $scope.user.name); //存储密码用作自动登录 localStorage.setItem("password", $scope.user.password); /*var tempdate = UtilService.formatDate(); SqliteStorageService.insertSingleData("userinfo",{mobile:$scope.user.name,password:$scope.user.password,updatetime:tempdate.formattime2});*/ //注册成功后把userId放内存里面 UserService.id = response.data; //注册成功跳转到设置昵称界面 $timeout(function () { $scope.go('setname', { 'userid': UserService.id, 'userpwd': $scope.user.password, 'username': $scope.user.name }); }, 50); } else if (response.code == ConstantService.STATUS_TYPE_21007) { if ($scope.app) { if ($scope.defaultLan == 'Chinese') { UtilService.showMess("该手机号码已注册"); } else { UtilService.showMess("already registered"); } } else { if ($scope.defaultLan == 'Chinese') { CommonService.showMessage('该手机号码已注册', $scope); } else { CommonService.showMessage('already registered', $scope); } } } }, function () { $scope.hideLoadingToast(); if ($scope.app) { UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); } else { CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR, $scope) } }); } });