LDAP身份验证对于我的新应用程序工作正常,并且能够提取用户详细信息,例如电子邮件,全名,标题等,但不能提取缩略图。
缩略图照片的格式如下:
thumbnailPhoto:
'����\ u0000 \ u0010JFIF \ u0000 \ u0001 \ u0001 \ u0001 \ u0000 \u0000
\ u0000 \u0000��\ u0000C \ u0000 \ b \ u0006 \ u0006 \ u0007 \ u0006 \ u0005 \ b \ u0007 \ u0007 \ u0007 \ t \ t \ b \ n \ f \ u0014 \ r \ f \ u000b \ u000b \ f \ u0019 \ u0012 \ u0013 \ u000f \ u0014 \ u001d \ u001a \ u001f \ u001e \ u001d \ u001d \ u001a \ u001c \ u001c $。\'“,#\ u001c \ u001c(7),01444 \ u001f \'9 = 82 <.342��\ u0000C \ u0001 \ t \ t \ t \ f \ u000b \ f \ u0018 \ r \ r \ u00182!\ u001c
app.set('trust proxy', 1); // trust first proxy
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: { secure: true }
}));
var user_sess = null;
function auth(req, res, next) {
if (user_sess) {
return next();
} else {
res.redirect('/');
}
};
app.post('/auth/signin', passport.authenticate('ldapauth', { failureRedirect: '/' }), function (req, res) {
req.session.uname = req.body.username;
user_sess = req.session;
res.redirect('/profile');
});
app.get('/profile', auth, (req, res) => {
/* if (user_sess.passport.user.thumbnailPhoto.status == 200) {
var buffer = (new Buffer(user_sess.passport.user.thumbnailPhoto.status.body.toString()));
res.end(buffer.toString("base64")); // output content as response body
require('fs').writeFileSync('./public/images/profilepic.jpg', buffer); // also write it to file
return;
}
console.log(buffer);
res.writeHead(user_sess.passport.user.thumbnailPhoto.status, user_sess.passport.user.thumbnailPhoto.headers);
res.write(user_sess.passport.user.thumbnailPhoto.body);*/
res.render('profilesView', {
uname: user_sess.uname,
title: user_sess.passport.user.title,
email: user_sess.passport.user.mail,
//photo: buffer
},
);
});
app.get("/", (req, res) => {
res.render("index", {
title: "XYZ"
});
});
app.get('/logout', function (req, res) {
req.logout();
user_sess = null;
req.session.destroy();
res.redirect('/');
});
app.listen(3000, () => {
console.log("listening port 3000");
});
I am able to render name, title, email but not the photo.
I am using below code in profile view.ejs file
<div class="container">
<div class="user-profilewrap">
<!-- <img src="http://http://localhost:3000/./public/images/profilepic.jpg">-->
<a href='/logout' style="align:right" > Logout </a>
<h6>User Name: <%= uname %></h6>
<h6>Email: <%= email%></h6>
<h6>Title: <%= title %></h6>
</div>
</div>