forked from projects/fipamo
112 lines
3.3 KiB
JavaScript
112 lines
3.3 KiB
JavaScript
var express = require('express');
|
|
var router = express.Router();
|
|
var Models = require('../../models');
|
|
var bCrypt = require('bcrypt-nodejs');
|
|
var config = require('../../../config.json');
|
|
module.exports = function (session) {
|
|
//--------------------------
|
|
// Index
|
|
//--------------------------
|
|
router.get('/:page?', function (req, res) {
|
|
|
|
if (req.params.page == null || req.params.page == "") {
|
|
Models.FolioProject.findAll({
|
|
limit: 5,
|
|
order: [
|
|
['id', 'DESC']
|
|
]
|
|
}).then(entries => {
|
|
Models.Post.findAll({
|
|
limit: 5,
|
|
order: [
|
|
['id', 'DESC']
|
|
]
|
|
}).then(posts => {
|
|
Models.Bookmark.findAll({
|
|
limit: 5,
|
|
order: [
|
|
['id', 'DESC']
|
|
]
|
|
}).then(saved => {
|
|
res.render(config.theme + '/index', {
|
|
theme: config.theme,
|
|
title: 'The Twelfth House | Home of creative technologist, beat maker and over-thinker, Ro',
|
|
user_status: "What up, random person",
|
|
mode: 'index',
|
|
folio: entries,
|
|
posts: posts,
|
|
bookmarks: saved
|
|
});
|
|
|
|
}).catch(err => {
|
|
console.log(err);
|
|
})
|
|
|
|
})
|
|
|
|
}).then(function (value) {
|
|
//console.log(value);
|
|
}).catch(function (err) {
|
|
console.log(err);
|
|
})
|
|
} else {
|
|
switch (req.params.page) {
|
|
case "dashboard":
|
|
console.log('here')
|
|
break;
|
|
|
|
default:
|
|
console.log(req.params.page)
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
});
|
|
|
|
//--------------------------
|
|
// Login
|
|
//--------------------------
|
|
/* Handle Login POST */
|
|
router.post('/login', function (req, res, next) {
|
|
|
|
Models.User.findOne({
|
|
where: {
|
|
handle: req.body.handle
|
|
}
|
|
}).then(user => {
|
|
if (!isValidPassword(user, req.body.password)) {
|
|
console.log('Invalid Password');
|
|
//return done(null, false, req.flash('message', 'Invalid Password')); // redirect back to login page
|
|
return res.json({
|
|
message: 'CHECK YOUR PASSWORD'
|
|
});
|
|
}
|
|
let session = req.session;
|
|
session.user = user;
|
|
res.redirect('/@/dashboard');
|
|
//return done(null, user);
|
|
|
|
}).catch(err => {
|
|
console.log(err);
|
|
return res.json({
|
|
message: 'NOT FOUND BOSS'
|
|
});
|
|
})
|
|
});
|
|
|
|
//--------------------------
|
|
// Logout
|
|
//--------------------------
|
|
router.post('/logout', function (req, res, next) {
|
|
req.logout();
|
|
return res.json({
|
|
message: 'LOGGED OUT'
|
|
});
|
|
});
|
|
return router;
|
|
}
|
|
|
|
var isValidPassword = function (user, password) {
|
|
return bCrypt.compareSync(password, user.password);
|
|
} |