2013-12-06 09:51:35 +01:00
|
|
|
var config = require('../config'),
|
2014-02-05 00:40:30 -08:00
|
|
|
_ = require('lodash'),
|
2013-09-24 12:46:30 +02:00
|
|
|
path = require('path'),
|
2013-11-21 21:17:38 -06:00
|
|
|
when = require('when'),
|
2013-09-24 12:46:30 +02:00
|
|
|
api = require('../api'),
|
2014-05-09 12:11:29 +02:00
|
|
|
errors = require('../errors'),
|
2013-11-07 16:00:39 +00:00
|
|
|
storage = require('../storage'),
|
2014-01-03 15:50:03 +00:00
|
|
|
updateCheck = require('../update-check'),
|
2014-07-01 00:26:08 +01:00
|
|
|
adminControllers;
|
2013-05-29 01:10:39 +01:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
adminControllers = {
|
2014-07-01 00:26:08 +01:00
|
|
|
// Route: index
|
|
|
|
// Path: /ghost/
|
|
|
|
// Method: GET
|
2014-02-26 23:15:31 +00:00
|
|
|
'index': function (req, res) {
|
|
|
|
/*jslint unparam:true*/
|
2014-06-23 17:01:43 +01:00
|
|
|
var userData,
|
2014-07-01 00:26:08 +01:00
|
|
|
// config we need on the frontend
|
2014-06-23 17:01:43 +01:00
|
|
|
frontConfig = {
|
2014-06-24 00:24:13 +01:00
|
|
|
apps: config().apps,
|
|
|
|
fileStorage: config().fileStorage
|
2014-06-23 17:01:43 +01:00
|
|
|
};
|
2014-05-09 00:00:10 -05:00
|
|
|
|
2014-02-25 10:51:12 +00:00
|
|
|
function renderIndex() {
|
2014-07-01 00:26:08 +01:00
|
|
|
res.render('default', {
|
|
|
|
user: userData,
|
|
|
|
config: JSON.stringify(frontConfig)
|
2014-02-25 10:51:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
when.join(
|
|
|
|
updateCheck(res),
|
|
|
|
when(renderIndex())
|
|
|
|
// an error here should just get logged
|
|
|
|
).otherwise(errors.logError);
|
|
|
|
},
|
|
|
|
// Route: upload
|
|
|
|
// Path: /ghost/upload/
|
|
|
|
// Method: POST
|
|
|
|
'upload': function (req, res) {
|
2013-09-28 14:54:26 +01:00
|
|
|
var type = req.files.uploadimage.type,
|
2013-08-13 21:04:07 +01:00
|
|
|
ext = path.extname(req.files.uploadimage.name).toLowerCase(),
|
2013-11-07 16:00:39 +00:00
|
|
|
store = storage.get_storage();
|
2013-09-28 14:54:26 +01:00
|
|
|
|
2013-11-12 11:37:54 -07: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 14:54:26 +01:00
|
|
|
return res.send(415, 'Unsupported Media Type');
|
|
|
|
}
|
2013-08-05 18:31:29 +01:00
|
|
|
|
2013-11-07 16:00:39 +00:00
|
|
|
store
|
|
|
|
.save(req.files.uploadimage)
|
2013-09-28 14:54:26 +01:00
|
|
|
.then(function (url) {
|
2013-11-07 16:00:39 +00:00
|
|
|
return res.send(url);
|
2013-09-28 14:54:26 +01:00
|
|
|
})
|
|
|
|
.otherwise(function (e) {
|
2014-01-11 13:40:21 +00:00
|
|
|
errors.logError(e);
|
|
|
|
return res.send(500, e.message);
|
2013-08-05 18:31:29 +01:00
|
|
|
});
|
|
|
|
},
|
2014-02-25 10:51:12 +00:00
|
|
|
|
|
|
|
// Route: doSignup
|
2014-07-01 00:26:08 +01:00
|
|
|
// Path: /ghost/setup/
|
2014-02-25 10:51:12 +00:00
|
|
|
// Method: POST
|
2014-06-30 14:58:10 +02:00
|
|
|
'doSignup': function (req, res) {
|
2013-12-06 09:51:35 +01:00
|
|
|
var name = req.body.name,
|
2013-09-08 21:16:40 +02:00
|
|
|
email = req.body.email,
|
2014-04-28 21:42:38 +01:00
|
|
|
password = req.body.password,
|
2014-06-25 14:12:48 +02:00
|
|
|
blogTitle = req.body.blogTitle,
|
2014-04-28 21:42:38 +01:00
|
|
|
users = [{
|
|
|
|
name: name,
|
|
|
|
email: email,
|
|
|
|
password: password
|
|
|
|
}];
|
2014-07-01 00:26:08 +01:00
|
|
|
|
2014-06-30 14:58:10 +02:00
|
|
|
api.users.register({users: users}).then(function () {
|
|
|
|
var settings = [];
|
2014-06-25 14:12:48 +02: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-28 13:42:52 -08:00
|
|
|
var message = {
|
2014-05-09 00:12:18 +01: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 14:58:10 +02:00
|
|
|
};
|
2014-05-09 00:12:18 +01:00
|
|
|
|
|
|
|
api.mail.send(payload).otherwise(function (error) {
|
2014-01-12 21:49:24 +00: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-28 13:42:52 -08:00
|
|
|
});
|
2014-06-30 14:58:10 +02:00
|
|
|
res.json(200, {
|
|
|
|
redirect: config().paths.subdir + '/ghost/'
|
2013-11-24 15:29:36 +01:00
|
|
|
});
|
2014-06-30 14:58:10 +02:00
|
|
|
|
2013-09-17 03:08:36 +01:00
|
|
|
});
|
|
|
|
}).otherwise(function (error) {
|
2013-08-18 22:50:42 +01:00
|
|
|
res.json(401, {error: error.message});
|
|
|
|
});
|
2013-06-25 12:43:15 +01:00
|
|
|
}
|
|
|
|
};
|
2013-05-11 17:44:25 +01:00
|
|
|
|
2013-08-09 02:22:49 +01:00
|
|
|
module.exports = adminControllers;
|