diff options
author | Struan Donald <struan@exo.org.uk> | 2012-11-22 16:08:42 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-11-22 16:08:42 +0000 |
commit | 9ad3b72c6177216022d3ec4747ef0d7ffcd3dbb9 (patch) | |
tree | 281d526ba9b22eef0dbaaf6b498448806ae0a00a /web | |
parent | 0754d06f830c9eaf148ee276def1a80cbc04e83b (diff) | |
parent | 8db5951dee5a41ae6dbe428f779f01d94c3b079b (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'web')
-rw-r--r-- | web/cobrands/fixmybarangay/message_manager_client.js | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/web/cobrands/fixmybarangay/message_manager_client.js b/web/cobrands/fixmybarangay/message_manager_client.js index fa04063c8..ba7383933 100644 --- a/web/cobrands/fixmybarangay/message_manager_client.js +++ b/web/cobrands/fixmybarangay/message_manager_client.js @@ -133,12 +133,36 @@ var message_manager = (function() { } }; - // btoa doesn't work on all browers? var make_base_auth = function(user, password) { var tok = user + ':' + password; - var hash = btoa(tok); + var hash = encodeBase64(tok); // window.btoa(tok) doesn't work on all browers return "Basic " + hash; }; + + function encodeBase64(input) { + var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', + INVALID_CHARACTER_ERR = (function () { + // fabricate a suitable error object + try { + document.createElement('$'); + } catch (error) { + return error; + } + }()), + block, charCode, idx, map, output; + // encoder (with wee change by mhl Mark to satisfy jslint) + // [https://gist.github.com/999166] by [https://github.com/nignag] + for (idx = 0, map = chars, output = ''; + input.charAt(idx | 0) || ((map = '=') && (idx % 1)); + output += map.charAt(63 & block >> 8 - idx % 1 * 8)) { + charCode = input.charCodeAt(idx += 3/4); + if (charCode > 0xFF) { + throw INVALID_CHARACTER_ERR; + } + block = block << 8 | charCode; + } + return output; + } var get_current_auth_credentials = function() { var base_auth = ""; |