Merge pull request #6544 from ErisDS/client-secret

Move client secret logic into the model
This commit is contained in:
Sebastian Gierlinger 2016-02-22 09:49:05 +01:00
commit 8d6ec8555c
3 changed files with 18 additions and 11 deletions

View File

@ -70,16 +70,12 @@
{
"name": "Ghost Admin",
"slug": "ghost-admin",
"status": "enabled",
"type": "ua",
"secret": "not_available"
"status": "enabled"
},
{
"name": "Ghost Frontend",
"slug": "ghost-frontend",
"status": "enabled",
"type": "ua",
"secret": "not_available"
"status": "enabled"
}
]
}

View File

@ -93,10 +93,6 @@ populate = function populate() {
});
_.each(fixtures.clients, function (client) {
// no random secrets during testing
if (process.env.NODE_ENV.indexOf('testing') !== 0) {
client.secret = crypto.randomBytes(6).toString('hex');
}
ops.push(Client.add(client, options));
});
@ -252,7 +248,6 @@ to004 = function to004() {
if (!client) {
logInfo(i18n.t('notices.data.fixtures.addFrontendClientFixture'));
var frontendClient = fixtures.clients[1];
frontendClient.secret = crypto.randomBytes(6).toString('hex');
return models.Client.add(frontendClient, options);
}
return Promise.resolve();

View File

@ -1,10 +1,26 @@
var ghostBookshelf = require('./base'),
crypto = require('crypto'),
uuid = require('node-uuid'),
Client,
Clients;
Client = ghostBookshelf.Model.extend({
tableName: 'clients',
defaults: function defaults() {
var env = process.env.NODE_ENV,
secret = env.indexOf('testing') !== 0 ? crypto.randomBytes(6).toString('hex') : 'not_available';
return {
uuid: uuid.v4(),
secret: secret,
status: 'development',
type: 'ua'
};
},
trustedDomains: function trustedDomains() {
return this.hasMany('ClientTrustedDomain', 'client_id');
}