-
Notifications
You must be signed in to change notification settings - Fork 1
/
ctrl.js
66 lines (39 loc) · 1.39 KB
/
ctrl.js
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
'use strict';
angular.module('angularjsbs').controller('LoginCtrl', ['$scope','loginFactory', function($scope, loginFactory){
$scope.user = {};
$scope.user.role = 'superAdmin'
$scope.login = function(user){
loginFactory.login($scope.user).then(function(good){
$scope.setUser(good);
});
}
}]);
angular.module('angularjsbs').controller('MainCtrl', ['$scope', '$rootScope', '$location', 'USER_ROLES', 'AuthService', function($scope, $rootScope, $location, USER_ROLES, AuthService){
$scope.currentUser = null;
$scope.isAuthorized = AuthService.isAuthorized;
$scope.setUser = function(user){
var p = null;
if(user.role == 'superAdmin'){
user.roleCode = USER_ROLES.superAdmin;
p = 'admin';
}else if(user.role == 'admin'){
user.roleCode = USER_ROLES.admin;
p = 'admin';
}else if(user.role == 'normal'){
user.roleCode = USER_ROLES.normal;
p = 'normal';
}
if(p !== null){
p = '/' + p;
user.id = parseInt(Math.random() * 1000);
$scope.currentUser = user;
$rootScope.currentUser = user;
AuthService.newSession(user);
$location.path(p)
}else
alert('Unable to Log You In :(');
}
}]);
angular.module('angularjsbs').controller('AdminCtrl', ['$scope', function($scope){
$scope.user = $scope.$parent.currentUser;
}]);