2016-03-14 20:20:29 +08:00
|
|
|
///<reference path="../browser.d.ts"/>
|
2016-03-13 01:11:19 +08:00
|
|
|
|
2016-03-12 21:57:22 +08:00
|
|
|
import { Component } from 'angular2/core';
|
|
|
|
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router';
|
|
|
|
import {LoginComponent} from "./login/login.component";
|
2016-03-13 18:28:29 +08:00
|
|
|
import {AuthenticationService} from "./model/authentication.service";
|
|
|
|
import {GalleryComponent} from "./gallery/gallery.component";
|
|
|
|
import {OnInit} from "angular2/core";
|
|
|
|
import {User} from "../../common/entities/User";
|
2016-03-19 16:58:27 +08:00
|
|
|
import {Router, Location} from "angular2/router";
|
|
|
|
import {HTTP_PROVIDERS} from "angular2/http";
|
|
|
|
import {UserService} from "./model/user.service";
|
2016-03-12 21:57:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-13 01:11:19 +08:00
|
|
|
|
2016-03-12 21:57:22 +08:00
|
|
|
@Component({
|
|
|
|
selector: 'pi-gallery2-app',
|
|
|
|
template: `<router-outlet></router-outlet>`,
|
|
|
|
directives: [ROUTER_DIRECTIVES],
|
|
|
|
providers: [
|
2016-03-19 16:58:27 +08:00
|
|
|
HTTP_PROVIDERS,
|
2016-03-13 05:19:24 +08:00
|
|
|
ROUTER_PROVIDERS,
|
2016-03-19 16:58:27 +08:00
|
|
|
UserService,
|
|
|
|
AuthenticationService
|
2016-03-12 21:57:22 +08:00
|
|
|
]
|
|
|
|
})
|
|
|
|
@RouteConfig([
|
|
|
|
{
|
|
|
|
path: '/login',
|
|
|
|
name: 'Login',
|
|
|
|
component: LoginComponent,
|
|
|
|
useAsDefault: true
|
2016-03-13 18:28:29 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/gallery',
|
|
|
|
name: 'Gallery',
|
|
|
|
component: GalleryComponent
|
2016-03-12 21:57:22 +08:00
|
|
|
}
|
|
|
|
])
|
2016-03-13 18:28:29 +08:00
|
|
|
export class AppComponent implements OnInit{
|
|
|
|
|
2016-03-19 16:58:27 +08:00
|
|
|
constructor(private _router: Router, private _location:Location, private _authenticationService: AuthenticationService){
|
2016-03-13 18:28:29 +08:00
|
|
|
}
|
2016-03-13 01:11:19 +08:00
|
|
|
|
2016-03-13 18:28:29 +08:00
|
|
|
ngOnInit() {
|
|
|
|
this._authenticationService.OnAuthenticated.on((user:User) =>
|
|
|
|
{
|
2016-03-19 16:58:27 +08:00
|
|
|
this._location.replaceState('/'); // clears browser history so they can't navigate with back button
|
2016-03-13 18:28:29 +08:00
|
|
|
this._router.navigate(["Gallery"]);
|
|
|
|
});
|
2016-03-19 16:58:27 +08:00
|
|
|
|
2016-03-13 01:11:19 +08:00
|
|
|
}
|
2016-03-12 21:57:22 +08:00
|
|
|
}
|