2013-11-12 09:27:12 +04:00
|
|
|
var admin = require('../controllers/admin'),
|
|
|
|
api = require('../api'),
|
2013-11-17 22:40:26 +04:00
|
|
|
middleware = require('../middleware').middleware,
|
|
|
|
Ghost = require('../../ghost'),
|
|
|
|
url = require('url'),
|
|
|
|
|
|
|
|
ghost = new Ghost();
|
2013-11-12 09:27:12 +04:00
|
|
|
|
|
|
|
// Redirect to signup if no users are currently created
|
|
|
|
function redirectToSignup(req, res, next) {
|
2013-11-17 22:40:26 +04:00
|
|
|
var root = ghost.server.get('ghost root').replace(/\/$/, '');
|
2013-11-12 09:27:12 +04:00
|
|
|
/*jslint unparam:true*/
|
|
|
|
api.users.browse().then(function (users) {
|
|
|
|
if (users.length === 0) {
|
2013-11-17 22:40:26 +04:00
|
|
|
return res.redirect(root + '/ghost/signup/');
|
2013-11-12 09:27:12 +04:00
|
|
|
}
|
|
|
|
next();
|
|
|
|
}).otherwise(function (err) {
|
|
|
|
return next(new Error(err));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function (server) {
|
2013-11-17 22:40:26 +04:00
|
|
|
var root = server.get('ghost root').replace(/\/$/, '');
|
2013-11-12 09:27:12 +04:00
|
|
|
// ### Admin routes
|
|
|
|
/* TODO: put these somewhere in admin */
|
2013-11-26 13:38:54 +04:00
|
|
|
server.get('/logout/', function redirect(req, res) {
|
2013-11-12 09:27:12 +04:00
|
|
|
/*jslint unparam:true*/
|
2013-11-26 13:38:54 +04:00
|
|
|
res.redirect(301, root + '/ghost/signout/');
|
|
|
|
});
|
|
|
|
server.get('/signout/', function redirect(req, res) {
|
|
|
|
/*jslint unparam:true*/
|
|
|
|
res.redirect(301, root + '/ghost/signout/');
|
|
|
|
});
|
|
|
|
server.get('/signin/', function redirect(req, res) {
|
|
|
|
/*jslint unparam:true*/
|
|
|
|
res.redirect(301, root + '/ghost/signin/');
|
|
|
|
});
|
|
|
|
server.get('/signup/', function redirect(req, res) {
|
|
|
|
/*jslint unparam:true*/
|
|
|
|
res.redirect(301, root + '/ghost/signup/');
|
2013-11-12 09:27:12 +04:00
|
|
|
});
|
|
|
|
server.get('/ghost/login/', function redirect(req, res) {
|
|
|
|
/*jslint unparam:true*/
|
2013-11-17 22:40:26 +04:00
|
|
|
res.redirect(301, root + '/ghost/signin/');
|
2013-11-12 09:27:12 +04:00
|
|
|
});
|
2013-11-26 13:38:54 +04:00
|
|
|
|
|
|
|
server.get('/ghost/signout/', admin.logout);
|
2013-11-12 09:27:12 +04:00
|
|
|
server.get('/ghost/signin/', redirectToSignup, middleware.redirectToDashboard, admin.login);
|
|
|
|
server.get('/ghost/signup/', middleware.redirectToDashboard, admin.signup);
|
|
|
|
server.get('/ghost/forgotten/', middleware.redirectToDashboard, admin.forgotten);
|
2013-11-22 07:17:38 +04:00
|
|
|
server.post('/ghost/forgotten/', admin.generateResetToken);
|
|
|
|
server.get('/ghost/reset/:token', admin.reset);
|
|
|
|
server.post('/ghost/reset/:token', admin.resetPassword);
|
2013-11-12 09:27:12 +04:00
|
|
|
server.post('/ghost/signin/', admin.auth);
|
|
|
|
server.post('/ghost/signup/', admin.doRegister);
|
|
|
|
server.post('/ghost/changepw/', middleware.auth, admin.changepw);
|
|
|
|
server.get('/ghost/editor(/:id)/', middleware.auth, admin.editor);
|
|
|
|
server.get('/ghost/editor/', middleware.auth, admin.editor);
|
|
|
|
server.get('/ghost/content/', middleware.auth, admin.content);
|
|
|
|
server.get('/ghost/settings*', middleware.auth, admin.settings);
|
|
|
|
server.get('/ghost/debug/', middleware.auth, admin.debug.index);
|
|
|
|
|
|
|
|
// We don't want to register bodyParser globally b/c of security concerns, so use multipart only here
|
|
|
|
server.post('/ghost/upload/', middleware.auth, admin.uploader);
|
|
|
|
|
|
|
|
// redirect to /ghost and let that do the authentication to prevent redirects to /ghost//admin etc.
|
2013-11-17 22:40:26 +04:00
|
|
|
server.get(/\/((ghost-admin|admin|wp-admin|dashboard|signin)\/?)$/, function (req, res) {
|
2013-11-12 09:27:12 +04:00
|
|
|
/*jslint unparam:true*/
|
2013-11-17 22:40:26 +04:00
|
|
|
res.redirect(root + '/ghost/');
|
2013-11-12 09:27:12 +04:00
|
|
|
});
|
2013-11-17 22:40:26 +04:00
|
|
|
server.get(/\/(ghost$\/?)/, middleware.auth, function (req, res) {
|
2013-11-12 09:27:12 +04:00
|
|
|
/*jslint unparam:true*/
|
2013-11-17 22:40:26 +04:00
|
|
|
res.redirect(root + '/ghost/');
|
2013-11-12 09:27:12 +04:00
|
|
|
});
|
|
|
|
server.get('/ghost/', redirectToSignup, middleware.auth, admin.index);
|
|
|
|
};
|