From 6034ba3263fcfea911e914b38f6cdac188c7a596 Mon Sep 17 00:00:00 2001 From: Leberwurscht Date: Sun, 15 Apr 2012 22:57:25 +0200 Subject: [PATCH] jappixmini: wait for client secret to be set --- jappixmini/jappixmini.php | 8 ++- jappixmini/lib.js | 126 +++++++++++++++++++++----------------- 2 files changed, 77 insertions(+), 57 deletions(-) diff --git a/jappixmini/jappixmini.php b/jappixmini/jappixmini.php index b68114d1..80fc237f 100644 --- a/jappixmini/jappixmini.php +++ b/jappixmini/jappixmini.php @@ -270,7 +270,9 @@ function jappixmini_settings(&$a, &$s) { if (friendica_password) { jappixmini_addon_set_client_secret(friendica_password.value); - password.value = jappixmini_addon_encrypt_password(clear_password.value); + jappixmini_addon_encrypt_password(clear_password.value, function(encrypted_password){ + password.value = encrypted_password; + }); } } else { @@ -283,7 +285,9 @@ function jappixmini_settings(&$a, &$s) { password = document.getElementById('jappixmini-password'); clear_password = document.getElementById('jappixmini-clear-password'); if (encrypt) { - clear_password.value = jappixmini_addon_decrypt_password(password.value); + jappixmini_addon_decrypt_password(password.value, function(decrypted_password){ + clear_password.value = decrypted_password; + }); } else { clear_password.value = password.value; diff --git a/jappixmini/lib.js b/jappixmini/lib.js index 610a8312..94e465d1 100644 --- a/jappixmini/lib.js +++ b/jappixmini/lib.js @@ -24,59 +24,71 @@ function jappixmini_addon_set_client_secret(password) { client_secret2 = str_sha1(salt2+password); client_secret = client_secret1 + client_secret2; - setDB('jappix-mini', 'client_secret', client_secret); + setDB('jappix-mini', 'client-secret', client_secret); console.log("client secret set"); } -function jappixmini_addon_get_client_secret() { - client_secret = getDB('jappix-mini', 'client_secret'); +function jappixmini_addon_get_client_secret(callback) { + client_secret = getDB('jappix-mini', 'client-secret'); if (client_secret===null) { - div = $('
Retype your Friendica password for chatting:
'); - div.append($("
")); - input = $('') - div.append(input); - button = $(''); + div = document.getElementById("#jappixmini-password-query-div"); + + if (!div) { + div = $('
Retype your Friendica password for chatting:
'); + + input = $('') + div.append(input); + + button = $(''); + div.append(button); + + $("body").append(div); + } + button.click(function(){ - password = input.val(); + password = $("#jappixmini-password-query-input").val(); jappixmini_addon_set_client_secret(password); div.remove(); + + client_secret = getDB('jappix-mini', 'client-secret'); + callback(client_secret); }); - div.append(button); - $("body").append(div); } - - return client_secret; + else { + callback(client_secret); + } } -function jappixmini_addon_encrypt_password(password) { - client_secret = jappixmini_addon_get_client_secret(); - - // add \0 to password until it has the same length as secret - if (password.length>client_secret.length-1) throw "password too long"; - while (password.lengthclient_secret.length-1) throw "password too long"; + while (password.length