2013-12-06 12:51:35 +04:00
|
|
|
var config = require('../config'),
|
2014-02-05 12:40:30 +04:00
|
|
|
_ = require('lodash'),
|
2013-09-24 14:46:30 +04:00
|
|
|
path = require('path'),
|
2013-11-22 07:17:38 +04:00
|
|
|
when = require('when'),
|
2013-09-24 14:46:30 +04:00
|
|
|
api = require('../api'),
|
2014-05-09 14:11:29 +04:00
|
|
|
errors = require('../errors'),
|
2013-11-07 20:00:39 +04:00
|
|
|
storage = require('../storage'),
|
2014-01-03 19:50:03 +04:00
|
|
|
updateCheck = require('../update-check'),
|
2013-06-25 15:43:15 +04:00
|
|
|
adminNavbar,
|
2013-08-22 23:48:36 +04:00
|
|
|
adminControllers,
|
|
|
|
loginSecurity = [];
|
2013-05-11 20:44:25 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
adminNavbar = {
|
|
|
|
content: {
|
|
|
|
name: 'Content',
|
|
|
|
navClass: 'content',
|
|
|
|
key: 'admin.navbar.content',
|
2013-09-11 18:38:09 +04:00
|
|
|
path: '/'
|
2013-06-25 15:43:15 +04:00
|
|
|
},
|
|
|
|
add: {
|
|
|
|
name: 'New Post',
|
|
|
|
navClass: 'editor',
|
|
|
|
key: 'admin.navbar.editor',
|
|
|
|
path: '/editor/'
|
|
|
|
},
|
|
|
|
settings: {
|
|
|
|
name: 'Settings',
|
|
|
|
navClass: 'settings',
|
|
|
|
key: 'admin.navbar.settings',
|
|
|
|
path: '/settings/'
|
|
|
|
}
|
|
|
|
};
|
2013-05-11 20:44:25 +04:00
|
|
|
|
2013-08-22 23:48:36 +04:00
|
|
|
|
2013-06-25 20:58:26 +04:00
|
|
|
// TODO: make this a util or helper
|
2013-06-25 15:43:15 +04:00
|
|
|
function setSelected(list, name) {
|
|
|
|
_.each(list, function (item, key) {
|
|
|
|
item.selected = key === name;
|
2013-05-29 04:10:39 +04:00
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
return list;
|
|
|
|
}
|
2013-05-29 04:10:39 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
adminControllers = {
|
2014-02-27 03:15:31 +04:00
|
|
|
'index': function (req, res) {
|
2014-06-23 20:01:43 +04:00
|
|
|
|
2014-02-27 03:15:31 +04:00
|
|
|
/*jslint unparam:true*/
|
2014-06-23 20:01:43 +04:00
|
|
|
var userData,
|
|
|
|
// config we need on the frontend
|
|
|
|
frontConfig = {
|
2014-06-24 03:24:13 +04:00
|
|
|
apps: config().apps,
|
|
|
|
fileStorage: config().fileStorage
|
2014-06-23 20:01:43 +04:00
|
|
|
};
|
2014-05-09 09:00:10 +04:00
|
|
|
|
2014-05-15 03:36:13 +04:00
|
|
|
res.render('default-ember', {
|
2014-06-23 20:01:43 +04:00
|
|
|
user: userData,
|
|
|
|
config: JSON.stringify(frontConfig)
|
2014-05-15 03:36:13 +04:00
|
|
|
});
|
2014-02-27 03:15:31 +04:00
|
|
|
},
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: index
|
|
|
|
// Path: /ghost/
|
|
|
|
// Method: GET
|
2014-02-27 03:15:31 +04:00
|
|
|
'indexold': function (req, res) {
|
2014-02-25 14:51:12 +04:00
|
|
|
/*jslint unparam:true*/
|
|
|
|
function renderIndex() {
|
|
|
|
res.render('content', {
|
|
|
|
bodyClass: 'manage',
|
|
|
|
adminNav: setSelected(adminNavbar, 'content')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
when.join(
|
|
|
|
updateCheck(res),
|
|
|
|
when(renderIndex())
|
|
|
|
// an error here should just get logged
|
|
|
|
).otherwise(errors.logError);
|
|
|
|
},
|
|
|
|
'content': function (req, res) {
|
|
|
|
/*jslint unparam:true*/
|
|
|
|
res.render('content', {
|
|
|
|
bodyClass: 'manage',
|
|
|
|
adminNav: setSelected(adminNavbar, 'content')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// Route: editor
|
2014-05-01 05:50:24 +04:00
|
|
|
// Path: /ghost/editor(/:id)?(/:action)?/
|
2014-02-25 14:51:12 +04:00
|
|
|
// Method: GET
|
|
|
|
'editor': function (req, res) {
|
2014-05-01 05:50:24 +04:00
|
|
|
if (req.params.id && req.params.action) {
|
|
|
|
if (req.params.action !== 'view') {
|
|
|
|
return errors.error404(req, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
api.posts.read({ id: req.params.id }).then(function (result) {
|
|
|
|
return config.urlForPost(api.settings, result.posts[0]).then(function (url) {
|
|
|
|
return res.redirect(url);
|
|
|
|
});
|
|
|
|
}, function () {
|
|
|
|
return errors.error404(req, res);
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (req.params.id !== undefined) {
|
2014-02-25 14:51:12 +04:00
|
|
|
res.render('editor', {
|
|
|
|
bodyClass: 'editor',
|
|
|
|
adminNav: setSelected(adminNavbar, 'content')
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.render('editor', {
|
|
|
|
bodyClass: 'editor',
|
|
|
|
adminNav: setSelected(adminNavbar, 'add')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Route: settings
|
|
|
|
// path: /ghost/settings/(*/)?
|
|
|
|
// Method: GET
|
|
|
|
'settings': function (req, res, next) {
|
|
|
|
// TODO: Centralise list/enumeration of settings panes, so we don't run into trouble in future.
|
2014-03-02 15:46:03 +04:00
|
|
|
var allowedSections = ['', 'general', 'user', 'apps'],
|
2014-02-25 14:51:12 +04:00
|
|
|
section = req.url.replace(/(^\/ghost\/settings[\/]*|\/$)/ig, '');
|
|
|
|
|
|
|
|
if (allowedSections.indexOf(section) < 0) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render('settings', {
|
|
|
|
bodyClass: 'settings',
|
|
|
|
adminNav: setSelected(adminNavbar, 'settings')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// Route: debug
|
|
|
|
// path: /ghost/debug/
|
|
|
|
// Method: GET
|
|
|
|
'debug': {
|
|
|
|
index: function (req, res) {
|
|
|
|
/*jslint unparam:true*/
|
|
|
|
res.render('debug', {
|
|
|
|
bodyClass: 'settings',
|
|
|
|
adminNav: setSelected(adminNavbar, 'settings')
|
|
|
|
});
|
2014-02-27 19:48:38 +04:00
|
|
|
},
|
|
|
|
// frontend route for downloading a file
|
|
|
|
exportContent: function (req, res) {
|
2014-06-30 16:58:10 +04:00
|
|
|
api.db.exportContent({context: {user: req.user.id}}).then(function (exportData) {
|
2014-02-27 19:48:38 +04:00
|
|
|
// send a file to the client
|
|
|
|
res.set('Content-Disposition', 'attachment; filename="GhostData.json"');
|
|
|
|
res.json(exportData);
|
|
|
|
}).otherwise(function (err) {
|
|
|
|
var notification = {
|
|
|
|
type: 'error',
|
2014-04-29 00:58:18 +04:00
|
|
|
message: 'Your export file could not be generated. Error: ' + err.message
|
2014-02-27 19:48:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
errors.logError(err, 'admin.js', "Your export file could not be generated.");
|
|
|
|
|
2014-06-16 09:24:19 +04:00
|
|
|
return api.notifications.add({ notifications: [notification]}).then(function () {
|
2014-02-27 19:48:38 +04:00
|
|
|
res.redirect(config().paths.subdir + '/ghost/debug');
|
|
|
|
});
|
|
|
|
});
|
2014-02-25 14:51:12 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Route: upload
|
|
|
|
// Path: /ghost/upload/
|
|
|
|
// Method: POST
|
|
|
|
'upload': function (req, res) {
|
2013-09-28 17:54:26 +04:00
|
|
|
var type = req.files.uploadimage.type,
|
2013-08-14 00:04:07 +04:00
|
|
|
ext = path.extname(req.files.uploadimage.name).toLowerCase(),
|
2013-11-07 20:00:39 +04:00
|
|
|
store = storage.get_storage();
|
2013-09-28 17:54:26 +04:00
|
|
|
|
2013-11-12 22:37:54 +04:00
|
|
|
if ((type !== 'image/jpeg' && type !== 'image/png' && type !== 'image/gif' && type !== 'image/svg+xml')
|
|
|
|
|| (ext !== '.jpg' && ext !== '.jpeg' && ext !== '.png' && ext !== '.gif' && ext !== '.svg' && ext !== '.svgz')) {
|
2013-09-28 17:54:26 +04:00
|
|
|
return res.send(415, 'Unsupported Media Type');
|
|
|
|
}
|
2013-08-05 21:31:29 +04:00
|
|
|
|
2013-11-07 20:00:39 +04:00
|
|
|
store
|
|
|
|
.save(req.files.uploadimage)
|
2013-09-28 17:54:26 +04:00
|
|
|
.then(function (url) {
|
2013-11-07 20:00:39 +04:00
|
|
|
return res.send(url);
|
2013-09-28 17:54:26 +04:00
|
|
|
})
|
|
|
|
.otherwise(function (e) {
|
2014-01-11 17:40:21 +04:00
|
|
|
errors.logError(e);
|
|
|
|
return res.send(500, e.message);
|
2013-08-05 21:31:29 +04:00
|
|
|
});
|
|
|
|
},
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: signout
|
|
|
|
// Path: /ghost/signout/
|
|
|
|
// Method: GET
|
|
|
|
'signout': function (req, res) {
|
|
|
|
|
|
|
|
var notification = {
|
|
|
|
type: 'success',
|
|
|
|
message: 'You were successfully signed out',
|
2014-04-29 00:58:18 +04:00
|
|
|
status: 'passive'
|
2014-02-25 14:51:12 +04:00
|
|
|
};
|
|
|
|
|
2014-06-16 09:24:19 +04:00
|
|
|
return api.notifications.add({ notifications: [notification] }).then(function () {
|
2014-02-25 14:51:12 +04:00
|
|
|
res.redirect(config().paths.subdir + '/ghost/signin/');
|
|
|
|
});
|
|
|
|
},
|
2014-06-01 23:30:50 +04:00
|
|
|
// Route: doSignout
|
|
|
|
// Path: /ghost/signout/
|
|
|
|
// Method: POST
|
|
|
|
'doSignout': function (req, res) {
|
|
|
|
req.session.destroy();
|
|
|
|
|
|
|
|
var statusCode,
|
|
|
|
redirectUrl,
|
|
|
|
errorMessage,
|
|
|
|
notification = {
|
|
|
|
type: 'success',
|
|
|
|
message: 'You were successfully signed out.',
|
|
|
|
status: 'passive'
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_.isUndefined(req.session)) {
|
|
|
|
statusCode = 200;
|
|
|
|
redirectUrl = config().paths.subdir + '/ghost/signin/';
|
|
|
|
} else {
|
|
|
|
notification.type = 'error';
|
|
|
|
notification.message = 'Unable to sign out.';
|
|
|
|
|
|
|
|
statusCode = 500;
|
|
|
|
errorMessage = 'There was a problem logging out. Please try again.';
|
|
|
|
}
|
|
|
|
|
2014-06-16 09:24:19 +04:00
|
|
|
return api.notifications.add({ notifications: [notification] }).then(function () {
|
2014-06-01 23:30:50 +04:00
|
|
|
res.json(statusCode, {error: errorMessage, redirect: redirectUrl});
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: signin
|
|
|
|
// Path: /ghost/signin/
|
|
|
|
// Method: GET
|
|
|
|
'signin': function (req, res) {
|
2013-10-31 22:02:34 +04:00
|
|
|
/*jslint unparam:true*/
|
2013-09-12 12:59:58 +04:00
|
|
|
res.render('login', {
|
2013-06-25 15:43:15 +04:00
|
|
|
bodyClass: 'ghost-login',
|
|
|
|
hideNavbar: true,
|
|
|
|
adminNav: setSelected(adminNavbar, 'login')
|
2013-05-11 20:44:25 +04:00
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
},
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: doSignin
|
|
|
|
// Path: /ghost/signin/
|
|
|
|
// Method: POST
|
|
|
|
'doSignin': function (req, res) {
|
2013-12-06 12:51:35 +04:00
|
|
|
var currentTime = process.hrtime()[0],
|
2014-01-05 06:46:15 +04:00
|
|
|
remoteAddress = req.connection.remoteAddress,
|
2013-08-22 23:48:36 +04:00
|
|
|
denied = '';
|
|
|
|
loginSecurity = _.filter(loginSecurity, function (ipTime) {
|
|
|
|
return (ipTime.time + 2 > currentTime);
|
|
|
|
});
|
|
|
|
denied = _.find(loginSecurity, function (ipTime) {
|
2014-01-05 06:46:15 +04:00
|
|
|
return (ipTime.ip === remoteAddress);
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
2013-08-22 23:48:36 +04:00
|
|
|
|
|
|
|
if (!denied) {
|
2014-01-05 06:46:15 +04:00
|
|
|
loginSecurity.push({ip: remoteAddress, time: currentTime});
|
2013-08-22 23:48:36 +04:00
|
|
|
api.users.check({email: req.body.email, pw: req.body.password}).then(function (user) {
|
2014-05-27 04:59:57 +04:00
|
|
|
// Carry over the csrf secret
|
2014-06-16 23:40:59 +04:00
|
|
|
var existingSecret = req.session.csrfSecret;
|
2014-05-27 04:59:57 +04:00
|
|
|
|
2013-11-24 18:29:36 +04:00
|
|
|
req.session.regenerate(function (err) {
|
|
|
|
if (!err) {
|
2014-06-16 23:40:59 +04:00
|
|
|
req.session.csrfSecret = existingSecret;
|
2014-05-27 04:59:57 +04:00
|
|
|
|
2013-11-24 18:29:36 +04:00
|
|
|
req.session.user = user.id;
|
2014-05-15 03:36:13 +04:00
|
|
|
req.session.userData = user.attributes;
|
|
|
|
|
2014-01-05 10:40:53 +04:00
|
|
|
var redirect = config().paths.subdir + '/ghost/';
|
2013-11-27 06:31:27 +04:00
|
|
|
if (req.body.redirect) {
|
|
|
|
redirect += decodeURIComponent(req.body.redirect);
|
|
|
|
}
|
2014-01-20 01:08:39 +04:00
|
|
|
// If this IP address successfully logs in we
|
2014-01-05 06:46:15 +04:00
|
|
|
// can remove it from the array of failed login attempts.
|
|
|
|
loginSecurity = _.reject(loginSecurity, function (ipTime) {
|
|
|
|
return ipTime.ip === remoteAddress;
|
|
|
|
});
|
2014-05-15 03:36:13 +04:00
|
|
|
res.json(200, {redirect: redirect, userData: req.session.userData});
|
2013-11-24 18:29:36 +04:00
|
|
|
}
|
|
|
|
});
|
2013-08-22 23:48:36 +04:00
|
|
|
}, function (error) {
|
|
|
|
res.json(401, {error: error.message});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.json(401, {error: 'Slow down, there are way too many login attempts!'});
|
|
|
|
}
|
2013-06-25 15:43:15 +04:00
|
|
|
},
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: signup
|
|
|
|
// Path: /ghost/signup/
|
|
|
|
// Method: GET
|
2013-06-25 15:43:15 +04:00
|
|
|
'signup': function (req, res) {
|
2013-10-31 22:02:34 +04:00
|
|
|
/*jslint unparam:true*/
|
2013-06-25 15:43:15 +04:00
|
|
|
res.render('signup', {
|
2013-09-12 12:59:58 +04:00
|
|
|
bodyClass: 'ghost-signup',
|
2013-06-25 15:43:15 +04:00
|
|
|
hideNavbar: true,
|
|
|
|
adminNav: setSelected(adminNavbar, 'login')
|
|
|
|
});
|
|
|
|
},
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: doSignup
|
|
|
|
// Path: /ghost/signup/
|
|
|
|
// Method: POST
|
2014-06-30 16:58:10 +04:00
|
|
|
'doSignup': function (req, res) {
|
2013-12-06 12:51:35 +04:00
|
|
|
var name = req.body.name,
|
2013-09-08 23:16:40 +04:00
|
|
|
email = req.body.email,
|
2014-04-29 00:42:38 +04:00
|
|
|
password = req.body.password,
|
2014-06-25 16:12:48 +04:00
|
|
|
blogTitle = req.body.blogTitle,
|
2014-04-29 00:42:38 +04:00
|
|
|
users = [{
|
|
|
|
name: name,
|
|
|
|
email: email,
|
|
|
|
password: password
|
|
|
|
}];
|
2014-06-25 16:12:48 +04:00
|
|
|
|
2014-06-30 16:58:10 +04:00
|
|
|
api.users.register({users: users}).then(function () {
|
|
|
|
var settings = [];
|
2014-06-25 16:12:48 +04:00
|
|
|
|
|
|
|
settings.push({key: 'email', value: email});
|
|
|
|
|
|
|
|
// Handles the additional values set by the setup screen.
|
|
|
|
if (!_.isEmpty(blogTitle)) {
|
|
|
|
settings.push({key: 'title', value: blogTitle});
|
|
|
|
settings.push({key: 'description', value: 'Thoughts, stories and ideas by ' + name});
|
|
|
|
}
|
|
|
|
|
|
|
|
api.settings.edit({settings: settings}, {context: {user: 1}}).then(function () {
|
2013-12-29 01:42:52 +04:00
|
|
|
var message = {
|
2014-05-09 03:12:18 +04:00
|
|
|
to: email,
|
|
|
|
subject: 'Your New Ghost Blog',
|
|
|
|
html: '<p><strong>Hello!</strong></p>' +
|
|
|
|
'<p>Good news! You\'ve successfully created a brand new Ghost blog over on ' + config().url + '</p>' +
|
|
|
|
'<p>You can log in to your admin account with the following details:</p>' +
|
|
|
|
'<p> Email Address: ' + email + '<br>' +
|
|
|
|
'Password: The password you chose when you signed up</p>' +
|
|
|
|
'<p>Keep this email somewhere safe for future reference, and have fun!</p>' +
|
|
|
|
'<p>xoxo</p>' +
|
|
|
|
'<p>Team Ghost<br>' +
|
|
|
|
'<a href="https://ghost.org">https://ghost.org</a></p>'
|
|
|
|
},
|
|
|
|
payload = {
|
|
|
|
mail: [{
|
|
|
|
message: message,
|
|
|
|
options: {}
|
|
|
|
}]
|
2014-06-30 16:58:10 +04:00
|
|
|
};
|
2014-05-09 03:12:18 +04:00
|
|
|
|
|
|
|
api.mail.send(payload).otherwise(function (error) {
|
2014-01-13 01:49:24 +04:00
|
|
|
errors.logError(
|
|
|
|
error.message,
|
|
|
|
"Unable to send welcome email, your blog will continue to function.",
|
|
|
|
"Please see http://docs.ghost.org/mail/ for instructions on configuring email."
|
|
|
|
);
|
2013-12-29 01:42:52 +04:00
|
|
|
});
|
2014-06-30 16:58:10 +04:00
|
|
|
res.json(200, {
|
|
|
|
redirect: config().paths.subdir + '/ghost/'
|
2013-11-24 18:29:36 +04:00
|
|
|
});
|
2014-06-30 16:58:10 +04:00
|
|
|
|
2013-09-17 06:08:36 +04:00
|
|
|
});
|
|
|
|
}).otherwise(function (error) {
|
2013-08-19 01:50:42 +04:00
|
|
|
res.json(401, {error: error.message});
|
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
},
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: forgotten
|
|
|
|
// Path: /ghost/forgotten/
|
|
|
|
// Method: GET
|
2013-09-01 02:20:12 +04:00
|
|
|
'forgotten': function (req, res) {
|
2013-10-31 22:02:34 +04:00
|
|
|
/*jslint unparam:true*/
|
2013-09-12 12:59:58 +04:00
|
|
|
res.render('forgotten', {
|
2013-09-01 02:20:12 +04:00
|
|
|
bodyClass: 'ghost-forgotten',
|
|
|
|
hideNavbar: true,
|
|
|
|
adminNav: setSelected(adminNavbar, 'login')
|
|
|
|
});
|
|
|
|
},
|
2014-06-20 13:15:01 +04:00
|
|
|
// TODO: remove when old admin is removed, functionality lives now in api/authentication
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: doForgotten
|
|
|
|
// Path: /ghost/forgotten/
|
|
|
|
// Method: POST
|
|
|
|
'doForgotten': function (req, res) {
|
2013-12-06 12:51:35 +04:00
|
|
|
var email = req.body.email;
|
2013-09-01 02:20:12 +04:00
|
|
|
|
2013-11-22 07:17:38 +04:00
|
|
|
api.users.generateResetToken(email).then(function (token) {
|
2014-02-22 05:25:31 +04:00
|
|
|
var baseUrl = config().forceAdminSSL ? (config().urlSSL || config().url) : config().url,
|
|
|
|
siteLink = '<a href="' + baseUrl + '">' + baseUrl + '</a>',
|
|
|
|
resetUrl = baseUrl.replace(/\/$/, '') + '/ghost/reset/' + token + '/',
|
2013-11-22 07:17:38 +04:00
|
|
|
resetLink = '<a href="' + resetUrl + '">' + resetUrl + '</a>',
|
2014-05-09 03:12:18 +04:00
|
|
|
payload = {
|
|
|
|
mail: [{
|
|
|
|
message: {
|
|
|
|
to: email,
|
|
|
|
subject: 'Reset Password',
|
|
|
|
html: '<p><strong>Hello!</strong></p>' +
|
|
|
|
'<p>A request has been made to reset the password on the site ' + siteLink + '.</p>' +
|
|
|
|
'<p>Please follow the link below to reset your password:<br><br>' + resetLink + '</p>' +
|
|
|
|
'<p>Ghost</p>'
|
|
|
|
},
|
|
|
|
options: {}
|
|
|
|
}]
|
2013-09-01 02:20:12 +04:00
|
|
|
};
|
|
|
|
|
2014-05-09 03:12:18 +04:00
|
|
|
return api.mail.send(payload);
|
2013-09-04 17:57:41 +04:00
|
|
|
}).then(function success() {
|
2014-05-09 03:12:18 +04:00
|
|
|
// TODO: note that this function takes a response as an
|
|
|
|
// argument but jshint complains of it not being used
|
2013-09-04 17:57:41 +04:00
|
|
|
var notification = {
|
|
|
|
type: 'success',
|
2013-11-22 07:17:38 +04:00
|
|
|
message: 'Check your email for further instructions',
|
2014-04-29 00:58:18 +04:00
|
|
|
status: 'passive'
|
2013-09-04 17:57:41 +04:00
|
|
|
};
|
|
|
|
|
2014-06-16 09:24:19 +04:00
|
|
|
return api.notifications.add({ notifications: [notification] }).then(function () {
|
2014-01-05 10:40:53 +04:00
|
|
|
res.json(200, {redirect: config().paths.subdir + '/ghost/signin/'});
|
2013-09-04 17:57:41 +04:00
|
|
|
});
|
2013-09-01 02:20:12 +04:00
|
|
|
|
2013-09-04 17:57:41 +04:00
|
|
|
}, function failure(error) {
|
2013-11-22 07:17:38 +04:00
|
|
|
// TODO: This is kind of sketchy, depends on magic string error.message from Bookshelf.
|
|
|
|
if (error && error.message === 'EmptyResponse') {
|
|
|
|
error.message = "Invalid email address";
|
|
|
|
}
|
|
|
|
|
2013-09-01 02:20:12 +04:00
|
|
|
res.json(401, {error: error.message});
|
2013-11-22 07:17:38 +04:00
|
|
|
});
|
|
|
|
},
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: reset
|
|
|
|
// Path: /ghost/reset/:token
|
|
|
|
// Method: GET
|
2013-11-22 07:17:38 +04:00
|
|
|
'reset': function (req, res) {
|
2013-12-06 12:51:35 +04:00
|
|
|
// Validate the request token
|
|
|
|
var token = req.params.token;
|
2013-11-22 07:17:38 +04:00
|
|
|
|
|
|
|
api.users.validateToken(token).then(function () {
|
|
|
|
// Render the reset form
|
|
|
|
res.render('reset', {
|
|
|
|
bodyClass: 'ghost-reset',
|
|
|
|
hideNavbar: true,
|
|
|
|
adminNav: setSelected(adminNavbar, 'reset')
|
|
|
|
});
|
|
|
|
}).otherwise(function (err) {
|
|
|
|
// Redirect to forgotten if invalid token
|
|
|
|
var notification = {
|
|
|
|
type: 'error',
|
2014-04-29 00:58:18 +04:00
|
|
|
message: 'Invalid or expired token'
|
2013-11-22 07:17:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
errors.logError(err, 'admin.js', "Please check the provided token for validity and expiration.");
|
|
|
|
|
2014-06-16 09:24:19 +04:00
|
|
|
return api.notifications.add({ notifications: [notification] }).then(function () {
|
2014-01-05 10:40:53 +04:00
|
|
|
res.redirect(config().paths.subdir + '/ghost/forgotten');
|
2013-11-22 07:17:38 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2014-06-20 13:15:01 +04:00
|
|
|
// TODO: remove when old admin is removed, functionality lives now in api/authentication
|
2014-02-25 14:51:12 +04:00
|
|
|
// Route: doReset
|
|
|
|
// Path: /ghost/reset/:token
|
|
|
|
// Method: POST
|
|
|
|
'doReset': function (req, res) {
|
2013-12-06 12:51:35 +04:00
|
|
|
var token = req.params.token,
|
2013-11-22 07:17:38 +04:00
|
|
|
newPassword = req.param('newpassword'),
|
|
|
|
ne2Password = req.param('ne2password');
|
|
|
|
|
|
|
|
api.users.resetPassword(token, newPassword, ne2Password).then(function () {
|
|
|
|
var notification = {
|
|
|
|
type: 'success',
|
|
|
|
message: 'Password changed successfully.',
|
2014-04-29 00:58:18 +04:00
|
|
|
status: 'passive'
|
2013-11-22 07:17:38 +04:00
|
|
|
};
|
|
|
|
|
2014-06-16 09:24:19 +04:00
|
|
|
return api.notifications.add({ notifications: [notification] }).then(function () {
|
2014-01-05 10:40:53 +04:00
|
|
|
res.json(200, {redirect: config().paths.subdir + '/ghost/signin/'});
|
2013-11-22 07:17:38 +04:00
|
|
|
});
|
|
|
|
}).otherwise(function (err) {
|
|
|
|
res.json(401, {error: err.message});
|
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
}
|
|
|
|
};
|
2013-05-11 20:44:25 +04:00
|
|
|
|
2013-08-09 05:22:49 +04:00
|
|
|
module.exports = adminControllers;
|