forgotpwd.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. app.controller('ForgotpwdCtrl', ['$scope', '$http', '$state', '$interval', function ($scope, $http, $state, $interval) {
  3. $scope.username = "";
  4. $scope.code = "";
  5. $scope.authError = null;
  6. $scope.codeTime = 0;
  7. $scope.getCheckCode = function () {
  8. $scope.authError = null;
  9. $http.get('/manager/user/getCode', {username: $scope.username})
  10. .then(function (response) {
  11. var data = response.data;
  12. if (data.result == 1) {
  13. $scope.authError = '无法获取验证码';
  14. } else {
  15. $scope.codeTime = 60;
  16. var timer = $interval(function () {
  17. $scope.codeTime--;
  18. if ($scope.codeTime <= 0) {
  19. $interval.cancel(timer);
  20. }
  21. }, 1000);
  22. }
  23. }, function (x) {
  24. $scope.authError = '服务器异常';
  25. });
  26. };
  27. $scope.sendCheck = function () {
  28. $scope.authError = null;
  29. $http.post('/manager/user/forgot', {username: $scope.username, code: $scope.code})
  30. .then(function (response) {
  31. var data = response.data;
  32. if (data.result == 1) {
  33. $scope.authError = '验证码不对';
  34. } else {
  35. $state.go('app');
  36. }
  37. }, function (x) {
  38. $scope.authError = '服务器异常';
  39. });
  40. };
  41. }]);