|
3 | 3 | // @param options {Object} an object with fields: |
4 | 4 | // - connection {Object} Optional DDP connection to reuse. |
5 | 5 | // - ddpUrl {String} Optional URL for creating a new DDP connection. |
6 | | -AccountsCommon = function _AccountsCommon(options) { |
7 | | - // Currently this is read directly by packages like accounts-password |
8 | | - // and accounts-ui-unstyled. |
9 | | - this._options = {}; |
10 | | - |
11 | | - // Note that setting this.connection = null causes this.users to be a |
12 | | - // LocalCollection, which is not what we want. |
13 | | - this.connection = undefined; |
14 | | - this._initConnection(options || {}); |
15 | | - |
16 | | - // There is an allow call in accounts_server.js that restricts writes to |
17 | | - // this collection. |
18 | | - this.users = new Mongo.Collection("users", { |
19 | | - _preventAutopublish: true, |
20 | | - connection: this.connection |
21 | | - }); |
| 6 | +AccountsCommon = class AccountsCommon { |
| 7 | + constructor(options) { |
| 8 | + // Currently this is read directly by packages like accounts-password |
| 9 | + // and accounts-ui-unstyled. |
| 10 | + this._options = {}; |
22 | 11 |
|
23 | | - // Callback exceptions are printed with Meteor._debug and ignored. |
24 | | - this._onLoginHook = new Hook({ |
25 | | - bindEnvironment: false, |
26 | | - debugPrintExceptions: "onLogin callback" |
27 | | - }); |
| 12 | + // Note that setting this.connection = null causes this.users to be a |
| 13 | + // LocalCollection, which is not what we want. |
| 14 | + this.connection = undefined; |
| 15 | + this._initConnection(options || {}); |
28 | 16 |
|
29 | | - this._onLoginFailureHook = new Hook({ |
30 | | - bindEnvironment: false, |
31 | | - debugPrintExceptions: "onLoginFailure callback" |
32 | | - }); |
33 | | -}; |
| 17 | + // There is an allow call in accounts_server.js that restricts writes to |
| 18 | + // this collection. |
| 19 | + this.users = new Mongo.Collection("users", { |
| 20 | + _preventAutopublish: true, |
| 21 | + connection: this.connection |
| 22 | + }); |
34 | 23 |
|
35 | | -var Ap = AccountsCommon.prototype; |
| 24 | + // Callback exceptions are printed with Meteor._debug and ignored. |
| 25 | + this._onLoginHook = new Hook({ |
| 26 | + bindEnvironment: false, |
| 27 | + debugPrintExceptions: "onLogin callback" |
| 28 | + }); |
| 29 | + |
| 30 | + this._onLoginFailureHook = new Hook({ |
| 31 | + bindEnvironment: false, |
| 32 | + debugPrintExceptions: "onLoginFailure callback" |
| 33 | + }); |
| 34 | + } |
36 | 35 |
|
37 | | -/** |
38 | | - * @summary Get the current user id, or `null` if no user is logged in. A reactive data source. |
39 | | - * @locus Anywhere but publish functions |
40 | | - */ |
41 | | -Ap.userId = function () { |
42 | | - throw new Error("userId method not implemented"); |
43 | | -}; |
| 36 | + |
| 37 | + /** |
| 38 | + * @summary Get the current user id, or `null` if no user is logged in. A reactive data source. |
| 39 | + * @locus Anywhere but publish functions |
| 40 | + */ |
| 41 | + userId() { |
| 42 | + throw new Error("userId method not implemented"); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @summary Register a callback to be called after a login attempt succeeds. |
| 47 | + * @memberof Accounts |
| 48 | + * @locus Anywhere |
| 49 | + * @param {Function} func The callback to be called when login is successful. |
| 50 | + */ |
| 51 | + onLogin(func) { |
| 52 | + return this._onLoginHook.register(func); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +var Ap = AccountsCommon.prototype; |
44 | 57 |
|
45 | 58 | Ap.user = function () { |
46 | 59 | var userId = this.userId(); |
@@ -234,15 +247,6 @@ Ap._tokenExpiresSoon = function (when) { |
234 | 247 | return new Date() > (new Date(when) - minLifetimeMs); |
235 | 248 | }; |
236 | 249 |
|
237 | | -/** |
238 | | - * @summary Register a callback to be called after a login attempt succeeds. |
239 | | - * @locus Anywhere |
240 | | - * @param {Function} func The callback to be called when login is successful. |
241 | | - */ |
242 | | -Ap.onLogin = function (func) { |
243 | | - return this._onLoginHook.register(func); |
244 | | -}; |
245 | | - |
246 | 250 | /** |
247 | 251 | * @summary Register a callback to be called after a login attempt fails. |
248 | 252 | * @locus Anywhere |
|
0 commit comments