Experiment application model
This commit is contained in:
parent
83ca45e07e
commit
e810213590
|
@ -0,0 +1,45 @@
|
|||
var models = require('../../lib/models');
|
||||
|
||||
var asteroid = require('../../');
|
||||
var app = asteroid();
|
||||
|
||||
app.use(asteroid.rest());
|
||||
|
||||
var dataSource = asteroid.createDataSource('db', {connector: asteroid.Memory});
|
||||
|
||||
var Application = models.Application(dataSource);
|
||||
|
||||
app.model(Application);
|
||||
|
||||
|
||||
var data = {pushSettings: [
|
||||
{ "platform": "apns",
|
||||
"apns": {
|
||||
"pushOptions": {
|
||||
"gateway": "gateway.sandbox.push.apple.com",
|
||||
"cert": "credentials/apns_cert_dev.pem",
|
||||
"key": "credentials/apns_key_dev.pem"
|
||||
},
|
||||
|
||||
"feedbackOptions": {
|
||||
"gateway": "feedback.sandbox.push.apple.com",
|
||||
"cert": "credentials/apns_cert_dev.pem",
|
||||
"key": "credentials/apns_key_dev.pem",
|
||||
"batchFeedback": true,
|
||||
"interval": 300
|
||||
}
|
||||
}}
|
||||
]}
|
||||
|
||||
Application.create(data, function(err, data) {
|
||||
console.log('Created: ', data.toObject());
|
||||
});
|
||||
|
||||
|
||||
Application.register('MyApp', 'My first mobile application', 'rfeng', function (err, result) {
|
||||
console.log(result.toObject());
|
||||
|
||||
result.resetKeys(function (err, result) {
|
||||
console.log(result.toObject());
|
||||
});
|
||||
});
|
|
@ -1,13 +1,30 @@
|
|||
// Authentication schemes
|
||||
var AuthenticationScheme = {
|
||||
var AuthenticationSchemeSchema = {
|
||||
scheme: String, // local, facebook, google, twitter, linkedin, github
|
||||
credential: Object // Scheme-specific credentials
|
||||
}
|
||||
|
||||
var APNSSettingSchema = {
|
||||
pushOptions: {type: {
|
||||
gateway: String,
|
||||
cert: String,
|
||||
key: String
|
||||
}},
|
||||
|
||||
feedbackOptions: {type: {
|
||||
gateway: String,
|
||||
cert: String,
|
||||
key: String,
|
||||
batchFeedback: Boolean,
|
||||
interval: Number
|
||||
}}
|
||||
};
|
||||
|
||||
// Push notification settings
|
||||
var PushNotificationSetting = {
|
||||
var PushNotificationSettingSchema = {
|
||||
platform: {type: String, required: true}, // apns, gcm, mpns
|
||||
configuration: Object // platform-specific configurations
|
||||
// configuration: {type: Object} // platform-specific configurations
|
||||
apns: APNSSettingSchema
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,12 +58,12 @@ var ApplicationSchema = {
|
|||
masterKey: String,
|
||||
|
||||
// Push notification
|
||||
pushSettings: [PushNotificationSetting],
|
||||
pushSettings: [PushNotificationSettingSchema],
|
||||
|
||||
// User Authentication
|
||||
authenticationEnabled: {type: Boolean, default: true},
|
||||
anonymousAllowed: {type: Boolean, default: true},
|
||||
authenticationSchemes: [AuthenticationScheme],
|
||||
authenticationSchemes: [AuthenticationSchemeSchema],
|
||||
|
||||
status: {type: String, default: 'sandbox'}, // Status of the application, production/sandbox/disabled
|
||||
|
||||
|
@ -74,9 +91,17 @@ function generateKey(hmacKey, algorithm) {
|
|||
module.exports = function (dataSource) {
|
||||
dataSource = dataSource || new require('jugglingdb').ModelBuilder();
|
||||
|
||||
// var AuthenticationScheme = dataSource.define('AuthenticationScheme', AuthenticationSchemeSchema);
|
||||
// ApplicationSchema.authenticationSchemes = [AuthenticationScheme];
|
||||
|
||||
// var PushNotificationSetting = dataSource.define('PushNotificationSetting', PushNotificationSettingSchema);
|
||||
// ApplicationSchema.pushSettings = [PushNotificationSetting];
|
||||
|
||||
var Application = dataSource.define('Application', ApplicationSchema);
|
||||
|
||||
// Application.hasMany(AuthenticationScheme, {as: 'authenticationSchemes', foreignKey: 'appId'});
|
||||
// Application.hasMany(PushNotificationSetting, {as: 'pushNotificationSettings', foreignKey: 'appId'});
|
||||
|
||||
Application.afterInitialize = function () {
|
||||
var app = this;
|
||||
// use data argument to update object
|
||||
|
@ -90,8 +115,17 @@ module.exports = function (dataSource) {
|
|||
};
|
||||
|
||||
// Register a new application
|
||||
Application.register = function (name, description, owner) {
|
||||
return new Application({name: name, description: description, owner: owner});
|
||||
Application.register = function (name, description, owner, cb) {
|
||||
Application.create({name: name, description: description, owner: owner}, cb);
|
||||
}
|
||||
|
||||
Application.prototype.resetKeys = function(cb) {
|
||||
this.clientKey = generateKey('client');
|
||||
this.javaScriptKey = generateKey('javaScript');
|
||||
this.restApiKey = generateKey('restApi');
|
||||
this.windowsKey = generateKey('windows');
|
||||
this.masterKey = generateKey('master');
|
||||
this.save(cb);
|
||||
}
|
||||
|
||||
return Application;
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
var ModelBuilder = require('jugglingdb').ModelBuilder;
|
||||
exports.Application = require('./application');
|
||||
exports.ACL = require('./acl');
|
||||
exports.Role = require('./role');
|
||||
exports.Installation = require('./installation');
|
||||
|
||||
var ds = new ModelBuilder();
|
||||
|
||||
exports.Application = require('./application')(ds);
|
||||
exports.ACL = require('./acl')(ds);
|
||||
exports.Role = require('./role')(ds);
|
||||
exports.Installation = require('./installation')(ds);
|
||||
|
||||
/*
|
||||
console.log(new exports.Role());
|
||||
console.log(new exports.ACL());
|
||||
console.log(new exports.Application());
|
||||
console.log(new exports.Installation());
|
||||
*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue