forked from artwells/meteor-accounts-guest
-
Notifications
You must be signed in to change notification settings - Fork 4
/
accounts-anonymous-server.js
45 lines (37 loc) · 1.13 KB
/
accounts-anonymous-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict";
/* globals AccountsAnonymous, AccountsMultiple, Hook */
Accounts.registerLoginHandler("anonymous", function(options) {
if (!options || !options.anonymous || Meteor.userId()) {
return undefined;
}
var newUserId = Accounts.insertUserDoc(options, {});
return {
userId: newUserId
};
});
AccountsAnonymous._onAbandonedHook = new Hook({
bindEnvironment: false,
debugPrintExceptions: "AccountsAnonymous.onAbandoned callback"
});
AccountsAnonymous.onAbandoned = function(func) {
var self = this;
return self._onAbandonedHook.register(func);
};
var callbackSet = {
onSwitch: function(attemptingUser /* , attempt (unused) */) {
if (isAnonymous(attemptingUser)) {
AccountsAnonymous._onAbandonedHook.each(function(callback) {
callback(attemptingUser);
return true;
});
}
}
};
AccountsAnonymous._init = function() {
AccountsMultiple.register(callbackSet);
};
AccountsAnonymous._init();
function isAnonymous(user) {
// A user is anonymous if they don't have any services other than "resume"
return (user.services && _.size(user.services) === 1 && user.services.resume);
}