-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #453 from equalizedigital/hotfix/basic-auth-fix
Hotfix - basic auth fix
- Loading branch information
Showing
7 changed files
with
99 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,73 @@ | ||
import { settings } from './settings'; | ||
import { info, debug } from './helpers'; | ||
import { showNotice } from './../common/helpers'; | ||
import { settings } from './settings'; | ||
import { init as initCheckPage } from './checkPage'; | ||
import { showNotice } from './../common/helpers'; | ||
|
||
|
||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
|
||
const SCANNABLE_POST_TYPE = edac_editor_app.active; | ||
|
||
if(SCANNABLE_POST_TYPE && settings.JS_SCAN_ENABLED){ | ||
|
||
if (SCANNABLE_POST_TYPE && settings.JS_SCAN_ENABLED) { | ||
|
||
if(edac_editor_app.pro === '1'){ | ||
|
||
// Use checkApi from pro instead. | ||
setTimeout(function(){ | ||
if (edac_editor_app.pro === '1' || edac_editor_app.basicAuth !== '1') { | ||
|
||
setTimeout(function () { | ||
initCheckPage(); | ||
}, 250); // Allow page load to fire before init, otherwise we'll have to wait for iframe to load. | ||
|
||
} else { | ||
|
||
const API_URL = edac_editor_app.edacApiUrl; | ||
const HEADERS = edac_editor_app.edacHeaders; | ||
|
||
|
||
const checkApi = async () => { | ||
try { | ||
const response = await fetch(API_URL + '/test', { | ||
method: "POST", | ||
headers: HEADERS | ||
}); | ||
|
||
return response.status; | ||
} catch (error) { | ||
return 401; // Default status for error | ||
} | ||
}; | ||
|
||
|
||
checkApi().then((status) => { | ||
|
||
if (status > 400) { | ||
|
||
if (status == 401) { | ||
|
||
showNotice({ | ||
msg: 'Whoops! It looks like your website is currently password protected. The free version of Accessibility Checker can only scan live websites. To scan this website for accessibility problems either remove the password protection or follow the link below to upgrade to Accessibility Checker Pro.', | ||
type: 'warning', | ||
url: 'https://equalizedigital.com/accessibility-checker/pricing/', | ||
label: 'Upgrade', | ||
closeOthers: true | ||
}); | ||
|
||
|
||
//Listen for dispatches from the wp data store so we can trap the update/publish event | ||
let saving = false; | ||
let autosaving = false; | ||
|
||
|
||
if (wp.data !== undefined && wp.data.subscribe !== undefined) { | ||
wp.data.subscribe(() => { | ||
|
||
|
||
if (wp.data.select('core/editor').isAutosavingPost()) { | ||
autosaving = true; | ||
} | ||
|
||
// Rescan the page if user saves post | ||
if (wp.data.select('core/editor').isSavingPost()) { | ||
|
||
saving = true; | ||
} else { | ||
showNotice({ | ||
msg: 'Whoops! It looks like there was a problem connecting to the WordPress REST API which is required by Accessibility Checker. Follow the link below for more information:', | ||
type: 'warning', | ||
url: 'https://developer.wordpress.org/rest-api/frequently-asked-questions', | ||
label: 'Rest API', | ||
closeOthers: true | ||
}); | ||
|
||
debug('Error: Cannot connect to API. Status code is: ' + status); | ||
|
||
if (saving) { | ||
saving = false; | ||
|
||
if (edac_editor_app.pro !== '1' || edac_editor_app.basicAuth === '1') { | ||
showNotice({ | ||
msg: 'Whoops! It looks like your website is currently password protected. The free version of Accessibility Checker can only scan live websites. To scan this website for accessibility problems either remove the password protection or follow the link below to upgrade to Accessibility Checker Pro.', | ||
type: 'warning', | ||
url: 'https://equalizedigital.com/accessibility-checker/pricing/', | ||
label: 'Upgrade', | ||
closeOthers: true | ||
}); | ||
|
||
} | ||
|
||
} | ||
} | ||
} else { | ||
|
||
setTimeout(function(){ | ||
initCheckPage(); | ||
}, 250); // Allow page load to fire before init, otherwise we'll have to wait for iframe to load. | ||
|
||
} | ||
|
||
}).catch((error) => { | ||
|
||
|
||
showNotice({ | ||
msg: 'Whoops! It looks like there was a problem connecting to the WordPress REST API which is required by Accessibility Checker. Follow the link below for more information:', | ||
type: 'warning', | ||
url: 'https://developer.wordpress.org/rest-api/frequently-asked-questions', | ||
label: 'Rest API', | ||
closeOthers: true | ||
|
||
}); | ||
|
||
debug(error); | ||
|
||
}); | ||
|
||
} else { | ||
debug("Gutenberg is not enabled."); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
}); | ||
|
||
|