diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 5b042f691..d8e82a0a0 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -2945,6 +2945,73 @@ app.controller('listWebsites', function ($scope, $http, $window) { }; + $scope.togglePasswordProtection = function(wp) { + if (wp.passwordProtection) { + // Show modal for credentials + $('#Passwordprotection').modal('show'); + // Store the current WordPress site for later use + $scope.currentWPSite = wp; + } else { + // Disable password protection + $scope.updateSetting(wp, 'password-protection'); + } + }; + + $scope.enablePasswordProtection = function() { + if (!$scope.PPUsername || !$scope.PPPassword) { + new PNotify({ + title: 'Error!', + text: 'Please provide both username and password', + type: 'error' + }); + return; + } + + var data = { + siteId: $scope.currentWPSite.id, + setting: 'password-protection', + PPUsername: $scope.PPUsername, + PPPassword: $scope.PPPassword + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('/websites/UpdateWPSettings', data, config).then( + function(response) { + if (response.data.status) { + new PNotify({ + title: 'Success!', + text: 'Password protection enabled successfully', + type: 'success' + }); + $('#Passwordprotection').modal('hide'); + // Clear the credentials + $scope.PPUsername = ''; + $scope.PPPassword = ''; + } else { + $scope.currentWPSite.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to enable password protection', + type: 'error' + }); + } + }, + function(response) { + $scope.currentWPSite.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server', + type: 'error' + }); + } + ); + }; + }); app.controller('listChildDomainsMain', function ($scope, $http, $timeout) { @@ -6338,6 +6405,73 @@ app.controller('listWebsites', function ($scope, $http, $window) { }; + $scope.togglePasswordProtection = function(wp) { + if (wp.passwordProtection) { + // Show modal for credentials + $('#Passwordprotection').modal('show'); + // Store the current WordPress site for later use + $scope.currentWPSite = wp; + } else { + // Disable password protection + $scope.updateSetting(wp, 'password-protection'); + } + }; + + $scope.enablePasswordProtection = function() { + if (!$scope.PPUsername || !$scope.PPPassword) { + new PNotify({ + title: 'Error!', + text: 'Please provide both username and password', + type: 'error' + }); + return; + } + + var data = { + siteId: $scope.currentWPSite.id, + setting: 'password-protection', + PPUsername: $scope.PPUsername, + PPPassword: $scope.PPPassword + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post('/websites/UpdateWPSettings', data, config).then( + function(response) { + if (response.data.status) { + new PNotify({ + title: 'Success!', + text: 'Password protection enabled successfully', + type: 'success' + }); + $('#Passwordprotection').modal('hide'); + // Clear the credentials + $scope.PPUsername = ''; + $scope.PPPassword = ''; + } else { + $scope.currentWPSite.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: response.data.error_message || 'Failed to enable password protection', + type: 'error' + }); + } + }, + function(response) { + $scope.currentWPSite.passwordProtection = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server', + type: 'error' + }); + } + ); + }; + }); app.controller('listChildDomainsMain', function ($scope, $http, $timeout) { diff --git a/websiteFunctions/templates/websiteFunctions/listWebsites.html b/websiteFunctions/templates/websiteFunctions/listWebsites.html index 3fd35f039..12c7ecf79 100755 --- a/websiteFunctions/templates/websiteFunctions/listWebsites.html +++ b/websiteFunctions/templates/websiteFunctions/listWebsites.html @@ -16,6 +16,37 @@ }); + +