-
Notifications
You must be signed in to change notification settings - Fork 0
/
able-signin.js
89 lines (85 loc) · 2.62 KB
/
able-signin.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(function() {
'use strict';
angular.module('able').directive('signinElement', signinDirective)
function signinDirective() {
var directive = {
restrict: 'A',
controller: signinController,
controllerAs: 'signin',
bindToController: true
}
return directive
}
function signinController(auth, $state, $scope, $http, config) {
var vm = this
vm.email = ''
vm.password = ''
vm.signin = signin
vm.reset = reset
vm.sending = false
function signin() {
vm.sending = true;
var signin = auth.signin(vm.email, vm.password);
signin.then(function(resolve) {
$state.go('storePage.offerPage')
vm.email = ''
vm.password = ''
}, function(reject) {
vm.password = ''
vm.sending = false;
if (reject.status == -1) {
if (navigator && navigator.notification) {
navigator.notification.alert("Verifique sua conexão.", false, 'Able', 'Ok')
} else {
window.alert("Verifique sua conexão.")
}
} else {
if (navigator && navigator.notification) {
navigator.notification.alert("Verifique seus dados e tente novamente.", false, 'Able', 'Ok')
} else {
window.alert("Verifique seus dados e tente novamente.")
}
}
})
}
function reset() {
vm.sending = true
var emailPattern = new RegExp(/^.+@.+\..+$/)
if (!emailPattern.test(vm.email)) {
if (navigator && navigator.notification) {
navigator.notification.alert("Digite um e-mail válido no campo E-mail.", false, 'Able', 'Ok')
} else {
window.alert("Digite um e-mail válido no campo E-mail.")
}
vm.sending = false
return
}
var payload = {
'email': vm.email
};
$http.patch(config.api + '/tokens', payload).then(function successCallback(response) {
vm.sending = false
if (navigator && navigator.notification) {
navigator.notification.alert("Enviamos um e-mail com instruções de recuperação da senha para " + vm.email, false, 'Able', 'Ok')
} else {
window.alert("Enviamos um e-mail com instruções de recuperação da senha para " + vm.email)
}
}, function errorCallback(response) {
vm.sending = false
if (response.data && response.data.errors && response.data.errors[0]) {
if (navigator && navigator.notification) {
navigator.notification.alert(response.data.errors[0].error, false, 'Able', 'Ok')
} else {
window.alert(response.data.errors[0].error)
}
return
}
if (navigator && navigator.notification) {
navigator.notification.alert("Verifique sua conexão.", false, 'Able', 'Ok')
} else {
window.alert("Verifique sua conexão.")
}
});
}
} // end controller
})();