Skip to content

Commit

Permalink
Update js error handle
Browse files Browse the repository at this point in the history
  • Loading branch information
yrccondor committed May 19, 2020
1 parent 4ab3c1d commit eb666d6
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
26 changes: 26 additions & 0 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ function updateList(){
action: 'wwa_authenticator_list'
},
success: function(data){
if(typeof data === "string"){
console.warn(data);
jQuery("#authenticator-list").html('<tr><td colspan="'+(jQuery(".usernameless-th").css("display") === "none" ? "5" : "6")+'">'+php_vars.i18n_8+'</td></tr>');
return;
}
if(data.length === 0){
if(configs.usernameless === "true"){
jQuery(".usernameless-th, .usernameless-td").show();
Expand Down Expand Up @@ -77,6 +82,11 @@ function updateLog(){
action: 'wwa_get_log'
},
success: function(data){
if(typeof data === "string"){
console.warn(data);
jQuery("#wwa_log").text(php_vars.i18n_8);
return;
}
if(data.length === 0){
document.getElementById("clear_log").disabled = true;
jQuery("#wwa_log").text("");
Expand Down Expand Up @@ -146,6 +156,16 @@ jQuery("#bind").click(function(){
usernameless: jQuery(".authenticator_usernameless:checked").val() ? jQuery(".authenticator_usernameless:checked").val() : "false"
},
success: function(data){
if(typeof data === "string"){
console.warn(data);
jQuery('#show-progress').html(php_vars.i18n_4+": "+data);
jQuery("#bind").removeAttr('disabled');
jQuery("#authenticator_name").removeAttr('disabled');
jQuery(".authenticator_usernameless").removeAttr('disabled');
jQuery("#authenticator_type").removeAttr('disabled');
updateList();
return;
}
// Get the args, code string into Uint8Array
jQuery('#show-progress').text(php_vars.i18n_2);
let challenge = new Uint8Array(32);
Expand Down Expand Up @@ -275,6 +295,12 @@ jQuery("#test, #test_usernameless").click(function(){
usernameless: usernameless
},
success: function(data){
if(typeof data === "string"){
console.warn(data);
jQuery(tip_id).html(php_vars.i18n_15+": "+data);
jQuery("#test, #test_usernameless").removeAttr('disabled');
return;
}
if(data === "User not inited."){
jQuery(tip_id).html(php_vars.i18n_15+": "+php_vars.i18n_17);
jQuery("#test, #test_usernameless").removeAttr('disabled');
Expand Down
49 changes: 45 additions & 4 deletions js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,21 @@ function wwa_auth(){
request.get(wwa_php_vars.ajax_url, "?action=wwa_auth_start&user="+encodeURIComponent(wwa_username)+"&type=auth", (rawData, status)=>{
if(status){
button_dom.parentNode.previousElementSibling.innerHTML = wwa_php_vars.i18n_4;
let data = JSON.parse(rawData);
let data = rawData;
try{
data = JSON.parse(rawData);
}catch(e){
console.warn(rawData);
wwa_enable_buttons();
if(wwa_php_vars.usernameless === "true" && wwa_username === ""){
button_dom.parentNode.previousElementSibling.innerHTML = wwa_php_vars.i18n_7+wwa_php_vars.i18n_33;
wwa_dom("wwa-try-username", (dom)=>{dom.style.transform = 'translateY(-' + (parseInt(button_dom.parentNode.previousElementSibling.style.lineHeight) - 20) + 'px)'}, "class");
}else{
button_dom.parentNode.previousElementSibling.innerHTML = wwa_php_vars.i18n_7;
}
wwa_dom("wwa-user-name", (dom)=>{dom.readOnly = false}, "class");
return;
}
data.challenge = Uint8Array.from(window.atob(base64url2base64(data.challenge)), c=>c.charCodeAt(0));

if (data.allowCredentials) {
Expand Down Expand Up @@ -299,7 +313,19 @@ function wwa_bind(){
request.get(wwa_php_vars.ajax_url, "?action=wwa_create&name="+encodeURIComponent(wwa_name)+"&type="+encodeURIComponent(wwa_type)+"&usernameless="+wwa_usernameless, (rawData, status)=>{
if(status){
button_dom.nextElementSibling.innerHTML = wwa_php_vars.i18n_28;
let data = JSON.parse(rawData);
let data = rawData;
try{
data = JSON.parse(rawData);
}catch(e){
console.warn(rawData);
button_dom.nextElementSibling.innerHTML = wwa_php_vars.i18n_30;
wwa_enable_buttons();
wwa_dom("wwa-authenticator-name", (dom)=>{dom.readOnly = false}, "class");
wwa_dom("wwa-authenticator-type", (dom)=>{dom.disabled = false}, "class");
wwa_dom("wwa-authenticator-usernameless", (dom)=>{dom.disabled = false}, "class");
updateList();
return;
}
let challenge = new Uint8Array(32);
let user_id = new Uint8Array(32);
challenge = Uint8Array.from(window.atob(base64url2base64(data.challenge)), c=>c.charCodeAt(0));
Expand Down Expand Up @@ -408,7 +434,15 @@ function wwa_verify(){
button_dom.nextElementSibling.innerHTML = wwa_php_vars.i18n_15;
return;
}
let data = JSON.parse(rawData);
let data = rawData;
try{
data = JSON.parse(rawData);
}catch(e){
console.warn(rawData);
button_dom.nextElementSibling.innerHTML = wwa_php_vars.i18n_15;
wwa_enable_buttons();
return;
}
data.challenge = Uint8Array.from(window.atob(base64url2base64(data.challenge)), c=>c.charCodeAt(0));

if (data.allowCredentials) {
Expand Down Expand Up @@ -472,7 +506,14 @@ function updateList(){
let request = wwa_ajax();
request.get(wwa_php_vars.ajax_url, "?action=wwa_authenticator_list", (rawData, status) => {
if(status){
let data = JSON.parse(rawData);
let data = rawData;
try{
data = JSON.parse(rawData);
}catch(e){
console.warn(rawData);
wwa_dom("wwa-authenticator-list", (dom)=>{dom.innerHTML = '<tr><td colspan="'+(document.getElementsByClassName("wwa-usernameless-th")[0].style.display === "none" ? "5" : "6")+'">'+wwa_php_vars.i18n_17+'</td></tr>'}, "class");
return;
}
if(data.length === 0){
if(wwa_php_vars.usernameless === "true"){
wwa_dom(".wwa-usernameless-th, .wwa-usernameless-td", (dom)=>{dom.style.display = "table-cell"});
Expand Down
16 changes: 15 additions & 1 deletion js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,21 @@ function check(){
request.get(php_vars.ajax_url, "?action=wwa_auth_start&user="+encodeURIComponent(document.getElementById("user_login").value)+"&type=auth", (rawData, status)=>{
if(status){
wwa_dom("wp-webauthn-notice", (dom)=>{dom.innerHTML = php_vars.i18n_4}, "class");
let data = JSON.parse(rawData);
let data = rawData;
try{
data = JSON.parse(rawData);
}catch(e){
console.warn(rawData);
if(php_vars.usernameless === "true" && document.getElementById("user_login").value === ""){
wwa_dom("wp-webauthn-notice", (dom)=>{dom.innerHTML = php_vars.i18n_7+php_vars.i18n_12}, "class");
wwa_dom("wwa-try-username", (dom)=>{dom.style.transform = 'translateY(-' + (parseInt(document.getElementsByClassName("wp-webauthn-notice")[0].style.lineHeight) - 24) + 'px)'}, "class");
}else{
wwa_dom("wp-webauthn-notice", (dom)=>{dom.innerHTML = php_vars.i18n_7}, "class");
}
wwa_dom("user_login", (dom)=>{dom.readOnly = false}, "id");
wwa_dom("#wp-webauthn-check, #wp-webauthn", (dom)=>{dom.disabled = false});
return;
}
data.challenge = Uint8Array.from(window.atob(base64url2base64(data.challenge)), c=>c.charCodeAt(0));

if (data.allowCredentials) {
Expand Down

0 comments on commit eb666d6

Please sign in to comment.