aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/cobrands/fixmybarangay/message_manager_client.js28
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 = "";