Files
kno-logic-api/utils/account.js
Johnathon Slightham 531a4d632b Added refresh tokens
2021-06-11 12:03:50 -04:00

40 lines
1.1 KiB
JavaScript

let User = require('../schema/user.model');
let Session = require('../schema/session.model');
const bcrypt = require('bcrypt');
// checkSession(userId, sessionId) checks if the sessionId is valid for the user
const checkSession = (userId, sessionId, f) => {
Session.find({ userId: userId, sessionId: sessionId }, (err, res) => {
if (res && res.type == 0) {
f(true);
return;
}
f(false);
});
}
// checkRefresh(userId, sessionId) checks if the refresh token is valid for the user
const checkRefresh = (userId, sessionId, f) => {
Session.find({ userId: userId, sessionId: sessionId }, (err, res) => {
if (res && res.type == 1) {
f(true);
return;
}
f(false);
});
}
// isAdmin(userId) checks if the user with userId is an administrator
const isAdmin = (userId, f) => {
User.findById(userId, (err, res) => {
if (res.permission == 1) {
f(true);
return;
}
f(false);
})
}
module.exports.checkSession = checkSession;
module.exports.isAdmin = isAdmin;