registerCtrl.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. angular.module('push')
  2. .controller('RegisterCtrl', function ($scope, ConfigService, $ionicPopup, RegisterService, UtilService, UserService, $timeout, SqliteStorageService, ConstantService, CommonService) {
  3. //TODO
  4. if ($scope.app) {
  5. $scope.setStatusBar(0);
  6. }
  7. $scope.defaultLan = UserService.defaultLan;
  8. $scope.titleLogo = 'img/wel_push.png';
  9. if ($scope.isLiyangApp) {
  10. $scope.titleLogo = 'img/wel_liyang.png';
  11. }
  12. $scope.user = {
  13. name: '',
  14. password: '',
  15. repeat_password: ''
  16. };
  17. $scope.show_psd = false;
  18. $scope.show_psd1 = false;
  19. $scope.showPassword = function () {
  20. $scope.show_psd = !$scope.show_psd;
  21. //$scope.show_psd = false;
  22. };
  23. $scope.showPassword1 = function () {
  24. $scope.show_psd1 = !$scope.show_psd1;
  25. //$scope.show_psd1 = false;
  26. };
  27. $scope.readCommit = false;
  28. $scope.readCommition = function () {
  29. $scope.readCommit = !$scope.readCommit;
  30. }
  31. $scope.isIncludeSChar = function (strData) {
  32. if (strData == "") {
  33. return false;
  34. }
  35. // 全部特殊字符
  36. var reg = new RegExp("[`~!@#$^&*%()_+=|{}':;',\\-\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  37. return reg.test(strData);
  38. }
  39. $scope.isIncludeNumber = function (strData) {
  40. if (!strData) {
  41. return false;
  42. }
  43. var reg = /[0-9]/;
  44. if (!reg.test(strData)) {
  45. return false;
  46. }
  47. return true;
  48. }
  49. $scope.isIncludeLiter = function (strData) {
  50. if (!strData) {
  51. return false;
  52. }
  53. var reg = /[a-z]/i;
  54. if (!reg.test(strData)) {
  55. return false;
  56. }
  57. return true;
  58. }
  59. $scope.GetStrLen = function (strData) {
  60. if (!strData) {
  61. return 0;
  62. }
  63. var length = 0;
  64. for (var i = 0; i < strData.length; i++) {
  65. var char = strData.charCodeAt(i);
  66. //单字节加1
  67. if ((char >= 0x0001 && char <= 0x007e) || (0xff60 <= char && char <= 0xff9f)) {
  68. length++;
  69. }
  70. else {
  71. length += 2;
  72. }
  73. }
  74. return length;
  75. }
  76. /**
  77. * 密码注册
  78. */
  79. $scope.register = function () {
  80. /**
  81. * 起码强度(强中弱)判断
  82. */
  83. if(UserService.node == 320481000) {
  84. var len = $scope.GetStrLen($scope.user.password); // 获取字符串长度
  85. // 条件1 判断
  86. $scope.newPswdValidOne = (len >= 8 && len <= 20);
  87. // 条件2 判断
  88. $scope.newPswdValidTwo = $scope.isIncludeSChar($scope.user.password);
  89. // 包含字母
  90. $scope.newPswdHasLiter = $scope.isIncludeLiter($scope.user.password);
  91. // 包含数字
  92. $scope.newPswdHasNumber = $scope.isIncludeNumber($scope.user.password);
  93. // 条件3 判断
  94. $scope.newPswdValidThree = ($scope.newPswdHasNumber && $scope.newPswdHasLiter) || // 数字和字母
  95. ($scope.newPswdHasNumber && $scope.newPswdValidTwo) || // 数字和特殊字符
  96. ($scope.newPswdHasLiter && $scope.newPswdValidTwo); // 数字、字母和特殊字符
  97. // 密码等级判断
  98. // 3.密码中包含数字、字母和多个特殊字符时,密码强度强
  99. if ($scope.newPswdValidOne && $scope.newPswdHasNumber && $scope.newPswdHasLiter && $scope.newPswdValidTwo) {
  100. $scope.newPswdRank = 3;
  101. $scope.newPswdRankText = "强";
  102. $ionicPopup.alert({
  103. title: '提示',
  104. template: '密码强度强,欢迎注册!'
  105. })
  106. }
  107. // 2.密码中包含数字、字母和任一特殊字符时,密码强度中;
  108. else if ($scope.newPswdValidOne && $scope.newPswdValidThree ) {
  109. $scope.newPswdRank = 2;
  110. $scope.newPswdRankText = "中";
  111. $ionicPopup.alert({
  112. title: '提示',
  113. template: '密码强度中,必须包含数字、字母和特殊字符,请重新输入密码!'
  114. })
  115. return;
  116. }
  117. // 1.密码中仅包含数字、字母时,密码强度弱;
  118. else {
  119. $scope.newPswdRank = 1;
  120. $scope.newPswdRankText = "弱";
  121. $ionicPopup.alert({
  122. title: '提示',
  123. template: '密码强度弱,必须包含数字、字母和特殊字符,且至少输入8位密码,请重新输入密码!'
  124. })
  125. return;
  126. }
  127. }
  128. // if ($scope.readCommit == false) {
  129. // if ($scope.app) {
  130. // UtilService.showMess("您尚未接受《平台注册协议》,请勾选后再注册!");
  131. // return;
  132. // } else {
  133. // CommonService.showMessage('您尚未接受《平台注册协议》,请勾选后再注册!', $scope);
  134. // return;
  135. // }
  136. // }
  137. // if(!UtilService.isDefined($scope.user.name)){
  138. // UtilService.showMess("手机号不能为空");
  139. // return;
  140. // }
  141. // if(!(/^1[3|4|5|7|8|][0-9]{9}$/.test($scope.user.name))){
  142. // UtilService.showMess("手机号不正确");
  143. // return;
  144. // }
  145. // if(!UtilService.isDefined($scope.user.password)){
  146. // UtilService.showMess("密码请填写完整");
  147. // return;
  148. // }
  149. // if(!UtilService.isDefined($scope.user.repeat_password)){
  150. // UtilService.showMess("确认密码请填写完整");
  151. // return;
  152. // }
  153. // if($scope.user.password !=$scope.user.repeat_password){
  154. // UtilService.showMess("密码和确认密码不一致");
  155. // return;
  156. // }
  157. $scope.showLoadingToast();
  158. $scope.register_finish = 'colorName';
  159. $scope.inputuser = {
  160. mobile: $scope.user.name,
  161. password: $scope.user.password,
  162. comefrom: ConfigService.comefrom
  163. };
  164. console.log( $scope.inputuser)
  165. RegisterService.register($scope.inputuser).then(function (response) {
  166. $scope.hideLoadingToast();
  167. if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  168. if ($scope.app) {
  169. if ($scope.defaultLan == 'Chinese') {
  170. UtilService.showMess("注册成功");
  171. } else {
  172. UtilService.showMess("login successfully");
  173. }
  174. } else {
  175. if ($scope.defaultLan == 'Chinese') {
  176. CommonService.showMessage('注册成功', $scope);
  177. } else {
  178. CommonService.showMessage('login successfully', $scope);
  179. }
  180. }
  181. //存储用户信息--自动登录
  182. //用户手机号作为用户的唯一的表示,用作全局变量
  183. localStorage.setItem("mobile", $scope.user.name);
  184. //存储密码用作自动登录
  185. localStorage.setItem("password", $scope.user.password);
  186. /*var tempdate = UtilService.formatDate();
  187. SqliteStorageService.insertSingleData("userinfo",{mobile:$scope.user.name,password:$scope.user.password,updatetime:tempdate.formattime2});*/
  188. //注册成功后把userId放内存里面
  189. UserService.id = response.data;
  190. //注册成功跳转到设置昵称界面
  191. $timeout(function () {
  192. $scope.go('setname', {
  193. 'userid': UserService.id,
  194. 'userpwd': $scope.user.password,
  195. 'username': $scope.user.name
  196. });
  197. }, 50);
  198. } else if (response.code == ConstantService.STATUS_TYPE_21007) {
  199. if ($scope.app) {
  200. if ($scope.defaultLan == 'Chinese') {
  201. UtilService.showMess("该手机号码已注册");
  202. } else {
  203. UtilService.showMess("already registered");
  204. }
  205. } else {
  206. if ($scope.defaultLan == 'Chinese') {
  207. CommonService.showMessage('该手机号码已注册', $scope);
  208. } else {
  209. CommonService.showMessage('already registered', $scope);
  210. }
  211. }
  212. }
  213. }, function () {
  214. $scope.hideLoadingToast();
  215. if ($scope.app) {
  216. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  217. } else {
  218. CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR, $scope)
  219. }
  220. });
  221. }
  222. });