forgetPassword.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. app.controller('ForgetPasswordCtrl', function($rootScope, $scope, $http, $interval, $state, myConfig, $cookieStore) {
  2. $scope.login = {
  3. login_name : '',
  4. mobile: '',
  5. password : '',
  6. confirm_password : '',
  7. verify_code: ''
  8. }
  9. $scope.mobileChecked = false;
  10. $scope.sendMessageTime = 0;
  11. $interval(function(){
  12. if($scope.sendMessageTime > 0){
  13. $scope.sendMessageTime--;
  14. }
  15. }, 1000);
  16. $scope.sendMessage = function(){
  17. $scope.sendMessageTime = 100;
  18. $scope.myPromise = $http({
  19. url : myConfig.url + '/user/checkSendSms',
  20. method : 'POST',
  21. data : angular.toJson($scope.login)
  22. }).success(function(data) {
  23. if(data.code == 0){
  24. if(data.result.checkResult){
  25. $scope.doSendSms();
  26. }else{
  27. $rootScope.dialogMsg("请勿频繁操作,请稍后重试", function(){});
  28. }
  29. }else{
  30. $rootScope.dialogMsg("请稍后重试", function(){});
  31. }
  32. }).error(function() {
  33. });
  34. }
  35. $scope.doSendSms = function(){
  36. $scope.myPromise = $http({
  37. url : myConfig.url + '/user/saveSmsLog',
  38. method : 'POST',
  39. data : angular.toJson($scope.login)
  40. }).success(function(data) {
  41. if(data.code == 0){
  42. $rootScope.dialogMsg("验证码已发送,请注意查收", function(){});
  43. }else{
  44. $rootScope.dialogMsg(data.errorMsg, function(){});
  45. }
  46. }).error(function() {
  47. });
  48. }
  49. // function to submit the form after all validation has occurred
  50. $scope.submitForm = function(isValid) {
  51. $scope.submitted = true;
  52. console.log($scope.login.password +" = "+ $scope.login.confirm_password);
  53. if($scope.login.password != $scope.login.confirm_password){
  54. $rootScope.dialogMsg("两次输入的密码不一致");
  55. return;
  56. }
  57. // check to make sure the form is completely valid
  58. if (isValid && $scope.mobileExists) {
  59. $scope.myPromise = $http({
  60. url : myConfig.url + '/user/resetPassword',
  61. method : 'POST',
  62. data : angular.toJson($scope.login)
  63. }).success(function(data) {
  64. if(data.code == 0){
  65. if(!data.result){
  66. $rootScope.dialogMsg("密码修改成功,请登录", function(){
  67. $state.go('login');
  68. });
  69. }else if(data.result.success == false){
  70. $rootScope.dialogMsg(data.result.message, function(){
  71. });
  72. }
  73. }else{
  74. $rootScope.dialogMsg(data.errorMsg, function(){});
  75. }
  76. }).error(function() {
  77. });
  78. }
  79. };
  80. $scope.checkMobile = function(){
  81. $scope.mobileChecked = true;
  82. if($scope.login.mobile.trim().length > 0){
  83. $scope.myPromise = $http({
  84. url : myConfig.url + '/user/checkMobile',
  85. method : 'POST',
  86. data : angular.toJson($scope.login)
  87. }).success(function(data) {
  88. if(data.code == 0){
  89. $scope.mobileExists = data.result.length > 0;
  90. }else{
  91. $rootScope.dialogMsg(data.errorMsg, function(){});
  92. }
  93. }).error(function() {
  94. });
  95. }
  96. }
  97. })