exports.post = function*(next) {
var self = this;
yield passport.authenticate('local', function* (err, user, info) {
if (err) throw err;
if (user === false) {
self.status = 401;
self.body = info.message;
} else {
yield self.login(user);
}
self.redirect('/');
});
};
const passport = require('koa-passport');
...
yield passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/'
});
...
'use strict';
const fs = require('mz/fs');
fs.readdir(__dirname)
.then(filesNames => Promise.all(
filesNames.map(fileName => {
return fs.stat(fileName).then(stat => {
return {name: fileName, stat: stat};
});
})
)
)
.then(stats => stats.filter(
statsObj => statsObj.stat.isFile()
))
.then(stats => stats.reduce(
(sum, statsObj) => {
console.log(`${statsObj.name}: ${statsObj.stat.size}`);
return sum + statsObj.stat.size;
}, 0
))
.then(console.log)
.catch(error => console.log(error));