srv/core/AuthenticationService.js
function (context, token, callback) {
            var authentication = this.$.dataSource.createEntity(Authentication, token),
                self = this;

            // setup authentication
            this.$stage.$bus.setUp(authentication);

            flow()
                .seq("authentication", function (cb) {
                    authentication.fetch({noCache: true}, function (err) {
                        if (!err) {
                            var now = new Date();
                            if (authentication.$.updated.getTime() < now.getTime() - (1000 * self.$.tokenLifeTime)) {
                                // remove token
                                authentication.remove();
                                // return error
                                err = AuthenticationError.AUTHENTICATION_EXPIRED;
                            }
                        } else {
                            // TODO: change to authentication not found
                            err = AuthenticationError.AUTHENTICATION_EXPIRED;
                        }

                        cb(err, authentication);
                    });
                })
                .seq(function (cb) {
                    this.vars.authentication.set('updated', new Date());
                    this.vars.authentication.save(null, cb);
                })
                .seq(function (cb) {
                    // init authentication
                    this.vars.authentication.init(cb);
                })
                .exec(function (err, results) {
                    authentication = results.authentication;
                    if (!err && authentication) {
                        context.user.addAuthentication(authentication);
                    }
                    callback && callback(err, authentication);
                });
        }
function (context, token, callback) {
            var authentication = this.$.dataSource.createEntity(Authentication, token),
                self = this;

            // setup authentication
            this.$stage.$bus.setUp(authentication);

            flow()
                .seq("authentication", function (cb) {
                    authentication.fetch({noCache: true}, function (err) {
                        if (!err) {
                            var now = new Date();
                            if (authentication.$.updated.getTime() < now.getTime() - (1000 * self.$.tokenLifeTime)) {
                                // remove token
                                authentication.remove();
                                // return error
                                err = AuthenticationError.AUTHENTICATION_EXPIRED;
                            }
                        } else {
                            // TODO: change to authentication not found
                            err = AuthenticationError.AUTHENTICATION_EXPIRED;
                        }

                        cb(err, authentication);
                    });
                })
                .seq(function (cb) {
                    this.vars.authentication.set('updated', new Date());
                    this.vars.authentication.save(null, cb);
                })
                .seq(function (cb) {
                    // init authentication
                    this.vars.authentication.init(cb);
                })
                .exec(function (err, results) {
                    authentication = results.authentication;
                    if (!err && authentication) {
                        context.user.addAuthentication(authentication);
                    }
                    callback && callback(err, authentication);
                });
        }
function ( context , token , callback ) { var authentication = this . $ . dataSource . createEntity ( Authentication , token ) , self = this ; // setup authentication this . $stage . $bus . setUp ( authentication ) ; flow ( ) . seq ( "authentication" , function ( cb ) { authentication . fetch ( { noCache : true } , function ( err ) { if ( ! err ) { var now = new Date ( ) ; if ( authentication . $ . updated . getTime ( ) < now . getTime ( ) - ( 1000 * self . $ . tokenLifeTime ) ) { // remove token authentication . remove ( ) ; // return error err = AuthenticationError . AUTHENTICATION_EXPIRED ; } } else { // TODO: change to authentication not found err = AuthenticationError . AUTHENTICATION_EXPIRED ; } cb ( err , authentication ) ; } ) ; } ) . seq ( function ( cb ) { this . vars . authentication . set ( 'updated' , new Date ( ) ) ; this . vars . authentication . save ( null , cb ) ; } ) . seq ( function ( cb ) { // init authentication this . vars . authentication . init ( cb ) ; } ) . exec ( function ( err , results ) { authentication = results . authentication ; if ( ! err && authentication ) { context . user . addAuthentication ( authentication ) ; } callback && callback ( err , authentication ) ; } ) ; }
Checks token against a database

@param token
@param callback
Checks token against a database