-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.js
48 lines (38 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module.exports.register = register
module.exports.register.attributes = {
name: 'hoodie-server'
}
var format = require('util').format
var getConfig = require('./lib/config')
var registerPlugins = require('./lib/plugins')
function register (server, options, next) {
getConfig(server, options, function (error, config) {
if (error) {
return next(error)
}
registerPlugins(server, config, function (error) {
if (error) {
return next(error)
}
// add / remove user databases on signups / account deletions
server.plugins.account.api.accounts.on('add', function (account) {
server.log(['account', 'info'], format('created for %s (id: %s)', account.username, account.id))
server.plugins.store.api.create('user/' + account.id, {
access: ['read', 'write'],
role: ['id:' + account.id]
})
.then(function (dbName) {
server.log(['store', 'info'], format('database %s created', dbName))
})
})
server.plugins.account.api.accounts.on('remove', function (account) {
server.log(['account', 'info'], format('removed for %s (id: %s)', account.username, account.id))
server.plugins.store.api.destroy('user/' + account.id)
.then(function (dbName) {
server.log(['store', 'info'], format('database %s destroyed', dbName))
})
})
next(null, server, config)
})
})
}