authentication.controller.js
2.02 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
(function(){
'use strict';
angular.module('sbAdminApp')
.controller('LoginCtrl', ['$scope', '$rootScope', '$state','$mdDialog','$log', 'AUTH_EVENTS', 'LoginService', 'toaster', loginCtrl]);
function loginCtrl($scope, $rootScope, $state, $mdDialog,$log, AUTH_EVENTS, LoginService ,toaster) {
$scope.doLogin = function() {
$rootScope.auth = window.btoa($scope.loginData.email + ':' + $scope.loginData.password);
LoginService.doLogin().save($scope.loginData).$promise.then(function(result) {
console.log("result",result);
if(result){
$rootScope.$broadcast(AUTH_EVENTS.updateUser);
LoginService.setUser(result);
/*if(result.role === 'admin'){
$state.go("app.user");
} else {
$state.go("app.");
} */
$state.go("app.user");
}
if (Notification.permission !== 'denied') {
Notification.requestPermission(function(permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
/*var notification = new Notification("Hello!");*/
}
});
}
},
function error(error) {
console.log("ererrorror",error);
if(error){
toaster.error("server error");
}
});
}
$scope.signUp=function(){
LoginService.signUp().save($scope.signupData).$promise.then(function(result) {
console.log("result",result);
// toaster.success("signed up successfully")
$mdDialog.show(
$mdDialog.alert()
.clickOutsideToClose(true)
.title()
.textContent("Please check your email and click on the verification link before logging in.")
.ariaLabel('Alert')
.ok('ok')
);
});
}
}
})();