apply.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. app.controller('ApplyCtrl', function($rootScope, $scope, $http, $timeout, $state, myConfig, $cookieStore, $interval) {
  2. $scope.load = function(){
  3. $scope.login = {
  4. login_name : '',
  5. mobile: '',
  6. password : '',
  7. confirm_password : ''
  8. };
  9. $scope.sendMessageTime = 0;
  10. $interval(function(){
  11. if($scope.sendMessageTime > 0){
  12. $scope.sendMessageTime--;
  13. }
  14. }, 1000);
  15. $scope.myPromise = $http({
  16. url : myConfig.url + '/frame/province',
  17. method : 'GET'
  18. }).success(function(data) {
  19. if(data.code == 0){
  20. $scope.provinces = data.result;
  21. }else{
  22. $rootScope.dialogMsg(data.message, function(){
  23. window.location = "index.html";
  24. })
  25. }
  26. }).error(function() {
  27. });
  28. }
  29. $scope.load();
  30. $scope.refreshArea = function(){
  31. $scope.login.graduate_school_area = null;
  32. $scope.login.graduate_school_city = null;
  33. $scope.myPromise = $http({
  34. url : myConfig.url + '/frame/area/' + $scope.login.graduate_school_province,
  35. method : 'GET'
  36. }).success(function(data) {
  37. if(data.code == 0){
  38. $scope.areas = data.result;
  39. }
  40. }).error(function() {
  41. });
  42. }
  43. $scope.refreshCity = function(){
  44. $scope.login.graduate_school_city = null;
  45. $scope.myPromise = $http({
  46. url : myConfig.url + '/frame/city/' + $scope.login.graduate_school_area,
  47. method : 'GET'
  48. }).success(function(data) {
  49. if(data.code == 0){
  50. $scope.cities = data.result;
  51. }
  52. }).error(function() {
  53. });
  54. }
  55. $scope.refreshSchool = function(){
  56. $scope.login.graduate_school_id = null;
  57. $scope.myPromise = $http({
  58. url : myConfig.url + '/frame/school/' + $scope.login.graduate_school_city,
  59. method : 'GET'
  60. }).success(function(data) {
  61. if(data.code == 0){
  62. $scope.schoolList = data.result;
  63. }
  64. }).error(function() {
  65. });
  66. }
  67. // function to submit the form after all validation has occurred
  68. $scope.submitForm = function(isValid) {
  69. $scope.submitted = true;
  70. if($scope.login.password != $scope.login.confirm_password){
  71. $rootScope.dialogMsg("两次输入的密码不一致");
  72. return;
  73. }
  74. // check to make sure the form is completely valid
  75. if (isValid && $scope.loginNameExists == false && $scope.certIdExists == false && !$scope.invalidCertId) {
  76. $scope.myPromise = $http({
  77. url : myConfig.url + '/user/checkVerifyCode',
  78. method : 'POST',
  79. data : angular.toJson($scope.login)
  80. }).success(function(data) {
  81. if(data.code == 0){
  82. $scope.myPromise = $http({
  83. url : myConfig.url + '/user/apply',
  84. method : 'POST',
  85. data : angular.toJson($scope.login)
  86. }).success(function(data) {
  87. if(data.code == 0){
  88. $rootScope.dialogMsg("注册成功,请登录", function(){
  89. $state.go('login');
  90. });
  91. }else{
  92. $rootScope.dialogMsg(data.errorMsg, function(){});
  93. }
  94. }).error(function() {
  95. });
  96. }else{
  97. $rootScope.dialogMsg(data.errorMsg, function(){});
  98. }
  99. }).error(function() {
  100. });
  101. }
  102. };
  103. // $scope.checkLoginName = function(){
  104. // if($scope.login.login_name.trim().length > 0){
  105. // $scope.myPromise = $http({
  106. // url : myConfig.url + '/user/checkLoginName',
  107. // method : 'POST',
  108. // data : angular.toJson($scope.login)
  109. // }).success(function(data) {
  110. // if(data.code == 0){
  111. // $scope.loginNameExists = data.result.length > 0;
  112. // }else{
  113. // $rootScope.dialogMsg(data.errorMsg, function(){});
  114. // }
  115. // }).error(function() {
  116. // });
  117. // }
  118. // }
  119. $scope.checkLoginName = function(){
  120. if(!(/^1[3|4|5|7|8|9][0-9]\d{8}$/.test($scope.login.login_name))){
  121. $scope.invalidMobile = true;
  122. return;
  123. }else{
  124. $scope.invalidMobile = false;
  125. }
  126. if($scope.login.login_name.trim().length > 0){
  127. $scope.myPromise = $http({
  128. url : myConfig.url + '/user/checkLoginName',
  129. method : 'POST',
  130. data : angular.toJson($scope.login)
  131. }).success(function(data) {
  132. if(data.code == 0){
  133. $scope.loginNameExists = data.result.length > 0;
  134. }else{
  135. $rootScope.dialogMsg(data.errorMsg, function(){});
  136. }
  137. }).error(function() {
  138. });
  139. }
  140. }
  141. $scope.checkCertId = function(){
  142. var card = $scope.login.cert_id;
  143. //校验长度,类型
  144. if(isCardNo(card) === false || checkProvince(card) === false || checkBirthday(card) === false || checkParity(card) === false )
  145. {
  146. $scope.invalidCertId = true;
  147. return false;
  148. }else{
  149. $scope.invalidCertId = false;
  150. }
  151. if($scope.login.cert_id.trim().length > 0){
  152. $scope.myPromise = $http({
  153. url : myConfig.url + '/user/checkCertId',
  154. method : 'POST',
  155. data : angular.toJson($scope.login)
  156. }).success(function(data) {
  157. if(data.code == 0){
  158. $scope.certIdExists = data.result.length > 0;
  159. }else{
  160. $rootScope.dialogMsg(data.errorMsg, function(){});
  161. }
  162. }).error(function() {
  163. });
  164. }
  165. }
  166. // $scope.checkMobile = function(){
  167. // if(!(/^1[3|4|5|7|8][0-9]\d{8}$/.test($scope.login.mobile))){
  168. // $scope.invalidMobile = true;
  169. // return;
  170. // }else{
  171. // $scope.invalidMobile = false;
  172. // }
  173. //
  174. // if($scope.login.mobile.trim().length > 0){
  175. // $scope.myPromise = $http({
  176. // url : myConfig.url + '/user/checkMobile',
  177. // method : 'POST',
  178. // data : angular.toJson($scope.login)
  179. // }).success(function(data) {
  180. // if(data.code == 0){
  181. // $scope.mobileExists = data.result.length > 0;
  182. // }else{
  183. // $rootScope.dialogMsg(data.errorMsg, function(){});
  184. // }
  185. // }).error(function() {
  186. // });
  187. // }
  188. // }
  189. $scope.sendMessage = function(){
  190. if(!$scope.login.login_name){
  191. $rootScope.dialogMsg("请输入手机号", function(){});
  192. return;
  193. }
  194. if($scope.loginNameExists){
  195. $rootScope.dialogMsg("手机号已注册,请重新输入", function(){});
  196. return;
  197. }
  198. if(!(/^1[3|4|5|7|8][0-9]\d{8}$/.test($scope.login.login_name))){
  199. $scope.invalidMobile = true;
  200. $rootScope.dialogMsg("手机号格式不正确,请重新输入", function(){});
  201. return;
  202. }
  203. $scope.sendMessageTime = 100;
  204. $scope.login.mobile = $scope.login.login_name;
  205. $scope.myPromise = $http({
  206. url : myConfig.url + '/user/checkSendSms',
  207. method : 'POST',
  208. data : angular.toJson($scope.login)
  209. }).success(function(data) {
  210. if(data.code == 0){
  211. if(data.result.checkResult){
  212. $scope.doSendSms();
  213. }else{
  214. $rootScope.dialogMsg("请勿频繁操作,请稍后重试", function(){});
  215. }
  216. }else{
  217. $rootScope.dialogMsg("请稍后重试", function(){});
  218. }
  219. }).error(function() {
  220. });
  221. }
  222. $scope.doSendSms = function(){
  223. $scope.myPromise = $http({
  224. url : myConfig.url + '/user/saveSmsLog',
  225. method : 'POST',
  226. data : angular.toJson($scope.login)
  227. }).success(function(data) {
  228. if(data.code == 0){
  229. $rootScope.dialogMsg("验证码已发送,请注意查收", function(){});
  230. }else{
  231. $rootScope.dialogMsg(data.errorMsg, function(){});
  232. }
  233. }).error(function() {
  234. });
  235. }
  236. var vcity={ 11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",
  237. 21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",
  238. 33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",
  239. 42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",
  240. 51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",
  241. 63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"
  242. };
  243. //检查号码是否符合规范,包括长度,类型
  244. isCardNo = function(card)
  245. {
  246. //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
  247. var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
  248. if(reg.test(card) === false)
  249. {
  250. return false;
  251. }
  252. return true;
  253. };
  254. //取身份证前两位,校验省份
  255. checkProvince = function(card)
  256. {
  257. var province = card.substr(0,2);
  258. if(vcity[province] == undefined)
  259. {
  260. return false;
  261. }
  262. return true;
  263. };
  264. //检查生日是否正确
  265. checkBirthday = function(card)
  266. {
  267. var len = card.length;
  268. //身份证15位时,次序为省(3位)市(3位)年(2位)月(2位)日(2位)校验位(3位),皆为数字
  269. if(len == '15')
  270. {
  271. var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;
  272. var arr_data = card.match(re_fifteen);
  273. var year = arr_data[2];
  274. var month = arr_data[3];
  275. var day = arr_data[4];
  276. var birthday = new Date('19'+year+'/'+month+'/'+day);
  277. return verifyBirthday('19'+year,month,day,birthday);
  278. }
  279. //身份证18位时,次序为省(3位)市(3位)年(4位)月(2位)日(2位)校验位(4位),校验位末尾可能为X
  280. if(len == '18')
  281. {
  282. var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;
  283. var arr_data = card.match(re_eighteen);
  284. var year = arr_data[2];
  285. var month = arr_data[3];
  286. var day = arr_data[4];
  287. var birthday = new Date(year+'/'+month+'/'+day);
  288. return verifyBirthday(year,month,day,birthday);
  289. }
  290. return false;
  291. };
  292. //校验日期
  293. verifyBirthday = function(year,month,day,birthday)
  294. {
  295. var now = new Date();
  296. var now_year = now.getFullYear();
  297. //年月日是否合理
  298. if(birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day)
  299. {
  300. //判断年份的范围(3岁到100岁之间)
  301. var time = now_year - year;
  302. if(time >= 3 && time <= 100)
  303. {
  304. return true;
  305. }
  306. return false;
  307. }
  308. return false;
  309. };
  310. //校验位的检测
  311. checkParity = function(card)
  312. {
  313. //15位转18位
  314. card = changeFivteenToEighteen(card);
  315. var len = card.length;
  316. if(len == '18')
  317. {
  318. var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
  319. var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
  320. var cardTemp = 0, i, valnum;
  321. for(i = 0; i < 17; i ++)
  322. {
  323. cardTemp += card.substr(i, 1) * arrInt[i];
  324. }
  325. valnum = arrCh[cardTemp % 11];
  326. if (valnum == card.substr(17, 1))
  327. {
  328. return true;
  329. }
  330. return false;
  331. }
  332. return false;
  333. };
  334. //15位转18位身份证号
  335. changeFivteenToEighteen = function(card)
  336. {
  337. if(card.length == '15')
  338. {
  339. var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
  340. var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
  341. var cardTemp = 0, i;
  342. card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);
  343. for(i = 0; i < 17; i ++)
  344. {
  345. cardTemp += card.substr(i, 1) * arrInt[i];
  346. }
  347. card += arrCh[cardTemp % 11];
  348. return card;
  349. }
  350. return card;
  351. };
  352. })