FortPasdCtrl.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. angular.module('push')
  2. .controller('FortPasdCtrl', 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.loginLogo = 'img/push_login.png';
  9. if ($scope.isLiyangApp) {
  10. $scope.loginLogo = 'img/liyang_login.jpg';
  11. }
  12. $scope.user = {
  13. name: '',
  14. captcha:'',
  15. password: '',
  16. repeat_password: ''
  17. };
  18. $scope.ifcta=""
  19. $scope.show_psd = false;
  20. $scope.show_psd1 = false;
  21. $scope.showPassword = function () {
  22. $scope.show_psd = !$scope.show_psd;
  23. //$scope.show_psd = false;
  24. };
  25. $scope.showPassword1 = function () {
  26. $scope.show_psd1 = !$scope.show_psd1;
  27. //$scope.show_psd1 = false;
  28. };
  29. $scope.isIncludeSChar = function (strData) {
  30. if (strData == "") {
  31. return false;
  32. }
  33. // 全部特殊字符
  34. var reg = new RegExp("[`~!@#$^&*%()_+=|{}':;',\\-\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
  35. return reg.test(strData);
  36. }
  37. $scope.isIncludeNumber = function (strData) {
  38. if (!strData) {
  39. return false;
  40. }
  41. var reg = /[0-9]/;
  42. if (!reg.test(strData)) {
  43. return false;
  44. }
  45. return true;
  46. }
  47. $scope.isIncludeLiter = function (strData) {
  48. if (!strData) {
  49. return false;
  50. }
  51. var reg = /[a-z]/i;
  52. if (!reg.test(strData)) {
  53. return false;
  54. }
  55. return true;
  56. }
  57. $scope.GetStrLen = function (strData) {
  58. if (!strData) {
  59. return 0;
  60. }
  61. var length = 0;
  62. for (var i = 0; i < strData.length; i++) {
  63. var char = strData.charCodeAt(i);
  64. //单字节加1
  65. if ((char >= 0x0001 && char <= 0x007e) || (0xff60 <= char && char <= 0xff9f)) {
  66. length++;
  67. }
  68. else {
  69. length += 2;
  70. }
  71. }
  72. return length;
  73. }
  74. //获取验证码
  75. $scope.time=60
  76. $scope.captcha=function(){
  77. var myVa=setInterval(function(){
  78. if($scope.time==0){
  79. clearInterval(myVa)
  80. $scope.$apply(function () {
  81. $scope.time=60
  82. });
  83. }else {
  84. $scope.$apply(function () {
  85. $scope.time--
  86. });
  87. }
  88. },1000);
  89. var params={
  90. node:localStorage.node,
  91. mobile:$scope.user.name
  92. }
  93. RegisterService.getcaptcha(params).then(function (res) {
  94. if(res.code==3350){
  95. if ($scope.app) {
  96. if ($scope.defaultLan == 'Chinese') {
  97. UtilService.showMess("验证码已发送");
  98. } else {
  99. UtilService.showMess("Verification code sent");
  100. }
  101. } else {
  102. if ($scope.defaultLan == 'Chinese') {
  103. CommonService.showMessage('验证码已发送', $scope);
  104. } else {
  105. CommonService.showMessage('Verification code sent', $scope);
  106. }
  107. }
  108. }else if(res.code==3352){
  109. // clearInterval(myVa)
  110. // $scope.time=60
  111. if ($scope.app) {
  112. if ($scope.defaultLan == 'Chinese') {
  113. UtilService.showMess(" 短信验证码已发送至您的手机,有效时长10分钟,请勿重复获取。");
  114. } else {
  115. UtilService.showMess("SMS verification code has been sent to your mobile phone, valid for 10 minutes, please do not get it again.");
  116. }
  117. } else {
  118. if ($scope.defaultLan == 'Chinese') {
  119. CommonService.showMessage('短信验证码已发送至您的手机,有效时长10分钟,请勿重复获取。', $scope);
  120. } else {
  121. CommonService.showMessage('SMS verification code has been sent to your mobile phone, valid for 10 minutes, please do not get it again.', $scope);
  122. }
  123. }
  124. } else {
  125. clearInterval(myVa)
  126. $scope.time=60
  127. if ($scope.app) {
  128. if ($scope.defaultLan == 'Chinese') {
  129. UtilService.showMess(res.message);
  130. } else {
  131. UtilService.showMess("error");
  132. }
  133. } else {
  134. if ($scope.defaultLan == 'Chinese') {
  135. CommonService.showMessage(res.message, $scope);
  136. } else {
  137. CommonService.showMessage('error', $scope);
  138. }
  139. }
  140. }
  141. })
  142. }
  143. //确认
  144. $scope.confirm = function () {
  145. /**
  146. * 起码强度(强中弱)判断
  147. */
  148. if(UserService.node == 320481000) {
  149. var len = $scope.GetStrLen($scope.user.password); // 获取字符串长度
  150. // 条件1 判断
  151. $scope.newPswdValidOne = (len >= 8 && len <= 20);
  152. // 条件2 判断
  153. $scope.newPswdValidTwo = $scope.isIncludeSChar($scope.user.password);
  154. // 包含字母
  155. $scope.newPswdHasLiter = $scope.isIncludeLiter($scope.user.password);
  156. // 包含数字
  157. $scope.newPswdHasNumber = $scope.isIncludeNumber($scope.user.password);
  158. // 条件3 判断
  159. $scope.newPswdValidThree = ($scope.newPswdHasNumber && $scope.newPswdHasLiter) || // 数字和字母
  160. ($scope.newPswdHasNumber && $scope.newPswdValidTwo) || // 数字和特殊字符
  161. ($scope.newPswdHasLiter && $scope.newPswdValidTwo); // 数字、字母和特殊字符
  162. // 密码等级判断
  163. // 3.密码中包含数字、字母和多个特殊字符时,密码强度强
  164. if ($scope.newPswdValidOne && $scope.newPswdHasNumber && $scope.newPswdHasLiter && $scope.newPswdValidTwo) {
  165. $scope.newPswdRank = 3;
  166. $scope.newPswdRankText = "强";
  167. $ionicPopup.alert({
  168. title: '提示',
  169. template: '密码强度强,欢迎注册!'
  170. })
  171. }
  172. // 2.密码中包含数字、字母和任一特殊字符时,密码强度中;
  173. else if ($scope.newPswdValidOne && $scope.newPswdValidThree ) {
  174. $scope.newPswdRank = 2;
  175. $scope.newPswdRankText = "中";
  176. $ionicPopup.alert({
  177. title: '提示',
  178. template: '密码强度中,必须包含数字、字母和特殊字符,请重新输入密码!'
  179. })
  180. return;
  181. }
  182. // 1.密码中仅包含数字、字母时,密码强度弱;
  183. else {
  184. $scope.newPswdRank = 1;
  185. $scope.newPswdRankText = "弱";
  186. $ionicPopup.alert({
  187. title: '提示',
  188. template: '密码强度弱,必须包含数字、字母和特殊字符,且至少输入8位密码,请重新输入密码!'
  189. })
  190. return;
  191. }
  192. }
  193. $scope.showLoadingToast();
  194. $scope.register_finish = 'colorName';
  195. $scope.inputuser = {
  196. node:localStorage.node,
  197. smsVerCode: $scope.user.captcha,
  198. mobile: $scope.user.name,
  199. newPwd: $scope.user.password,
  200. };
  201. RegisterService.PwdReset($scope.inputuser).then(function (response) {
  202. $scope.hideLoadingToast();
  203. if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  204. if ($scope.app) {
  205. if ($scope.defaultLan == 'Chinese') {
  206. UtilService.showMess("重置成功");
  207. } else {
  208. UtilService.showMess("Reset successful");
  209. }
  210. } else {
  211. if ($scope.defaultLan == 'Chinese') {
  212. CommonService.showMessage('重置成功', $scope);
  213. } else {
  214. CommonService.showMessage('Reset successful', $scope);
  215. }
  216. }
  217. localStorage.setItem("mobile", $scope.user.name);
  218. localStorage.setItem("password", $scope.user.password);
  219. UserService.id = response.data;
  220. $timeout(function () {
  221. $scope.go('login');
  222. }, 3000);
  223. } else{
  224. if ($scope.app) {
  225. if ($scope.defaultLan == 'Chinese') {
  226. UtilService.showMess(response.message);
  227. } else {
  228. UtilService.showMess("error");
  229. }
  230. } else {
  231. if ($scope.defaultLan == 'Chinese') {
  232. CommonService.showMessage(response.message, $scope);
  233. } else {
  234. CommonService.showMessage('error', $scope);
  235. }
  236. }
  237. }
  238. }, function () {
  239. $scope.hideLoadingToast();
  240. if ($scope.app) {
  241. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  242. } else {
  243. CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR, $scope)
  244. }
  245. });
  246. }
  247. });