Hy everyone i'm trying to show a expire_data field of my database with the value "2017-06-01 11:42:00" but in the browser appears "01-06-2017 10:42:26" Why is this happening?
To insert in bd I'm doing
Database.Users.updateUserLastAuthentication(jwtPayload.id, false, moment(jwtPayload.expire*1000).format("YYYY-MM-DD HH:mm"), true);
where
1|wscontro | [2017-06-01 10:45:49.873] - debug: /opt/wscontroller/wscontroller-api passport NA passport jwtPayload.expire "2017-06-01 11:42"
1|wscontro | [2017-06-01 10:45:49.873] - debug: /opt/wscontroller/wscontroller-api/routes/users UsersDatabase NA updateUserLastAuthentication expireDate "2017-06-01 11:42"
My expire_date field is a "timestamp without time zone"
Passport:
module.exports = function (passport) {
var opts = {};
opts.secretOrKey = global.configs.config.databases.ws_controller.password;
opts.jwtFromRequest = extractJwt.fromAuthHeader();
passport.use(new jwtStrategy(opts, function(jwtPayload, done) {
createLog('debug', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'passport', 'jwtPayload', jwtPayload);
console.log("global.getUsers()", wavesysUser);
if(wavesysUser[jwtPayload.id] && wavesysUser[jwtPayload.id][ jwtPayload.tokenId]) {
createLog('debug', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'passport', 'jwtPayload.expire', moment(jwtPayload.expire*1000).format("YYYY-MM-DD HH:mm"));
console.log("Comparing expire with date",jwtPayload.expire,moment().unix());
if(jwtPayload.expire > moment().unix()){
console.log("In time");
Database.Users.updateUserLastAuthentication(jwtPayload.id, true, moment(jwtPayload.expire*1000).format("YYYY-MM-DD HH:mm"), false);
//done(null, false, {error: 'Login failed. Token expired.'});
var user = jwtPayload;
done(null, user);
} else {
console.log("Expired");
Database.Users.updateUserLastAuthentication(jwtPayload.id, false, moment(jwtPayload.expire*1000).format("YYYY-MM-DD HH:mm"), true);
return done(null, null);
}
}else{
var lastAction = moment().unix();
// check is user array is already created
if(!wavesysUser[jwtPayload.id])
wavesysUser[jwtPayload.id] = [];
// add token
wavesysUser[jwtPayload.id][jwtPayload.tokenId] = {lastAction: lastAction};
Database.Users.updateUserAuthenticationExpiration(jwtPayload.id, true, false);
}
}));
passport.serializeUser(function(jwtPayload, done) {
done(null, jwtPayload.id);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
};
UsersDatabase:
UsersDatabase.prototype.updateUserLastAuthentication = function (userId, check, expireDate, expired) {
createLog('debug', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'updateUserLastAuthentication', 'expireDate', expireDate);
return new Promise(function (resolve, reject) {
pg.connect(dbConnectionString, function (err, client, done) {
if (err) {
createLog('error', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'updateUserLastAuthentication', err);
reject(err);
return
}
client.query('UPDATE users \
SET modified_date=NOW(), authenticated=$1, expire_date=$2, expired=$3 WHERE id = $4 AND not deleted \
RETURNING id, username, created_date, modified_date, created_by, modified_by, last_login_date, organization_id, organization_permission_group_id, data',
[check, expireDate, expired, userId], function (err, result) {
done();
if (err) {
createLog('error', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'updateUserLastAuthentication', err);
reject(err);
} else {
createLog('debug', __dirname, __filename.slice(__dirname.length + 1, -3), null, 'updateUserLastAuthentication', 'result',result);
resolve(result.rows[0]);
}
});
});
});
}
In angular:
controllerScope.usersData.columns = [
{"data":"username","defaultContent":""},
{"data":"organization_data.name","defaultContent":""},
{"data":"permission_group_name","defaultContent":""},
{"data":"data.root","render":function(data){
if (data){
return '<i style="color:#2ECC71" class="fa fa-check"></i>';
}else{
return '<i style="color:#DC6457" class="fa fa-close"></i>';
}
}},
{"data": "last_login_date", render: function (data, type, row) {
return $filter('date')(row.modified_date, 'dd-MM-yyyy HH:mm:ss');
}
},
{"data":"authenticated","render":function(data){
if (data){
return '<i style="color:#2ECC71" class="fa fa-check"></i>';
}else{
return '<i style="color:#DC6457" class="fa fa-close"></i>';
}
}},
{"data":"expired","render":function(data){
if (data){
return '<i style="color:#2ECC71" class="fa fa-check"></i>';
}else{
return '<i style="color:#DC6457" class="fa fa-close"></i>';
}
}},
{"data": "expire_date", render: function (data, type, row) {
return $filter('date')(row.modified_date, 'dd-MM-yyyy HH:mm:ss');
}
},
{"data":null, "orderable":false, "render":function(data){
return '<button class="btn btn-default btn-sm" style="margin-right:5px;" onclick=\'angular.element(this).scope().openNewUserModal('+JSON.stringify(data)+')\'><i class="fa fa-pencil"></i></button>'
+'<button class="btn btn-default btn-sm" onclick="angular.element(this).scope().deleteUser(\''+data.id+'\')"><i class="fa fa-trash"></i></button>';
}}];
via Catia Matos
No comments:
Post a Comment