Blame view
app/views/login/login.service.js
2.07 KB
5c6477d3d
|
1 2 |
(function() { 'use strict'; |
9835dbe3e
|
3 |
angular.module('acuefuel') |
cf2b34983
|
4 |
.service('LoginService', ['$rootScope', '$q', '$http', 'BE', '$state', LoginService]) |
5c6477d3d
|
5 |
|
cf2b34983
|
6 |
function LoginService($rootScope, $q, $http, BE, $state) { |
5c6477d3d
|
7 8 9 10 11 12 |
this.loginUser = function(data) { var deferred = $q.defer(); $http({ method : 'POST', |
0a4eb77cc
|
13 |
url : BE.url +'/login', |
5c6477d3d
|
14 15 16 17 |
headers : {'Content-Type': 'application/x-www-form-urlencoded'}, data : data }) .success(function(result) { |
0a4eb77cc
|
18 |
deferred.resolve(result.data); |
5c6477d3d
|
19 20 21 |
}) return deferred.promise; } |
0a4eb77cc
|
22 23 24 25 26 |
this.authenticate = function() { var deferred = $q.defer(); $http({ method : 'GET', |
cf2b34983
|
27 |
url : BE.url+'/user/authenticate', |
0a4eb77cc
|
28 29 30 |
headers : {'Content-Type': 'application/x-www-form-urlencoded'} }).then(function (result){ console.log(result) |
cf2b34983
|
31 32 33 34 35 36 37 38 |
if(result.data.user.admin == true){ window.localStorage.setItem('loginId', result.data.id); window.localStorage.setItem('loginData', JSON.stringify(result.data.userProfile)); $state.go('index.dashboard'); }else{ localStorage.clear(); toastr.info("Unauthorized"); } |
0a4eb77cc
|
39 40 41 42 43 44 45 46 47 48 |
deferred.resolve(result.data); },function (result){ deferred.resolve(result.data); }); return deferred.promise; } this.setAuth = function(data) { localStorage.setItem('loginStatus', data); } |
cf2b34983
|
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
this.logout = function(data) { var deferred = $q.defer(); $http({ method : 'POST', url : BE.url +'/user/logout', headers : {'Content-Type': 'application/x-www-form-urlencoded'}, data : data }) .success(function(result) { deferred.resolve(result.data); }) return deferred.promise; } |
5c6477d3d
|
64 65 66 |
} })(); |