2017-10-11 01:00:08 +02:00
|
|
|
const db = require('../models'); // require our models for syncing
|
|
|
|
const logger = require('winston');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
populateLocalsDotUser (req, res, next) {
|
|
|
|
if (req.user) {
|
|
|
|
res.locals.user = {
|
|
|
|
id : req.user.id,
|
|
|
|
userName : req.user.userName,
|
|
|
|
channelName : req.user.channelName,
|
|
|
|
channelClaimId: req.user.channelClaimId,
|
|
|
|
shortChannelId: req.user.shortChannelId,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
},
|
|
|
|
serializeSpeechUser (user, done) {
|
|
|
|
done(null, user.id);
|
|
|
|
},
|
|
|
|
deserializeSpeechUser (id, done) {
|
|
|
|
let userInfo = {};
|
|
|
|
db.User.findOne({ where: { id } })
|
|
|
|
.then(user => {
|
|
|
|
userInfo['id'] = user.id;
|
|
|
|
userInfo['userName'] = user.userName;
|
|
|
|
return user.getChannel();
|
|
|
|
})
|
|
|
|
.then(channel => {
|
|
|
|
userInfo['channelName'] = channel.channelName;
|
|
|
|
userInfo['channelClaimId'] = channel.channelClaimId;
|
2017-10-31 18:05:15 +01:00
|
|
|
return db.Certificate.getShortChannelIdFromLongChannelId(channel.channelClaimId, channel.channelName);
|
2017-10-11 01:00:08 +02:00
|
|
|
})
|
|
|
|
.then(shortChannelId => {
|
|
|
|
userInfo['shortChannelId'] = shortChannelId;
|
2017-10-26 17:46:00 +02:00
|
|
|
// return done(null, userInfo);
|
|
|
|
done(null, userInfo);
|
|
|
|
return null;
|
2017-10-11 01:00:08 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
logger.error(error);
|
|
|
|
done(error, null);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|