'use strict';

app.controller('ChangePasswordController', function ($scope, $state, toastr, User) {
  $scope.save = function () {

    var oldPassData = $scope.formData.currentPassword;
    var newPassData = $scope.formData.newPassword;
    var jsonData = JSON.stringify( { old_password : oldPassData, new_password : newPassData });
    
    User.changePassword(jsonData).then(function (data) {
      toastr.success('Successfully changed password!');
      $state.transitionTo('account-settings.main', null, { reload: true, inherit: true, notify: true  });     
    }).
    catch(function (error) {
      toastr.error(error);
    });
  };
});


