Node-Red Multiple Contexts - javascript

I have a Node-Red Application.
A user logs in with credentials stored in a sqlite database.
Based on the information returned from the database it sets a bunch of variables for use in other flows.
flow.set('sid', userid);
flow.set('fname',forename);
flow.set('sname',surname);
However, if another user logs in at the same time, all of these variables are reset to belong to the User 2 and therefor, user 1 now has all of user 2's information.
Is there a way to set variables, so that both can exist at the same time, so that each time a user visits the application they have their own context of it?
Any help here would be appreciated

A node-red flow has no inherent knowledge of 'who' is triggering it. That is an application level detail.
Assuming you have a way to identify the user that has triggered a flow, you can use that information to build unique context keys for them.
For example, let's say msg.req.user contains a unique id for the user. You could then do:
flow.set(msg.req.user+':sid', userid);
flow.set(msg.req.user+':fname',forename);
flow.set(msg.req.user+':sname',surname);

Related

Looping with Firestore querying [Web/Javascript]

How would I go about setting up a loop to query through my Firestore database structure? I don't believe I'm allowed to post pictures or links yet, so I'll try to give some path examples here. Note that there is a lot more to it than these examples.
Rating->Arrow->Arrow-Rating->(user ID)->(data fields)show_name, user_id, rating
Rating->Arrow->Arrow-Rating->(different user ID)->(data fields)show_name, user_id, rating
......
Rating->Flash->Flash-Rating->(user ID)->((data fields)show_name, user_id, rating<br />
......
To give a quick rundown of what this is all about, I'm trying to develop a mock site (with functionality) for a project, where I can display user created information (user info is created from a concurrently developed Android application) such as ratings.
Basically what I'm trying to do is get and display the average rating for each show, by getting each 'rating' field from each user in the respective "Rating" paths... i.e., getting a user rating from each show (Show-Rating->User ID/(data fields)), going to the next user from the same show, and then going to the next show and doing the same.
I'm just not entirely sure how to start going about this.
I suggest you use a cloud function that listens for changes in the ratings node. Use OnUpdate listener
Store every movie rating in its own node, and only query that node for the rating
This will reduce a lot of computation on the client side and will also be more efficient
Use this guide that describes a distributed counter

Mixpanel: alias on a known user

I can:
assign a temporary ID to an unlogged user,
collect events
use alias to keep track of the user (all the events appear in the mixpanel people section).
My problem is that if
the user logout, and the cookies gets cleaned out,
when my user come back I assign a new temporary ID to my unlogged user
than it logs in again,
so I use the alias again (with an unknown temp ID and a known user ID) but mixpanel is not able to link that it was the same user again.
These events are lost, they appear nowhere in the people section.
Is it because I explicitly set the distinct_id property of my user (in the mixpanel.track method) ? or it is just not possible to do this operation of tracing unlogged operation and finally realizing that it was a known user ?
If user LogOut there is no way to tie his activity between LogOut and LogIn after cleaning cookies. So this is how Mixpanel's user identification model works together with cookies.
According to Mixpanel documentation - you should use alias() only once in a user lifetime after Signing Up (Registering).
If you use alias() on the last step - Mixpanel will ignore it.
You must use identify() method instead of alias(), but of course Mixpanel will accept only events fired up after indentifying user.
This scenario is described here in Advanced Aliasing: https://mixpanel.com/docs/integration-libraries/using-mixpanel-alias
Their example says about user coming back from Phone insted of PC, but clearing browser cookies means anonymizing (like using another device).
In any general scenario LogOut should not lead to resetting mixpanel's cookies. Can you provide more specific information? Maybe there is a way not to reset them?
For example in my project one device can be used by many users, so this works just fine for me.

How do I do anonymous Firebase logins which allow browser refresh?

I'm doing a javascript single-page app which allows people to log in, either via twitter or (for some use cases) anonymously.
A very important thing to figure out was how to let them reload the page -- this shouldn't force them to log back in!
I figured this out pretty quickly for the twitter login, and so it uses cookie-stored information to log back in (specifically, the user_id, oauth_token and oauth_token_secret).
However, I can't seem to make this work with the anonymous login facility.
I tried:
auth.login("anonymous", {
user_id: #get("userId"),
firebase_auth_token: #get("firebaseAuthToken")
});
but it doesn't work... I get a new anonymous user ID. I want to keep the same one for the duration of the user's browser session.
And yeah, I tried both user_id and id, firebaseAuthToken and firebase_auth_token.
Thanks!
By default, sessions are created any time you successfully log in a user, and last up until the session expiration time configured under the 'Auth' tab in Forge. This built-in sessioning applies to all Simple Login authentication types, and is automatic as long as local storage and cookies are available.
To resume a session, simply instantiate the FirebaseSimpleLogin object with a Firebase reference and callback. If a local session exists, the callback will be invoked with the same payload you would see if you had just logged the user in for the first time. Invoking the login method will always generate a brand new auth. flow regardless of current user authentication state or session.
Note that in anonymous auth, once a user session expires it cannot be recovered. This may change in the future or some additional functionality may be added to enable it, but it is currently only logged-in to once per user id.

Dropping a Mongo Database Collection in Meteor

Is there any way to drop a Mongo Database Collection from within the server side JavaScript code with Meteor? (really drop the whole thing, not just Meteor.Collection.remove({}); it's contents)
In addition, is there also a way to drop a Meteor.Collection from within the server side JavaScript code without dropping the corresponding database collection?
Why do that?
Searching in the subdocuments (subdocuments of the user-document, e.g. userdoc.mailbox[12345]) with underscore or similar turns out quiet slow (e.g. for large mailboxes).
On the other hand, putting all messages (in context of the mailbox-example) of all users in one big DB and then searching* all messages for one or more particular messages turns out to be very, very slow (for many users with large mailboxes), too.
There is also the size limit for Mongo documents, so if I store all messages of a user in his/her user-document, the mailbox's maximum size is < 16 MB together with all other user-data.
So I want to have a database for each of my user to use it as a mailbox, then the maximum size for one message is 16 MB (very acceptable) and I can search a mailbox using mongo queries.
Furthemore, since I'm using Meteor, it would be nice to then have this mongo db collection be loaded as Meteor.Collection whenever a user logs in. When a user deactivates his/her account, the db should of course be dropped, if the user just logs out, only the Meteor.Collection should be dropped (and restored when he/she logs in again).
To some extent, I got this working already, each user has a own db for the mailbox, but if anybody cancels his/her account, I have to delete this particular Mongo Collection manually. Also, I have do keep all mongo db collections alive as Meteor.Collections at all times because I cannot drop them.
This is a well working server-side code snippet for one-collection-per-user mailboxes:
var mailboxes = {};
Meteor.users.find({}, {fields: {_id: 1}}).forEach(function(user) {
mailboxes[user._id] = new Meteor.Collection("Mailbox_" + user._id);
});
Meteor.publish("myMailbox", function(_query,_options) {
if (this.userId) {
return mailboxes[this.userId].find(_query, _options);
};
});
while a client just subscribes with a certain query with this piece of client-code:
myMailbox = new Meteor.Collection("Mailbox_"+Meteor.userId());
Deps.autorun(function(){
var filter=Session.get("mailboxFilter");
if(_.isObject(filter) && filter.query && filter.options)
Meteor.subscribe("myMailbox",filter.query,filter.options);
});
So if a client manipulates the session variable "mailboxFilter", the subscription is updated and the user gets a new bunch of messages in the minimongo.
It works very nice, the only thing missing is db collection dropping.
Thanks for any hint already!
*I previeously wrote "dropping" here, which was a total mistake. I meant searching.
A solution that doesn't use a private method is:
myMailbox.rawCollection().drop();
This is better in my opinion because Meteor could randomly drop or rename the private method without any warning.
You can completely drop the collection myMailbox with myMailbox._dropCollection(), directly from meteor.
I know the question is old, but it was the first hit when I searched for how to do this
Searching in the subdocuments...
Why use subdocuments? A document per user I suppose?
each message must be it's own document
That's a better way, a collection of messages, each is id'ed to the user. That way, you can filter what a user sees when doing publish subscribe.
dropping all messages in one db turns out to be very slow for many users with large mailboxes
That's because most NoSQL DBs (if not all) are geared towards read-intensive operations and not much with write-intensive. So writing (updating, inserting, removing, wiping) will take more time.
Also, some online services (I think it was Twitter or Yahoo) will tell you when deactivating the account: "Your data will be deleted within the next N days." or something that resembles that. One reason is that your data takes time to delete.
The user is leaving anyway, so you can just tell the user that your account has been deactivated, and your data will be deleted from our databases in the following days. To add to that, so you can respond to the user immediately, do the remove operation asynchronously by sending it a blank callback.

Get username using javascript in pdf

I was wondering if it was possible to grab the username of the account logged into the computer. I wanted to print the username of the person that is printing out the pdf file.
I was thinking about trying to grab the %username% environment variable. Does not seem to be possible.
In Acrobat JavaScript, many local system parameters are considered privileged. The user's login name is one of these. In order to access the "identity" object the JavaScript code has to be executed from a trusted context. Code inside a PDF doesn't qualify. Or at least it doesn't normally. If the local system user has given explicit permission to the PDF, then it can access privileged data. But obviously this isn't a general purpose solution. Typically the "identity" object is only accessible to Folder Level Automation scripts.
Thom Parker
www.pdfscripting.com
take a look a the identity object.
name = identity.name; //gives you the user name that the user entered in the Identity preferences panel
userName = identity.loginName; //login name as registered by the operating system
This may be possible to some extent server-side. Here's an NTLM auth module for Apache/Unix, and here's one for Apache/Windows.

Categories

Resources