Commit 37e31cb0 authored by kevinflo's avatar kevinflo

increment sign in count on login

parent 6fe7832f
......@@ -20,7 +20,7 @@ var Raven = require("raven");
passport.use(
new LocalStrategy(function(email, password, done) {
db.query("SELECT person_uuid, password FROM person WHERE email = $1", [email])
db.query("SELECT person_uuid, sign_in_count, password FROM person WHERE email = $1", [email])
.then(result => {
if (!result.rows[0]) {
return done(null, false, { message: "User not found" });
......@@ -32,7 +32,19 @@ passport.use(
}
if (isMatch) {
return done(null, _.pick(result.rows[0], "person_uuid"));
var newSignInCount = result.rows[0].sign_in_count;
if (!newSignInCount){
newSignInCount = 1;
} else {
newSignInCount++;
}
var query = `UPDATE person SET sign_in_count = ${newSignInCount} WHERE person_uuid = '${result.rows[0].person_uuid}'`;
db.query(query).then(() => {
return done(null, _.pick(result.rows[0], "person_uuid"));
}).catch(err => {
console.error(err)
throw err;
})
} else {
return done(null, false, { message: "Incorrect password" });
}
......
......@@ -156,15 +156,12 @@ router.get("/confirm/:tokenId", function(req, res, err) {
} else {
db.query(
"SELECT person_id FROM person WHERE email_confirmation_token = $1",
[tokenId],
function(err, rows) {
if (err) {
res.render("confirm", {
title: "Express",
mainjs: false,
confirmed: false
});
} else if (rows.length === 0 || !rows[0].person_id) {
[tokenId]
)
.then(function(results) {
var rows = results.rows;
if (rows.length === 0 || !rows[0].person_id) {
console.error("person ID not found");
res.render("confirm", {
title: "Express",
mainjs: false,
......@@ -172,28 +169,26 @@ router.get("/confirm/:tokenId", function(req, res, err) {
});
} else {
var userId = rows[0].person_id;
db.query(
return db.query(
"UPDATE person SET email_confirmed_at = $1 where person_id = $2",
[new Date(), userId],
function(err, rows) {
if (err) {
console.err(err);
res.render("confirm", {
title: "Express",
mainjs: false,
confirmed: false
});
}
res.render("confirm", {
title: "Express",
mainjs: false,
confirmed: true
});
}
[new Date(), userId]
);
}
}
);
})
.then(() => {
res.render("confirm", {
title: "Express",
mainjs: false,
confirmed: true
});
})
.catch(err => {
console.error("token confirm error", err);
res.render("confirm", {
title: "Express",
mainjs: false,
confirmed: false
});
});
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment