123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- app.controller('ForgetPasswordCtrl', function($rootScope, $scope, $http, $interval, $state, myConfig, $cookieStore) {
- $scope.login = {
- login_name : '',
- mobile: '',
- password : '',
- confirm_password : '',
- verify_code: ''
- }
- $scope.mobileChecked = false;
- $scope.sendMessageTime = 0;
- $interval(function(){
- if($scope.sendMessageTime > 0){
- $scope.sendMessageTime--;
- }
- }, 1000);
-
- $scope.sendMessage = function(){
- $scope.sendMessageTime = 100;
-
- $scope.myPromise = $http({
- url : myConfig.url + '/user/checkSendSms',
- method : 'POST',
- data : angular.toJson($scope.login)
- }).success(function(data) {
- if(data.code == 0){
- if(data.result.checkResult){
- $scope.doSendSms();
- }else{
- $rootScope.dialogMsg("请勿频繁操作,请稍后重试", function(){});
- }
- }else{
- $rootScope.dialogMsg("请稍后重试", function(){});
- }
- }).error(function() {
- });
- }
-
- $scope.doSendSms = function(){
- $scope.myPromise = $http({
- url : myConfig.url + '/user/saveSmsLog',
- method : 'POST',
- data : angular.toJson($scope.login)
- }).success(function(data) {
- if(data.code == 0){
- $rootScope.dialogMsg("验证码已发送,请注意查收", function(){});
- }else{
- $rootScope.dialogMsg(data.errorMsg, function(){});
- }
- }).error(function() {
- });
- }
- // function to submit the form after all validation has occurred
- $scope.submitForm = function(isValid) {
- $scope.submitted = true;
- console.log($scope.login.password +" = "+ $scope.login.confirm_password);
- if($scope.login.password != $scope.login.confirm_password){
- $rootScope.dialogMsg("两次输入的密码不一致");
- return;
- }
-
- // check to make sure the form is completely valid
- if (isValid && $scope.mobileExists) {
- $scope.myPromise = $http({
- url : myConfig.url + '/user/resetPassword',
- method : 'POST',
- data : angular.toJson($scope.login)
- }).success(function(data) {
- if(data.code == 0){
- if(!data.result){
- $rootScope.dialogMsg("密码修改成功,请登录", function(){
- $state.go('login');
- });
- }else if(data.result.success == false){
- $rootScope.dialogMsg(data.result.message, function(){
- });
- }
- }else{
- $rootScope.dialogMsg(data.errorMsg, function(){});
- }
- }).error(function() {
- });
- }
- };
-
- $scope.checkMobile = function(){
- $scope.mobileChecked = true;
- if($scope.login.mobile.trim().length > 0){
- $scope.myPromise = $http({
- url : myConfig.url + '/user/checkMobile',
- method : 'POST',
- data : angular.toJson($scope.login)
- }).success(function(data) {
- if(data.code == 0){
- $scope.mobileExists = data.result.length > 0;
- }else{
- $rootScope.dialogMsg(data.errorMsg, function(){});
- }
- }).error(function() {
- });
- }
- }
-
- })
|