diff --git a/lib/roles/device/plugins/account.js b/lib/roles/device/plugins/account.js index 5a14bcc8..c7170c99 100644 --- a/lib/roles/device/plugins/account.js +++ b/lib/roles/device/plugins/account.js @@ -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) diff --git a/lib/roles/websocket.js b/lib/roles/websocket.js index 584d648b..2e72f286 100644 --- a/lib/roles/websocket.js +++ b/lib/roles/websocket.js @@ -332,6 +332,16 @@ module.exports = function(options) { ) ]) }) + .on('account.check', function(channel, responseChannel, data){ + joinChannel(responseChannel) + push.send([ + channel + , wireutil.transaction( + responseChannel + , new wire.AccountCheckMessage(data) + ) + ]) + }) .on('account.remove', function(channel, responseChannel, data) { joinChannel(responseChannel) push.send([ diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 2c2e0a80..ff3d4d01 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -59,6 +59,7 @@ enum MessageType { WifiGetStatusMessage = 58; AccountAddMenuMessage = 59; AccountAddMessage = 60; + AccountCheckMessage = 63; AccountGetMessage = 62; AccountRemoveMessage = 55; SdStatusMessage = 61; @@ -399,6 +400,11 @@ message AccountAddMessage { required string password = 2; } +message AccountCheckMessage { + required string type = 1; + required string account = 2; +} + message AccountGetMessage { required string type = 1; } diff --git a/res/app/components/stf/control/control-service.js b/res/app/components/stf/control/control-service.js index 8e68a507..2f8ad1f7 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -218,6 +218,13 @@ module.exports = function ControlServiceFactory( return sendTwoWay('screen.capture') } + this.checkAccount = function(type, account) { + return sendTwoWay('account.check', { + type: type + , account: account + }) + } + this.removeAccount = function(type, account) { return sendTwoWay('account.remove', { type: type