From e1f2926f64441759cfaddc49151a1981c6a3a093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Fri, 12 Feb 2016 05:10:14 +0800 Subject: [PATCH] Added remove action --- notify-term/WNSAuth.js | 19 ++++++++++++++++++- notify-term/app.js | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/notify-term/WNSAuth.js b/notify-term/WNSAuth.js index 45a1a63..02c212c 100644 --- a/notify-term/WNSAuth.js +++ b/notify-term/WNSAuth.js @@ -82,15 +82,21 @@ class WNSAuth extends EventEmitter , { upsert: true } ) .exec( ( err, data ) => { + if( err ) { Dragonfly.Error( err ); handler( _self, "Server Error: Cannot save channel information" ); return; } + + // Success handler( _self, uuid ); } ); + + return; } + handler( _self, e.statusCode + " Server Error: Unable to push message to channel" ); } ); }; @@ -106,6 +112,17 @@ class WNSAuth extends EventEmitter } } + Unregister( uuid, handler ) + { + if( uuid == AuthTokenName ) + { + handler( "Malicious action: Trying to remove AuthToken" ); + return; + } + + Model.Tokens.remove({ name: uuid }).exec( handler ); + } + Deliver( NotisQ ) { Model.Tokens @@ -120,7 +137,7 @@ class WNSAuth extends EventEmitter if( data && data.token ) { this.__send( data.token, NotisQ, ( sender, e ) => { - Dragonfly.Debug( e.Data ); + Dragonfly.Debug( "Send: " + e.statusCode ); } ); } else diff --git a/notify-term/app.js b/notify-term/app.js index ab83688..ce761b4 100644 --- a/notify-term/app.js +++ b/notify-term/app.js @@ -45,6 +45,23 @@ class App extends Base case "deliver": this.__sendMesg( query ); break; + + case "remove": + this.OAuth.Unregister( query.id, ( err, data ) => { + + if( err ) + { + Dragonfly.Error( err ); + } + else + { + Dragonfly.Debug( "Removed " + query.id + ": " + data ); + } + + _self.result = "OK"; + _self.plantResult(); + } ); + break; default: this.result = "Invalid Action"; this.plantResult();