-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
39 lines (33 loc) · 941 Bytes
/
controller.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
angular.module('test').controller('controller',function($scope,$rootScope,$location,$mdDialog){
$scope.login=function(user,password){
for(i=0;i<$rootScope.tempUsers.length;i++){
if($rootScope.tempUsers[i].userId==user && $rootScope.tempUsers[i].password==password){
$rootScope.loggedIn=true;
localStorage.setItem('user',user);
$location.path('/inbox');
$scope.log=true;
break;
}
else{
$scope.log=false;
}
}
if(!$scope.log){
$mdDialog.show(
$mdDialog.alert()
.parent(angular.element(document.querySelector('#popupContainer')))
.clickOutsideToClose(true)
.title('Error')
.textContent('Enter valid credentials')
.ariaLabel('Alert')
.ok('Got it!')
);
}
}
$scope.logout=function(){
localStorage.removeItem('user');
localStorage.removeItem('data');
$rootScope.loggedIn=false;
$location.path('/login');
};
});