'use strict';
appCore.controller("ChangePasswordCtrl", ["$scope", "$stateParams", "$http", "$timeout", "vServices", function ($scope, $stateParams, $http, $timeout, vServices) {
  $scope.$root.page.title = "Change Password";
  $scope.data = {
    emp_old_password: null,
    emp_password: null,
    emp_confirmpassword: null
  };
  $scope.changePassword = function () {
    if (!$scope.data.emp_password) {
      toastr.warning("Please fill the Password.", "Warning!", {timeOut: 5000});
    }
    else if (!$scope.data.emp_confirmpassword) {
      toastr.warning("Please fill the Confirm Password.", "Warning!", {timeOut: 5000});
    }
    else if ($scope.data.emp_password !== $scope.data.emp_confirmpassword) {
      toastr.error("Your new password and confirmation password do not match", "Error!", {timeOut: 5000});
    }
    else {
      vServices.callApi("auth/change_password", "PUT", $scope.data).then(function (res) {
        if (res) {
          toastr.success(res, "Success!", {timeOut: 5000});
        }
      });
    }
  };
}]);
