window.onload = function(){
function timer(){
let minute = document.getElementById('minute').innerHTML;
let second = document.getElementById('second').innerHTML;
let end = false;
if( second > 0 ) {
second--;
if( second < 10) {
second = '0'+second
};
} else{
second = 60;
if( minute > 0 ) {
minute--;
if(minute < 10){
minute = '0'+minute
}
} else{
end = true;
}
}
if(end){
clearInterval(intervalID);
alert("Время истекло!");
}else{document.getElementById('minute').innerHTML = minute;
document.getElementById('second').innerHTML = second;
}
}
window.intervalID = setInterval(timer, 1000);
}
router.post('/', async (ctx) => {
await passport.authenticate('local', async(err, user) => {
if(user === false){
await ctx.render('login', {title: 'Авторизация', message: 'Неверный логин или пароль'});
} else {
console.log(user);
const payload = {
id: user.id,
username: user.username,
};
const token = jwt.sign(payload, jwtsecret); //здесь создается JWT
ctx.body = {user: user.username, token: 'JWT ' + token};
console.log(ctx.body);
ctx.redirect('/user');
}
}) (ctx)
});