Implement account check (if it's already added).

This commit is contained in:
Valverde Antonio
2014-07-30 19:25:09 +09:00
parent 060b58973c
commit 2e61911f8c
4 changed files with 52 additions and 1 deletions

View File

@@ -14,7 +14,35 @@ module.exports = syrup.serial()
.define(function(options, service, identity, touch, router, push, adb) {
var log = logger.createLogger('device:plugins:account')
router.on(wire.AccountGetMessage, function(channel, message){
router.on(wire.AccountCheckMessage, function(channel, message) {
var reply = wireutil.reply(options.serial)
log.info('Checking if account "%s" is added',message.account)
service.getAccounts(message.type)
.timeout(30000)
.then(function(accounts) {
if(accounts.indexOf(message.account) >= 0) {
push.send([
channel
, reply.okay()
])
}
else {
throw new Error('The account is not added')
}
})
.catch(function(err){
log.error('Account check failed', err.stack)
push.send([
channel
, reply.fail(err.message)
])
})
})
router.on(wire.AccountGetMessage, function(channel, message) {
var reply = wireutil.reply(options.serial)
log.info('Getting account(s) of type "%s"', message.type)