forgotpwd.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. app.controller('ForgotpwdCtrl', ['$scope', '$http', '$state', '$interval', 'toaster', 'md5', function ($scope, $http, $state, $interval, toaster, MD5) {
  3. $scope.username = "";
  4. $scope.code = "";
  5. $scope.authError = null;
  6. $scope.codeTime = 0;
  7. $scope.getCheckCode = function () {
  8. function isPhone(str) {
  9. var phoneReg = /^[1][3456789]\d{9}$/;
  10. return phoneReg.test(str);
  11. }
  12. if (!isPhone($scope.username)) {
  13. toaster.pop("warning", "提示", "请输入11位正确手机号码",2000);
  14. return;
  15. }
  16. $scope.authError = null;
  17. $http.get('/manager/getCheckCode', {params: {username: $scope.username}})
  18. .then(function (response) {
  19. if (response.result == 0) {
  20. $scope.authError = response.description;
  21. } else {
  22. $scope.codeTime = 60;
  23. var timer = $interval(function () {
  24. $scope.codeTime--;
  25. if ($scope.codeTime <= 0) {
  26. $interval.cancel(timer);
  27. }
  28. }, 1000);
  29. }
  30. }, function (x) {
  31. $scope.authError = '服务器异常';
  32. });
  33. };
  34. $scope.sendCheck = function () {
  35. $scope.authError = null;
  36. $http.post('/manager/verifyForgetCode', {
  37. username: $scope.username,
  38. password: MD5.createHash($scope.password + ''),
  39. code: $scope.code
  40. })
  41. .then(function (response) {
  42. if (response.result === 0) {
  43. $scope.authError = '验证码不对';
  44. } else {
  45. $state.go('app');
  46. }
  47. }, function (x) {
  48. $scope.authError = '服务器异常';
  49. });
  50. };
  51. }]);