Last active
August 29, 2015 14:18
-
-
Save zewa666/a6bc9ab8d7b0c927ffca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Router} from 'aurelia-router'; | |
import bootstrap from 'bootstrap'; | |
import {EventAggregator} from 'aurelia-event-aggregator'; | |
export class App { | |
static inject() { return [ Router, EventAggregator ];} | |
constructor(router, ea) { | |
this.router = router; | |
this.isLoggedIn = false; | |
this.ea = ea; | |
var test = "Welcome"; | |
this.router.configure(config => { | |
config.title = 'Aurelia'; | |
config.addPipelineStep('authorize', AuthorizeStep); | |
config.map([ | |
{ route: ['','welcome'], moduleId: './welcome', nav: true, title:test }, | |
{ route: 'flickr', moduleId: './flickr', auth: true, nav: true }, | |
{ route: 'login', moduleId: './login', nav: false }, | |
{ route: 'child-router', moduleId: './child-router', nav: true, title:'Child Router' } | |
]); | |
}); | |
this.ea.subscribe('login', (credentials) => { | |
if(credentials.username === 'test' && | |
credentials.pass === 'pass') | |
this.isLoggedIn = true; | |
this.router.navigate('flickr'); | |
}); | |
} | |
} | |
class AuthorizeStep { | |
static inject(){ | |
return [App]; | |
} | |
constructor(app){ | |
this.app = app; | |
} | |
run( routingContext, next ) { | |
if( routingContext.nextInstructions.some( i => i.config.auth ) ) { | |
if( !this.app.isLoggedIn ) { | |
routingContext.router.navigate('login'); | |
return next.cancel(); | |
} | |
return next(); | |
} else { | |
return next(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {EventAggregator} from 'aurelia-event-aggregator'; | |
export class Login { | |
static inject() { return [EventAggregator]; } | |
constructor(ea) { | |
this.ea = ea; | |
} | |
doLogin() { | |
this.ea.publish('login', { username: 'test', pass: 'pass' }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment