我正在使用 nodejs、nowjs、codeigniter 和 mysql 编写应用程序。我使用数据库来存储会话。有没有一种好方法可以检查和检索 nodejs 中的会话 cookie?因此,例如,如果我需要使用 nowjs 检查用户是否拥有数据库中即将被删除的特定行。例如:
服务器:
//some code here to get session cookie and retrieve stored data from database
var session = { user_id: //userid from database }
everyone.now.deleteGuestbook = function(recordId) {
var owner_id = client.query(
'SELECT owner_id FROM guestbook WHERE id = ?',
[recordId]
);
if (session.user_id === owner_id) {
client.query(
'DELETE FROM guestbook WHERE id = ?',
[recordId], function() {
everyone.now.deleteRecord;
}
);
}
}
客户:
//Delete guestbook record
$('#guestbook_records li').live('click', function(e) {
if ($(e.target).is('a.delete')) {
var id = $(this).find('a.delete').attr('href');
dialogBox('warning', 'Are you sure you want to delete the record?',
function() {
now.deleteGuestbook(id);
});
}
else {
return;
}
return false;
});
now.deleteMessage = function(id) {
$('li[class="' + id + '"]').slideUp(400, function() {
$(this).remove();
});
};