Mercurial > hg > OKFNAnnotator
comparison annotator_files/lib/plugin/auth.js @ 4:6979313586cf
new version of annotator.
author | casties |
---|---|
date | Mon, 27 Aug 2012 19:05:38 +0200 |
parents | 6356e78ccf5c |
children |
comparison
equal
deleted
inserted
replaced
3:6356e78ccf5c | 4:6979313586cf |
---|---|
1 // Generated by CoffeeScript 1.3.3 | |
1 var base64Decode, base64UrlDecode, createDateFromISO8601, parseToken, | 2 var base64Decode, base64UrlDecode, createDateFromISO8601, parseToken, |
2 __hasProp = Object.prototype.hasOwnProperty, | 3 __hasProp = {}.hasOwnProperty, |
3 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; | 4 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; |
4 | 5 |
5 createDateFromISO8601 = function(string) { | 6 createDateFromISO8601 = function(string) { |
6 var d, date, offset, regexp, time, _ref; | 7 var d, date, offset, regexp, time, _ref; |
7 regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" + "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" + "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"; | 8 regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" + "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" + "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"; |
8 d = string.match(new RegExp(regexp)); | 9 d = string.match(new RegExp(regexp)); |
9 offset = 0; | 10 offset = 0; |
10 date = new Date(d[1], 0, 1); | 11 date = new Date(d[1], 0, 1); |
11 if (d[3]) date.setMonth(d[3] - 1); | 12 if (d[3]) { |
12 if (d[5]) date.setDate(d[5]); | 13 date.setMonth(d[3] - 1); |
13 if (d[7]) date.setHours(d[7]); | 14 } |
14 if (d[8]) date.setMinutes(d[8]); | 15 if (d[5]) { |
15 if (d[10]) date.setSeconds(d[10]); | 16 date.setDate(d[5]); |
16 if (d[12]) date.setMilliseconds(Number("0." + d[12]) * 1000); | 17 } |
18 if (d[7]) { | |
19 date.setHours(d[7]); | |
20 } | |
21 if (d[8]) { | |
22 date.setMinutes(d[8]); | |
23 } | |
24 if (d[10]) { | |
25 date.setSeconds(d[10]); | |
26 } | |
27 if (d[12]) { | |
28 date.setMilliseconds(Number("0." + d[12]) * 1000); | |
29 } | |
17 if (d[14]) { | 30 if (d[14]) { |
18 offset = (Number(d[16]) * 60) + Number(d[17]); | 31 offset = (Number(d[16]) * 60) + Number(d[17]); |
19 offset *= (_ref = d[15] === '-') != null ? _ref : { | 32 offset *= (_ref = d[15] === '-') != null ? _ref : { |
20 1: -1 | 33 1: -1 |
21 }; | 34 }; |
34 b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | 47 b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; |
35 i = 0; | 48 i = 0; |
36 ac = 0; | 49 ac = 0; |
37 dec = ""; | 50 dec = ""; |
38 tmp_arr = []; | 51 tmp_arr = []; |
39 if (!data) return data; | 52 if (!data) { |
53 return data; | |
54 } | |
40 data += ''; | 55 data += ''; |
41 while (i < data.length) { | 56 while (i < data.length) { |
42 h1 = b64.indexOf(data.charAt(i++)); | 57 h1 = b64.indexOf(data.charAt(i++)); |
43 h2 = b64.indexOf(data.charAt(i++)); | 58 h2 = b64.indexOf(data.charAt(i++)); |
44 h3 = b64.indexOf(data.charAt(i++)); | 59 h3 = b64.indexOf(data.charAt(i++)); |
58 return tmp_arr.join(''); | 73 return tmp_arr.join(''); |
59 } | 74 } |
60 }; | 75 }; |
61 | 76 |
62 base64UrlDecode = function(data) { | 77 base64UrlDecode = function(data) { |
63 var i, m, _ref; | 78 var i, m, _i, _ref; |
64 m = data.length % 4; | 79 m = data.length % 4; |
65 if (m !== 0) { | 80 if (m !== 0) { |
66 for (i = 0, _ref = 4 - m; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) { | 81 for (i = _i = 0, _ref = 4 - m; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { |
67 data += '='; | 82 data += '='; |
68 } | 83 } |
69 } | 84 } |
70 data = data.replace(/-/g, '+'); | 85 data = data.replace(/-/g, '+'); |
71 data = data.replace(/_/g, '/'); | 86 data = data.replace(/_/g, '/'); |
173 'x-annotator-auth-token': this.token | 188 'x-annotator-auth-token': this.token |
174 })); | 189 })); |
175 }; | 190 }; |
176 | 191 |
177 Auth.prototype.withToken = function(callback) { | 192 Auth.prototype.withToken = function(callback) { |
178 if (!(callback != null)) return; | 193 if (!(callback != null)) { |
194 return; | |
195 } | |
179 if (this.haveValidToken()) { | 196 if (this.haveValidToken()) { |
180 return callback(this._unsafeToken); | 197 return callback(this._unsafeToken); |
181 } else { | 198 } else { |
182 this.waitingForToken.push(callback); | 199 this.waitingForToken.push(callback); |
183 if (!this.requestInProgress) return this.requestToken(); | 200 if (!this.requestInProgress) { |
201 return this.requestToken(); | |
202 } | |
184 } | 203 } |
185 }; | 204 }; |
186 | 205 |
187 return Auth; | 206 return Auth; |
188 | 207 |