mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
|
var Promise = require('bluebird'),
|
||
|
models = require('../models'),
|
||
|
errors = require('../errors');
|
||
|
|
||
|
/**
|
||
|
* If the setup is completed and...
|
||
|
* 1. the public client does exist, deny to switch to local
|
||
|
* 2. the public client does not exist, deny to switch to remote
|
||
|
*/
|
||
|
exports.switch = function validate(options) {
|
||
|
var authType = options.authType;
|
||
|
|
||
|
return models.User.isSetup()
|
||
|
.then(function (isSetup) {
|
||
|
if (!isSetup) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
return models.Client.findOne({slug: 'ghost-auth'}, {columns: 'id'})
|
||
|
.then(function (client) {
|
||
|
if ((client && authType === 'password') || !client && authType === 'ghost') {
|
||
|
return Promise.reject(new errors.InternalServerError({
|
||
|
code: 'AUTH_SWITCH',
|
||
|
message: 'Switching the auth strategy is not allowed.',
|
||
|
context: 'Please reset your database and start from scratch.',
|
||
|
help: 'NODE_ENV=production|development knex-migrator reset && NODE_ENV=production|development knex-migrator init\n'
|
||
|
}));
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
};
|