1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-16 11:37:13 +02:00
pigallery2/frontend/app/model/authentication.service.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2016-03-14 14:20:29 +02:00
///<reference path="../../browser.d.ts"/>
2016-03-13 12:28:29 +02:00
import {Injectable} from 'angular2/core';
import {User} from "../../../common/entities/User";
import {Event} from "../../../common/event/Event";
import {UserService} from "./user.service";
import {LoginCredential} from "../../../common/entities/LoginCredential";
import {Message} from "../../../common/entities/Message";
2016-03-13 12:28:29 +02:00
@Injectable()
export class AuthenticationService{
private _user:User = null;
2016-03-13 12:28:29 +02:00
public OnAuthenticated:Event<User>;
constructor(private _userService: UserService){
2016-03-13 12:28:29 +02:00
this.OnAuthenticated = new Event();
}
public login(credential:LoginCredential){
this._userService.login(credential).then( (message:Message<User>) =>{
console.log(message);
if(message.errors && message.errors.length > 0){
console.log(message.errors);
}else{
this._user = message.result;
this.OnAuthenticated.trigger(this._user);
}
});
}
2016-03-13 12:28:29 +02:00
public isAuthenticated():boolean{
return this._user && this._user != null;
2016-03-13 12:28:29 +02:00
}
2016-03-13 12:28:29 +02:00
}