login-block.component.ts
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {Input, Inject, Component} from "ng-forward";
import {SessionService, AuthService, IAuthEvents, AUTH_EVENTS} from "./../../../login";
/**
* @ngdoc controller
* @name layout.blocks.LoginBlockComponent
* @description
* The Noosfero block responible for presenting a login form and user status
*/
@Component({
selector: "noosfero-login-block",
templateUrl: 'app/layout/blocks/login-block/login-block.html',
})
@Inject("SessionService", "$state", 'AuthService', "$scope")
export class LoginBlockComponent {
/**
* @ngdoc property
* @name currentUser
* @propertyOf layout.blocks.LoginBlockComponent
* @description
* The current loged in user
*/
currentUser: noosfero.User;
/**
* @ngdoc property
* @name credentials
* @propertyOf layout.blocks.LoginBlockComponent
* @description
* The credentials of the currentUser
*/
credentials: noosfero.Credentials;
constructor(
private session: SessionService,
private $state: ng.ui.IStateService,
private authService: AuthService,
private $scope: ng.IScope) {
this.currentUser = this.session.currentUser();
this.$scope.$on(AUTH_EVENTS.loginSuccess, () => {
this.currentUser = this.session.currentUser();
});
this.$scope.$on(AUTH_EVENTS.logoutSuccess, () => {
this.currentUser = this.session.currentUser();
});
}
/**
* @ngdoc method
* @name login
* @methodOf layout.blocks.LoginBlockComponent
* @description
* Logs in the user using its credentials
*/
login() {
this.authService.login(this.credentials);
}
/**
* @ngdoc method
* @name logout
* @methodOf layout.blocks.LoginBlockComponent
* @description
* Logout the user
*/
logout() {
this.authService.logout();
};
}