Merge branch 'github-master'

This commit is contained in:
斟酌 鵬兄 2016-06-29 12:13:03 +08:00
commit b0e52f3d6a
3 changed files with 38 additions and 19 deletions

View File

@ -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,8 +134,19 @@ class WNSAuth extends EventEmitter
this.__send( data.token, NotisQ, ( sender, e ) => {
Dragonfly.Debug( "Send: " + e.statusCode );
if( e.statusCode != 200 )
switch( e.statusCode )
{
case 200: break;
case 410:
Dragonfly.Info( "Channel is expired: " + NotisQ.id );
data.expired = true;
data.save( x => {
Dragonfly.Info( "Mark expired: " + NotisQ.id );
});
break;
default:
AuthToken = null;
Dragonfly.Info( "Perhaps access token is expired, retrying ..." );
@ -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
{

View File

@ -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" );

View File

@ -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