Using browser module to submit form in node.js - forms

I used the browser module (https://github.com/shinout/browser) to test form submission in node.js and it was successful by running the following code:
var $b = new browser();
$b.submit({
from : 'https://accounts.google.com/Login',
selector: "#gaia_loginform",
data : {
Email : "XXXXXX#gmail.com",
Passwd : "XXXXXXXX"
}
});
// authenticated access
$b.browse('https://mail.google.com/mail/u/0/?ui=html&zy=d')
.after(); // browse after previously registered function
$b.on("end", function(err, out) {
console.log(out.url, out.result, out.responseHeaders);
});
$b.run();
But when I add additional code after $b.run()
$b.browse('https://mail.google.com').after();
$b.run();
I got the following error:
Junjo.register cannot be called when the template is frozen.
I don't know why. Any help would be appreciated.

From what I was able to read from sources, the browser module does not support running multiple jobs with single browser instance. Method $b.run() marks the object as frozen, which causes methods like browse to throw the error you are getting.

Related

Cannot get my collection's data in meteor client side js in Meteor

I have written the following code in my client side js:
var resolutionsQ;
Template.body.onCreated(function bodyOnCreated() {
resolutionsQ = new Mongo.Collection("res");
});
Template.body.helpers({
resolutions: function() {
var res = resolutionsQ.find({});
console.log(res);
return resolutionsQ.find({});
}
});
Then in my project folder(in terminal), i wrote:
meteor mongo
After the mongo db console started, I worte:
db.res.insert({title: "hello #1", createdAt: new Date()});
This also worked.
When I wrote this, my frontend application showed everything as expected. Then I shut down my computer, and after sometime switched it on again and tried to run my meteor application. Now I see nothing, I get no error either in server console or browser's console. I don't know what went wrong then.
Please help.
You've created a client-side collection by defining the collection only in client code. A collection needs to be defined on both the server and the client in order to persist documents to the database.
The quick solution is to create a shared file like lib/collections/resolutions.js which will contain:
Resolutions = new Mongo.Collection("resolutions");
Using the new-style imports mechanism, you would create a file like imports/api/resolutions/resolutions.js which will contain:
import { Mongo } from 'meteor/mongo';
export const Todos = new TodosCollection('Todos');
See this section of the guide for more details.

How to correctly set up session with everyauth and express?

I am trying to build a simple nodejs app that can log in with facebook using express and everyauth. Following the README tutorial here, I've performed the following setup in app.js:
var everyauth = require('everyauth');
everyauth.facebook
.appId('829428097067274')
.appSecret('2c4d4a96514aa8374fbc54d611945148')
.findOrCreateUser(function (session, accessToken, accessTokExtra, fbUserMetadata) {
// I will fill this in with something real later, but for now
// I just want something that works with a fake session
console.log("in find or create user")
// this is always undefined...
console.log(session);
// these look good; I'm getting real user info
console.log(accessToken);
console.log(accessTokExtra);
console.log(fbUserMetadata);
// I'm not sure what I need to return here. I've tried
// variations of this.Promise()/promise.fulfill() as well
return { id: 100, session: "the session" };
})
.redirectPath('/');
// ...
// this gives an error saying that session is no longer
// bundled with express, but I'm not sure which package to replace
// it with:
// app.use(express.session());
app.use(everyauth.middleware(app));
When I launch my app, I visit localhost:3000/auth/facebook, which correctly redirects to facebook. I authorize the app there, which redirects me to localhost:3000/auth/facebook/callback. However, here my app logs an error of:
Step getSession offacebookis promising: session ; however, the step returns nothing. Fix the step by returning the expected values OR by returning a Promise that promises said values.
What am I doing wrong?
It's late, but still talk about this that I also struggled with everyauth and express 4.x.
If you are using express 4.x, install express-session by npm install express-session
using the following code, some other code is the same as the example by the everyauth.
var session = require('express-session');
...
var app = express();
app.use(session({secret : "anything you want"}));
app.use(everyauth.middleware());

passport.socketio's passport "Failed to deserialize user out of session". But passport in my main app (with the same key) deserializes just fine

passport.socketio throwing this error, while failing to authorize the user.
Error: Error: Failed to deserialize user out of session
I've narrowed the problem down to passport.socketio's /lib/index.js.
At line 59
auth.passport.deserializeUser(userKey, function(err, user) {
if (err)
return auth.fail(data, err, true, accept);
...
It throws that error. Debugger tells me the userKey is valid, and should deserialize the user. It's the same key that passport in my main app uses to deserialize the user. (it's the ID of mongoDB object). And passport in my main app has no problem deserializing the user. (details)
So don't know why this still throws the error.
The userKey passed here is the same key passport in my main app uses to deserialize.
I've gone to the extent of making the userKey global and putting it in my main code
passport.deserializeUser(global.userKey, function(err, user) {
if (err)
return auth.fail(data, err, true, accept);
console.log('ok');
Which results in infinite loop (because it's inside outer passport.deserialize) but iut prints 'ok'!, so passport from my main app can atleast deserialize just fine using the same thing that passport from index.js (passport.socketio\lib\index.js) can not! .. for some reason.
Then I've even tried passing the passport object itself from main app
io.set('authorization', require('passport.socketio').authorize({
passport: passport,
...
which actually results in no errors!! but then I don't get the socket.handshake object.
I'm out of ideas to diagnose this any further and would really appreciate any help whatsoever.
What could be causing passport.socketio's passport to not "deserialize user out of session"?
Deleted npm_modules, re-wrote the packages.json with "every_package":"latest", and so basically re-installed every package's latest version. That fixed it.
One problem could be that you have configured your 'passport' instance in the main app to use a specific 'deserializeUser' implementation. look for all the places where your passport has been intiallized in the main app. (If its a framework like mean.io, you will find it in config/passport.js).
Make sure the same initiallization is done to the passport instance in the socket app. Pass it to passportsocketio as such:
passportSocketIo.authorize({
passport: passport,
cookieParser: express.cookieParser,
key: 'connect.sid'
...
});

Firefox Addon sdk : comunication between different contentScripts

I have two content Scripts in main.js of Firefox Addon :
contentScript A is inside 'panel' module (module A)
contentScript B is inside 'page-mod' module (module B)
How can they communicate or exchange messages ?
I tried to do this by using the following steps : 1. sending message from contentScript A to AddonScript A 2. sending message from AddonScript A to AddonScript B by including module B in A 3. sending message from AddonScript B to contentScript B.
However , it doesn't work (rather it does work intermittently , may be due to some errors in code).
.
Is this method ok ?
Can any one please comment on any better method ?
.
Thanx
Due to how the SDK's security model, any communication between your panel and your page-mod need to be routed through the main add-on code itself. Here is an example that takes data from a form implemented in a Panel and sends it through the main script into a page-mod:
https://builder.addons.mozilla.org/addon/1035008/latest/
The key piece of code is this one:
var pagemod = require("page-mod").PageMod({
include: [target],
contentScriptFile: [data.url('jquery-1.7.1.min.js'), data.url('page-mod.js')],
onAttach: function(worker) {
// console.log('attached...');
// when we get a panel-message event from the panel
panel.port.on('panel-message', function(data) {
// we emit the same message through to the page-mod
worker.port.emit('panel-message', data);
});
}
});
You'll notice that, when the page-mod is attached, I set up the panel instance to catch the 'panel-message' event and then emit it directly into the current page-mod worker.

Strange issue submitting form with ExtJS

I have worked some time now with ExtJS and never had a problem with submitting form. But now there is a form that is not making the POST call to the php file. And is returning me failure.
onSaveBtn : function() {
var formPanel = this.getComponent('planillaForm');
if (formPanel.getForm().isValid()) {
var vals = formPanel.getValues();
var msg = String.format(
this.msgs.saving,
vals.codigo
);
this.el.mask(msg, 'x-mask-loading');
formPanel.getForm().submit({
url : 'sistema/planilla/setPlanilla.php',
scope : this,
success : this.onFormSaveSuccess,
failure : this.onFormSaveFailure
});
}
else {
Ext.MessageBox.alert(
'Error!',
this.msgs.errorsInForm
);
}
}
I have always worked with this "template" for Form submitting and it have never failed. I dont know what is happening but he never makes the POST and it jumps to the failure function "onFormSaveFailure". I have changed the url and nothing. I dont know what to do and I am kinda in a hurry. Please help.
There could be one of many things going on. You will need to debug it further. These are the steps I would do :
Make sure the URL is valid. I would use fiddler (or a similar program) to look at my request. Make sure the URL I am trying to submit to is valid. The likely problem there is that you are using a relative path for your url, it uses the current url as the context.
Make sure the php file is getting hit (break point, print statement...).
Make sure the php file is not crashing, exceptions thrown from the server side would result in the failure function getting called.
Make sure the php file is returning something that indicates success. If the returning JSON string has {success : false} the request would be considered to be fail.
the this.onFormSaveFailure function takes in 2 parameters : "form" and "action", the "action" object has a "failureType", use a javascript debugger to look at the value of that.