由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Passport isAuthenticated() always returns TRUE
相关主题
Node.js passport 如何用isAuthenticated()检测所有网页?ftp的问题
这Shell脚本哪里有问题find command (转载)
vc2008下编译的问题Help: a Perl script question, Thanks (转载)
Critical GnuTLS crypto bug leaves Linux, hundreds of apps请问sql语句能不能实现这样的功能
backend是legecy系统,用户量会持续增加,用Java可以怎么解决?php直接运行文件问题
真是痛恨喜欢 throw 的猪用C#读取网页的问题?
OpenSuse在KDE下点击了lock screen之后,机器废了 (转载)程序中的各个变量/数组的内存地址是否会混在一起?
问个programming style 的问题自动背景运行程序
相关话题的讨论汇总
话题: var话题: require话题: function话题: username
进入Programming版参与讨论
1 (共1页)
w*s
发帖数: 7227
1
我老做了网站的login, logout,好像可以。问题是logout以后按browser back key,
尼玛以前只能login后看的内容又全出来了。
用了这个但还不行
app.get('/logout', isLoggedIn, function(req, res) {
req.logOut();
if (!req.user)
res.header('Cache-Control', 'private, no-cache, no-store, must-
revalidate');
res.redirect('/login');
});
w*s
发帖数: 7227
2
简化版的程序,logout, 按了back key后
isAuthenticated() 还说 "you are logged in".
var express = require('express');
var passport = require('passport');
var net = require('net');
var bodyParser = require('body-parser');
var http = require('http');
var multer = require('multer');
var cp = require('child_process');
var exec = require('child_process').exec;
var sys = require('sys');
var path = require('path');
var util = require('util');
var session = require('express-session');
var crypto = require('crypto');
var sqlite3 = require('sqlite3');
/////////////////////////////////////////////////
var LocalStrategy = require('passport-local').Strategy;
var db = new sqlite3.Database('./myPassword.db');
passport.use(new LocalStrategy(function(username, password, done)
{
console.log("step 2: Client sent you user: " + username + " password: "
+ password);
db.get('SELECT slat FROM users WHERE username = ?', username, function(
err, row)
{
if (!row) return done(null, false);
console.log("step 4");
db.get('SELECT username, id FROM users WHERE username = ? AND
password = ?',
username, password, function(err, row)
{
console.log("step 6");
if (!row) return done(null, false);
console.log("step 8");
return done(null, row);
});
});
}));
passport.serializeUser(function(user, done) {
return done(null, user.id);
});
passport.deserializeUser(function(id, done) {
db.get('SELECT id, username FROM users WHERE id = ?', id, function(err,
row)
{
if (!row)
return done(null, false);
return done(null, row);
});
});
/////////////////////////////////////////////////
var isAuthenticated = function(req, res, next)
{
//if (req.user.authenticated)
if (req.isAuthenticated()) {
console.log("Very good, you are logged in ...");
return next();
}
console.log("Sorry, you are NOT logged in yet ...");
res.send(200);
};
/////////////////////////////////////////////////
var app = express();
/////////////////////////////////////////////////
var server = http.createServer(app);
/////////////////////////////////////////////////
app.use(function(req, res, next) {
if (!req.user) {
console.log('Cannot display 1 ...');
res.header('Cache-Control', 'private, no-cache, no-store, must-
revalidate');
}
console.log('Cannot display 2 ...');
next();
});
app.use(express.static('../client/', {index: 'login.html'} ));
app.use(bodyParser());
app.use(session({ secret: 'my test cookie' }));
app.use(passport.initialize());
app.use(passport.session());
app.post('/auth/login', passport.authenticate('local',
{
successRedirect: '/index.html#/uploads',
failureRedirect: '/login.html',
}));
app.get('/auth/logout', function(req, res)
{
console.log("logging out ......");
req.session = null;
req.logout();
res.send(200);
});
app.get('/', isAuthenticated, function(req, res)
{
res.sendfile(path.resolve('../client/index.html'));
});
app.get('/systemStatus', isAuthenticated, function(req, res)
{
console.log("getting data from backend");
// skip details here ...
});
server.listen(5678);
1 (共1页)
进入Programming版参与讨论
相关主题
自动背景运行程序backend是legecy系统,用户量会持续增加,用Java可以怎么解决?
有没有可以自动check email的软件?真是痛恨喜欢 throw 的猪
头大得不行,请教c# active directory 问题OpenSuse在KDE下点击了lock screen之后,机器废了 (转载)
同主题转寄 (转载)问个programming style 的问题
Node.js passport 如何用isAuthenticated()检测所有网页?ftp的问题
这Shell脚本哪里有问题find command (转载)
vc2008下编译的问题Help: a Perl script question, Thanks (转载)
Critical GnuTLS crypto bug leaves Linux, hundreds of apps请问sql语句能不能实现这样的功能
相关话题的讨论汇总
话题: var话题: require话题: function话题: username