account.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. (function (app) {
  2. app.controller('loginCtrl', ["$scope", 'userService', "data", '$state', 'msg', '$http', function ($scope, userService, data, $state, msg, $http) {
  3. $scope.vm = {
  4. mobile: '',
  5. password:''
  6. };
  7. $scope.login = function () {
  8. msg.loading('登录中...');
  9. userService.login($scope.vm.mobile, $scope.vm.password).then(function (result) {
  10. msg.hide();
  11. data.setObject('user', result.data.user);
  12. data.set('token', result.data.token);
  13. $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.token;
  14. $state.go('wl.home');
  15. }, function (erro) {
  16. msg.hide();
  17. // msg.error(erro.data.message);
  18. msg.error(erro.data.message);
  19. });
  20. }
  21. }]);
  22. app.controller('registerCtrl', ["$scope", 'msg', 'util', 'userService', '$timeout', '$state', 'data', '$http', function ($scope, msg, util, userService, $timeout, $state, data, $http) {
  23. $scope.vm = {
  24. mobile: '',
  25. password: '',
  26. password1:'',
  27. verifyCode:'',
  28. waitSeconds: "获取验证码"
  29. };
  30. $scope.typeOpt = [
  31. { name: "托运方", value: 1 },
  32. { name: "承运方", value: 2 }
  33. ];
  34. $scope.idcard_typeOpt = [
  35. { name: "身份证", value: 1 },
  36. { name: "其它", value: 2 }
  37. ];
  38. $scope.save = function () {
  39. if (!$scope.vm.type) {
  40. msg.text('请选择类型');
  41. return;
  42. }
  43. if (!$scope.vm.idcard_type) {
  44. msg.text('请选择证件类型');
  45. return;
  46. }
  47. if (!$scope.vm.idcard_no) {
  48. msg.text('请输入证件号码');
  49. return;
  50. }
  51. if (!util.isMobile($scope.vm.mobile)) {
  52. msg.text('请输入正确的手机号', true);
  53. return;
  54. }
  55. if (!$scope.vm.verifyCode) {
  56. msg.text('请输入短信验证码');
  57. return;
  58. }
  59. if ($scope.vm.password !== $scope.vm.password1) {
  60. msg.text('密码前后输入不一致');
  61. return;
  62. }
  63. msg.loading('请稍等...');
  64. userService.register({
  65. phone: $scope.vm.mobile, password: $scope.vm.password,
  66. verifyCode: $scope.vm.verifyCode, idcard_type: $scope.vm.idcard_type, idcard_no: $scope.vm.idcard_no, type: $scope.vm.type
  67. }).then(function (result) {
  68. data.setObject('user', { mobile: $scope.vm.mobile, type: $scope.vm.type });
  69. data.set('token', result.data.token);
  70. $http.defaults.headers.common["Authorization"] = 'Bearer ' + result.data.token;
  71. msg.hide();
  72. if ($scope.vm.type == 1) {//托运方
  73. $state.go('wl.car');
  74. }
  75. if ($scope.vm.type == 2) {//承运方
  76. $state.go('wl.goods');
  77. }
  78. }, function (erro) {
  79. msg.hide();
  80. msg.error(erro.data.message);
  81. });
  82. }
  83. $scope.getVerifyCode = function () {
  84. if (!util.isMobile($scope.vm.mobile)) {
  85. msg.text('请输入正确的手机号',true);
  86. return;
  87. }
  88. $scope.vm.waitSeconds = "正在发送";
  89. userService.getVerifyCode($scope.vm.mobile).then(function (result) {
  90. wait(60);
  91. }, function (erro) {
  92. wait(0);
  93. msg.error(erro);
  94. });
  95. }
  96. var wait = function (seconds) {
  97. if (seconds > 0) {
  98. $scope.vm.waitSeconds = "" + seconds + "秒";
  99. $scope.vm.enableSend = false;
  100. } else {
  101. $scope.vm.waitSeconds = "获取验证码";
  102. $scope.vm.enableSend = true;
  103. }
  104. $timeout(function () {
  105. if (seconds >= 1)
  106. wait(seconds - 1);
  107. }, 1000);
  108. };
  109. }]);
  110. app.controller('forgetPasswordCtrl', ["$scope", "util", 'userService', '$timeout', '$state', 'msg', function ($scope, util, userService, $timeout, $state, msg) {
  111. $scope.vm = {
  112. mobile: '',
  113. code: '',
  114. password: '',
  115. password1:'',
  116. waitSeconds: "获取验证码"
  117. };
  118. $scope.getVerifyCode = function () {
  119. if (!util.isMobile($scope.vm.mobile)) {
  120. msg.text('请输入正确的手机号', true);
  121. return;
  122. }
  123. $scope.vm.waitSeconds = "正在发送";
  124. userService.getVerifyCode($scope.vm.mobile).then(function (result) {
  125. wait(60);
  126. }, function (erro) {
  127. wait(0);
  128. msg.error(erro);
  129. });
  130. }
  131. $scope.reset = function (vm) {
  132. if (vm.password != vm.password1) {
  133. msg.text('密码前后输入不一致');
  134. return;
  135. }
  136. msg.loading('请稍等...');
  137. var model = { phone: vm.mobile, verifyCode: vm.code, password:vm.password };
  138. userService.resetPassword(model).then(function () {
  139. msg.hide();
  140. msg.success('密码找回成功');
  141. $state.go('login');
  142. }, function (erro) {
  143. msg.hide();
  144. msg.error(erro.message);
  145. });
  146. }
  147. var wait = function (seconds) {
  148. if (seconds > 0) {
  149. $scope.vm.waitSeconds = "" + seconds + "秒";
  150. $scope.vm.enableSend = false;
  151. } else {
  152. $scope.vm.waitSeconds = "获取验证码";
  153. $scope.vm.enableSend = true;
  154. }
  155. $timeout(function () {
  156. if (seconds >= 1)
  157. wait(seconds - 1);
  158. }, 1000);
  159. };
  160. }]);
  161. })(angular.module('app.controllers'));