Merge branch 'github-master'
This commit is contained in:
commit
b0e52f3d6a
@ -121,7 +121,7 @@ class WNSAuth extends EventEmitter
|
||||
{
|
||||
var _self = this;
|
||||
Model.Tokens
|
||||
.findOne({ name: NotisQ.id })
|
||||
.findOne({ name: NotisQ.id, expired: false })
|
||||
.exec( ( err, data ) => {
|
||||
if( err )
|
||||
{
|
||||
@ -134,24 +134,35 @@ class WNSAuth extends EventEmitter
|
||||
this.__send( data.token, NotisQ, ( sender, e ) => {
|
||||
Dragonfly.Debug( "Send: " + e.statusCode );
|
||||
|
||||
if( e.statusCode != 200 )
|
||||
switch( e.statusCode )
|
||||
{
|
||||
AuthToken = null;
|
||||
Dragonfly.Info( "Perhaps access token is expired, retrying ..." );
|
||||
|
||||
if( NotisQ.Retry < 2 )
|
||||
{
|
||||
_self.once( "AuthComplete", () => {
|
||||
NotisQ.Retry ++;
|
||||
_self.Deliver( NotisQ );
|
||||
case 200: break;
|
||||
case 410:
|
||||
Dragonfly.Info( "Channel is expired: " + NotisQ.id );
|
||||
data.expired = true;
|
||||
data.save( x => {
|
||||
Dragonfly.Info( "Mark expired: " + NotisQ.id );
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Dragonfly.Info( "Retrying exceeded the limit, dropping the message" );
|
||||
}
|
||||
|
||||
_self.Authenticate();
|
||||
break;
|
||||
|
||||
default:
|
||||
AuthToken = null;
|
||||
Dragonfly.Info( "Perhaps access token is expired, retrying ..." );
|
||||
|
||||
if( NotisQ.Retry < 2 )
|
||||
{
|
||||
_self.once( "AuthComplete", () => {
|
||||
NotisQ.Retry ++;
|
||||
_self.Deliver( NotisQ );
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Dragonfly.Info( "Retrying exceeded the limit, dropping the message" );
|
||||
}
|
||||
|
||||
_self.Authenticate();
|
||||
}
|
||||
} );
|
||||
}
|
||||
@ -167,7 +178,12 @@ class WNSAuth extends EventEmitter
|
||||
var _self = this;
|
||||
Model.Tokens.update(
|
||||
{ name: uuid }
|
||||
, { name: uuid, token: ChannelUri, date_created: Date.now() }
|
||||
, {
|
||||
name: uuid
|
||||
, token: ChannelUri
|
||||
, date_created: Date.now()
|
||||
, expired: false
|
||||
}
|
||||
, { upsert: true }
|
||||
)
|
||||
.exec( ( err, data ) => {
|
||||
@ -256,7 +272,10 @@ class WNSAuth extends EventEmitter
|
||||
, { name: AuthTokenName, token: AuthToken, date_created: Date.now() }
|
||||
, { upsert: true }
|
||||
)
|
||||
.exec( ( err, data ) => _self.__emitAuthComplete() );
|
||||
.exec( ( err, data ) => {
|
||||
if( err ) Dragonfly.Error( err );
|
||||
_self.__emitAuthComplete();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -7,7 +7,6 @@ var HttpRequest = cl.load( "botanss.net.HttpRequest" );
|
||||
var Base = cl.load( "botanss.net.PostFrame" );
|
||||
|
||||
var WNSAuth = cl.load( "notifyterm.WNSAuth" );
|
||||
var Model = cl.load( "notifyterm.schema" );
|
||||
var NotisQ = cl.load( "notifyterm.Notis" );
|
||||
var SrvAuth = cl.load( "notifyterm.config.auth" );
|
||||
|
||||
|
@ -25,6 +25,7 @@ var R_Tokens = { type: Schema.Types.ObjectId, ref: "Tokens" };
|
||||
var M_Tokens = new Schema({
|
||||
name: { type: String, unique: true }
|
||||
, token: { type: String }
|
||||
, expired: { type: Boolean, default: false }
|
||||
, date_created: {
|
||||
type: Date
|
||||
, default: Date.now
|
||||
|
Loading…
Reference in New Issue
Block a user