auth-user.directive.js
1.26 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
(function() {
'use strict';
angular
.module('dialoga')
.directive('authUser', authUser);
/** @ngInject */
function authUser() {
/** @ngInject */
function AuthUserController($scope, AuthService, Session, AUTH_EVENTS, $log) {
$log.debug('AuthUserController');
var vm = this;
vm.$scope = $scope;
vm.AuthService = AuthService;
vm.Session = Session;
vm.AUTH_EVENTS = AUTH_EVENTS;
vm.$log = $log;
vm.init();
}
AuthUserController.prototype.init = function (){
var vm = this;
vm.currentUser = vm.Session.getCurrentUser();
// handle login
vm.$scope.$on(vm.AUTH_EVENTS.loginSuccess, function () {
vm.currentUser = vm.Session.getCurrentUser();
});
// handle logout
vm.$scope.$on(vm.AUTH_EVENTS.logoutSuccess, function () {
vm.currentUser = vm.Session.getCurrentUser();
});
};
AuthUserController.prototype.onClickLogout = function (){
var vm = this;
vm.AuthService.logout();
};
var directive = {
restrict: 'E',
templateUrl: 'app/components/auth-user/auth-user.html',
controller: AuthUserController,
controllerAs: 'vm',
bindToController: true
};
return directive;
}
})();