Skip to content

Commit 7cf025c

Browse files
author
Ben Newman
committed
working
1 parent a8d2aa5 commit 7cf025c

5 files changed

Lines changed: 91 additions & 84 deletions

File tree

docs/client/data.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@ DocsData = {
99
"scope": "global",
1010
"summary": "The namespace for all server-side accounts-related methods."
1111
},
12+
"Accounts.AccountsCommon#onLogin": {
13+
"filepath": "accounts-base/accounts_common.js",
14+
"kind": "function",
15+
"lineno": 51,
16+
"locus": "Anywhere",
17+
"longname": "Accounts.AccountsCommon#onLogin",
18+
"memberof": "Accounts",
19+
"name": "AccountsCommon#onLogin",
20+
"options": [],
21+
"params": [
22+
{
23+
"description": "<p>The callback to be called when login is successful.</p>",
24+
"name": "func",
25+
"type": {
26+
"names": [
27+
"function"
28+
]
29+
}
30+
}
31+
],
32+
"scope": "static",
33+
"summary": "Register a callback to be called after a login attempt succeeds."
34+
},
1235
"Accounts.changePassword": {
1336
"filepath": "accounts-password/password_client.js",
1437
"kind": "function",
@@ -467,10 +490,23 @@ DocsData = {
467490
"scope": "static",
468491
"summary": "Marks the user's email address as verified. Logs the user in afterwards."
469492
},
493+
"AccountsCommon#userId": {
494+
"filepath": "accounts-base/accounts_common.js",
495+
"kind": "function",
496+
"lineno": 41,
497+
"locus": "Anywhere but publish functions",
498+
"longname": "AccountsCommon#userId",
499+
"memberof": "AccountsCommon",
500+
"name": "userId",
501+
"options": [],
502+
"params": [],
503+
"scope": "instance",
504+
"summary": "Get the current user id, or `null` if no user is logged in. A reactive data source."
505+
},
470506
"Ap.config": {
471507
"filepath": "accounts-base/accounts_common.js",
472508
"kind": "function",
473-
"lineno": 112,
509+
"lineno": 125,
474510
"locus": "Anywhere",
475511
"longname": "Ap.config",
476512
"memberof": "Ap",
@@ -605,33 +641,10 @@ DocsData = {
605641
"scope": "static",
606642
"summary": "Register a function to call when an account enrollment link is\nclicked in an email sent by\n[`Accounts.sendEnrollmentEmail`](#accounts_sendenrollmentemail).\nThis function should be called in top-level code, not inside\n`Meteor.startup()`."
607643
},
608-
"Ap.onLogin": {
609-
"filepath": "accounts-base/accounts_common.js",
610-
"kind": "function",
611-
"lineno": 242,
612-
"locus": "Anywhere",
613-
"longname": "Ap.onLogin",
614-
"memberof": "Ap",
615-
"name": "onLogin",
616-
"options": [],
617-
"params": [
618-
{
619-
"description": "<p>The callback to be called when login is successful.</p>",
620-
"name": "func",
621-
"type": {
622-
"names": [
623-
"function"
624-
]
625-
}
626-
}
627-
],
628-
"scope": "static",
629-
"summary": "Register a callback to be called after a login attempt succeeds."
630-
},
631644
"Ap.onLoginFailure": {
632645
"filepath": "accounts-base/accounts_common.js",
633646
"kind": "function",
634-
"lineno": 251,
647+
"lineno": 255,
635648
"locus": "Anywhere",
636649
"longname": "Ap.onLoginFailure",
637650
"memberof": "Ap",
@@ -674,19 +687,6 @@ DocsData = {
674687
"scope": "static",
675688
"summary": "Register a function to call when a reset password link is clicked\nin an email sent by\n[`Accounts.sendResetPasswordEmail`](#accounts_sendresetpasswordemail).\nThis function should be called in top-level code, not inside\n`Meteor.startup()`."
676689
},
677-
"Ap.userId": {
678-
"filepath": "accounts-base/accounts_common.js",
679-
"kind": "function",
680-
"lineno": 41,
681-
"locus": "Anywhere but publish functions",
682-
"longname": "Ap.userId",
683-
"memberof": "Ap",
684-
"name": "userId",
685-
"options": [],
686-
"params": [],
687-
"scope": "static",
688-
"summary": "Get the current user id, or `null` if no user is logged in. A reactive data source."
689-
},
690690
"Ap.validateLoginAttempt": {
691691
"filepath": "accounts-base/accounts_server.js",
692692
"kind": "function",
@@ -4572,7 +4572,7 @@ DocsData = {
45724572
"Meteor.user": {
45734573
"filepath": "accounts-base/accounts_common.js",
45744574
"kind": "function",
4575-
"lineno": 61,
4575+
"lineno": 74,
45764576
"locus": "Anywhere but publish functions",
45774577
"longname": "Meteor.user",
45784578
"memberof": "Meteor",

docs/client/full-api/tableOfContents.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ var toc = [
127127
{name: "{{loggingIn}}", id: "template_loggingin"},
128128
{type: "spacer"},
129129

130+
{instance: "Accounts", name: "userId", id: "accounts_userId"},
131+
130132
"Accounts.config",
131133
"Accounts.ui.config",
132134
"Accounts.validateNewUser",

docs/client/names.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
"Accounts",
33
"Accounts",
4+
"Accounts.AccountsCommon#onLogin",
45
"Accounts.changePassword",
56
"Accounts.createUser",
67
"Accounts.emailTemplates",
@@ -13,14 +14,13 @@
1314
"Accounts.ui",
1415
"Accounts.ui.config",
1516
"Accounts.verifyEmail",
17+
"AccountsCommon#userId",
1618
"Ap.config",
1719
"Ap.onCreateUser",
1820
"Ap.onEmailVerificationLink",
1921
"Ap.onEnrollmentLink",
20-
"Ap.onLogin",
2122
"Ap.onLoginFailure",
2223
"Ap.onResetPasswordLink",
23-
"Ap.userId",
2424
"Ap.validateLoginAttempt",
2525
"Ap.validateNewUser",
2626
"App",

packages/accounts-base/accounts_common.js

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,57 @@
33
// @param options {Object} an object with fields:
44
// - connection {Object} Optional DDP connection to reuse.
55
// - 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 = {};
2211

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 || {});
2816

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+
});
3423

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+
}
3635

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;
4457

4558
Ap.user = function () {
4659
var userId = this.userId();
@@ -234,15 +247,6 @@ Ap._tokenExpiresSoon = function (when) {
234247
return new Date() > (new Date(when) - minLifetimeMs);
235248
};
236249

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-
246250
/**
247251
* @summary Register a callback to be called after a login attempt fails.
248252
* @locus Anywhere

packages/accounts-base/package.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Package.describe({
55

66
Package.onUse(function (api) {
77
api.use('underscore', ['client', 'server']);
8+
api.use('ecmascript', ['client', 'server']);
89
api.use('ddp-rate-limiter');
910
api.use('localstorage', 'client');
1011
api.use('tracker', 'client');

0 commit comments

Comments
 (0)