I'm trying to do a search quest using js-zimbra module, i keep on getting an error that i didn't knew how to fix,
her's my code :
var z = require('js-zimbra');
var comm = new z.Communication({
url: "myzimbraurl/service/soap"
});
// Authenticate
comm.auth({
"username": "user",
"secret": "pass",
"isPassword": true
}, function(err) {
if (err) {
// An error occured authenticating!
}
console.log('done !')
// Now, carry on creating requests and sending them
comm.getRequest({}, function(err, req) {
if (err) {
// Can't create a new request
}
req.addRequest({
name: "SearchRequest",
namespace: "zimbraMail",
params: {
"SearchRequest" : {
"types" : "message",
"fetch" : "all"
},
"query": {
"_content": "in:inbox"
}
}
}, function(err) {
if (err) {
console.log('err', err);
}
comm.send(req, function(err, res) {
if (err) {
console.log('err', err);
}
console.log(res);
})
})
})
});
and when i execute i got the following error message :
error: Received server error: {"Code":{"Value":"soap:Receiver"},"Reason":{"Text":"error while proxying request to target server: Connection reset"},"Detail":{"Error":{"Code":"service.PROXY_ERROR","Trace":"","_jsns":"urn:zimbra"}}}
Is there any fix for such error ?
Related
Why is a successful update response always passed as an error. is something wrong with my code or is it the Mongo DB response.
However I don't see any errors when I check them on MongoDB.
MongoDB Enterprise > db.getLastError();
null
Response:
{
"lastErrorObject": {
"n": 1,
"updatedExisting": true
},
"value": {
"_id": "1111111111",
"xyz": "hgfjdfjk"
}
}
Code Block
{
try {
const db = client.db(dbName);
db.collection(cName).updateOne({ _id: id }, { $pull: query }).then((err, result) => {
if (err) {
callBack(err);
} else {
callBack(null, result);
}
});
client.close();
}
catch (err) {
callBack({
error: 'Unable to process the request',
errorMessage: err
})
}
}
getLastError() returns the server response to the current operation within that connection, and is not related to an actual error in MongoDB. It is part of MongoDB's wire protocol.
See getLastError for more details.
I developped an invoice using ReactJS, nodejs and mysql, it have a dynamic table, as you can see the invoive component in this link : https://codeshare.io/5zqLeN
My router is :
exports.ajouterfact = function(req, res) {
console.log("req", req.body);
var today = new Date();
var factures = {
"Nfact": req.body.Nfact,
"Nom": req.body.Nom,
"Datefact": req.body.Datefact,
"Note": req.body.Note,
"Nomp": req.body.Nomp,
"QuantiteF": req.body.QuantiteF,
}
connection.query('INSERT INTO factures SET ?', factures, function(error, results, fields) {
if (error) {
console.log("error ocurred", error);
res.send({
"code": 400,
"failed": "error ocurred"
})
}
else {
// console.log('The solution is: ', results);
res.send({
"code": 200,
"success": "facture registered sucessfully"
});
}
})
};
My invoice is :
When I submit it, It will be added on the database by getting:
req { Nfact: '15',
Nom: 'Imen',
Datefact: '2018-09-04T09:47:32.925Z',
Note: 'Test',
QuantiteF: '' }
The Noun of product (Nomp) is null and the quantity is ''.
But when I run my backend with Postman, it works well.
How can I fix that ?
I am trying to use hapi-auth-bearer-simple module to enable bearer token on my app. However, I am getting the error shown in the title.
I am trying to implement this module to enable token authorisation in my app But I am getting error mentioned below
e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\node_modules\hoek\lib\index.js:723
I have a route file
module.exports = [
{
method: 'GET',
path: '/api/{_id?}',
handler: function (request, reply) {
Controller.control.get(request.params, function (err, success) {
console.log(request.params);
if (err) {
reply(unifunc.sendError(err));
} else {
reply(unifunc.sendSuccess(SuccessMsg,success)).code(200);
}
});
},
config: {
description: 'desc',
tags: ['api', 'oV'],
validate: {
headers: unifunc.authorizationHeaderObj,
params: {
o_id: Joi.string().required().trim(),
_id: Joi.string().optional().trim()
},
failAction: unifunc.failActionFunction
},
auth: {
strategy: 'bearer',
scope: ['admin', 'user-{params.id}']
},
plugins: {
'hapi-swagger': {
responseMessages: msgs
}](url)
and a controller file in which I mentioned strategy
var bearerSimple= require('hapi-auth-bearer-simple')
authorization = Authorization.auth; // This plugin has the logic to validate the token and return the error in case it fails and I am passing accesstoken as parameter in a function in that file
var getV = function(server, params, callbackRoute){
server.register(
[{
register: bearerSimple
}], function(err){
if(err){
console.log("Failed to log the plugin",err);
throw err;
}
server.auth.strategy('bearer', 'bearerAuth', {
authorization : authorization
});
});
console.log(params);
async.series([
function(cb){}
]}
complete error message is:
Error: Unknown authentication strategy: bearer in path: /api/orders/{order_id}/vehicles/{_id?}
at Object.exports.assert (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\node_modules\hoek\lib\index.js:723:11)
at e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\auth.js:152:14
at Array.forEach (native)
at internals.Auth._setupRoute (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\auth.js:149:24)
at new module.exports.internals.Route (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\route.js:142:47)
at internals.Connection._addRoute (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\connection.js:375:17)
at internals.Connection._route (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\connection.js:367:18)
at wrappedRoute [as _route] (e:\python_training\Training\Node\Test\Project\Backend\node_modules\newrelic\lib\instrumentation\hapi.js:222:29)
at internals.Plugin._apply (e:\python_training\Training\Node\Test\Project\Backend\node_modules\hapi\lib\plugin.js:460:14)
at internals.Plugin.route
Is there any way I can resolve this issue?
Edit:
I modified server.js file and removed the strategy from controller file
I placed strategy in server.js
var validationFunction = Authorization.auth;
console.log(validationFunction);
server.register(
[{
register: bearerSimple
}], function(err){
if(err){
console.log("Failed to log the plugin",err);
throw err;
}
server.auth.strategy('bearer', 'bearerAuth', {
validationFunction : validationFunction
});
});
and in Authorization file looks like this
function rauth(accessToken, cb) {
var criteria = {accessToken: accessToken};
var projection = {};
var options = {limit: 1};
Service.AdminService.getadmin(criteria, projection, options, function (err, data) {
if (err) {
cb(err);
} else if (data && data.length > 0 && data[0]._id) {
console.log(data);
console.log(data.length);
adminId = data[0]._id;
cb()
} else {
cb(UniversalFunctions.CONFIG.APP_CONSTANTS.STATUS_MSG.ERROR.INVALID_ACCESS_TOKEN);
}
});
Now I am getting this error:
Error: options.validateFunc must be a valid function in bearerAuthentication scheme
I have been breaking my head over this problem from days. Could anyone suggest what could be the problem here?
The only problem I found was with the parameters of callback function passed in validateFunction but I can't remove the parameters as those parameters are being defined in another function called getadmin. Could anyone suggest a workaround for this?
Solved in this issue https://github.com/Salesflare/hapi-auth-bearer-simple/issues/69.
The problems were a typo and needed to pass more info back on a successful authorization.
I have connected my Database to auth0 and when I try the connection is returns 401 unauthorized access. I have allowed auth into my firewall and the password is correct. How come it is returning this error when searching for username and password?
More info
in my easy tables I made them authenticated access only, do I have to do something to get around this?
function login(email, password, callback) {
//this example uses the "tedious" library
//more info here: http://pekim.github.io/tedious/index.html
var Connection = require('tedious#1.11.0').Connection;
var Request = require('tedious#1.11.0').Request;
var TYPES = require('tedious#1.11.0').TYPES;
var connection = new Connection({
userName: 'username',
password: 'pass',
server: 'server',
options: {
database: 'db',
encrypt: true,
rowCollectionOnRequestCompletion: true
}
});
var query = "SELECT Id, Email, Password " +
"FROM user WHERE Email = #Email";
connection.on('debug', function (text) {
// Uncomment next line in order to enable debugging messages
// console.log(text);
}).on('errorMessage', function (text) {
console.log(JSON.stringify(text, null, 2));
return callback(text);
}).on('infoMessage', function (text) {
// Uncomment next line in order to enable information messages
// console.log(JSON.stringify(text, null, 2));
});
connection.on('connect', function (err) {
if (err) { return callback(err); }
var request = new Request(query, function (err, rowCount, rows) {
if (err) {
callback(new Error(err));
} else if (rowCount < 1) {
callback(new WrongUsernameOrPasswordError(email));
} else {
bcrypt.compare(password, rows[0][2].value, function (err, isValid) {
if (err) { callback(new Error(err)); }
else if (!isValid) { callback(new WrongUsernameOrPasswordError(email)); }
else {
callback(null, {
user_id: rows[0][0].value,
email: rows[0][1].value
});
}
});
}
});
request.addParameter('Email', TYPES.VarChar, email);
connection.execSql(request);
});
}
Since you are using Azure Mobile App, which included the Node.js server SDK for your app. Then you don't need to install tedious to work with Azure SQL database. The SDK has already wrapped up mssql to do this. So basically you can use this code sample to connect your database.
var api = {
// an example of executing a SQL statement directly
get: (request, response, next) => {
var query = {
sql: 'UPDATE TodoItem SET complete = #completed',
parameters: [
{ name: 'completed', value: request.query.completed }
]
};
request.azureMobile.data.execute(query)
.then(function (results) {
response.json(results);
});
},
// an example of executing a stored procedure
post: (request, response, next) => {
var query = {
sql: 'EXEC completeAllStoredProcedure #completed',
parameters: [
{ name: 'completed', value: request.query.completed }
]
};
request.azureMobile.data.execute(query)
.then(function (results) {
response.json(results);
});
}
};
module.exports = api;
For more information, please refer to this documentation.
On localhost this works fine, but I when I put it on the live server the put requests are not sticking to the database. Specifically with req.body I have to define the attribute I want to send {points: req.body.points}
update: function(req, res) {
console.log("PUT received: " + req.body.points);
models.Player.update({ _id: req.params.pid }, req.body, function(err, player) {
if (err) {
res.json({error: 'Player not found.'});
} else {
res.json(player);
}
});
},
The only way I can get the above to work on the live server is, if I write the object to update like below. This is not good because the app updates more than just points, it may send a put to update {player_name: req.body.player_name} you know what I mean.
I don't understand why req.body isn't working, it usually does!!
update: function(req, res) {
console.log("PUT received: " + req.body.points);
models.Player.update({ _id: req.params.pid }, {points: req.body.points}, function(err, player) {
if (err) {
res.json({error: 'Player not found.'});
} else {
res.json(player);
}
});
},
EDIT: My quick solution was to do this, but I would rather just use the req.body object, whats the reason it's not working?
update: function(req, res) {
var test = {
player_name : req.body.player_name,
player_picture : req.body.player_picture,
bench : req.body.bench,
points : req.body.points,
rebounds : req.body.rebounds,
steals : req.body.steals,
blocks : req.body.blocks,
fouls : req.body.fouls,
team_id : req.body.team_id,
}
models.Player.update({ _id: req.params.pid }, test, function(err, player) {
if (err) {
res.json({error: 'Player not found.'});
} else {
res.json(player);
}
});
},