var callback = function(user) {
// user's an object with members anon and name
// user.anon is true if the current user is not logged in
};
config.extensions.tiddlyweb.getUserInfo(callback);
Combined with the recent snippet about retrieving space members*:
config.extensions.tiddlyweb.getUserInfo(function(user) {
if(user.anon) {
// unknown visitor
} else {
var host = config.extensions.tiddlyweb.host;
var space = config.extensions.tiddlyspace.currentSpace.name;
space = new tiddlyweb.Space(space, host);
space.members().get(function(members, status, xhr) {
if(members.contains(user.name)) {
// space member
} else {
// logged-in user
}
}, errback); // error callback to be defined
}
});
-- F.
* http://groups.google.com/group/tiddlywiki/msg/1184193d6e685b6c
That's right.
> Would you think, too, that it made sense to turn this into a global
> utility function in the TiddlySpace core? ...returning the visitor
> status with respect to a space ...which as of today would thus be one
> of 'member', 'user' or otherwise 'anon'
That sounds reasonable - however, I just realized that I was
overcomplicating things:
// set global read-only mode based on membership heuristics
var indicator = store.getTiddler("SiteTitle") || tiddler;
readOnly = !(recipe.split("_").pop() == "private" ||
tweb.hasPermission("write", indicator));
That's an excerpt from TiddlySpaceConfig - so you just have to check
read-only mode (plus employ getUserInfo if you want to distinguish
between anonymous visitors and non-members).
(Aside: There's a logic error in the snippet I'd posted. The else branch
in the members callback would never be executed, as the list of members
is only accessible to space members - so that would move into the
errback instead.)
-- F.
While I understand the impulse, I'm not keen on this - it seems to
conflate different concerns.
Your use case of distinguishing between visitors, users and members
seems unique at this point - generally it's either anonymous vs. logged
in or member vs. non-member.
I'd be happy to be convinced otherwise - other devs are encouraged to
chime in.
-- F.
I'd also be inclined to feature test "is this space read-only" or "can
I see private content" than worry about the roles which lead to these
capabilities ..
--
Paul (psd)
http://blog.whatfettle.com