- Posts: 3
- Thank you received: 0
Please Log in or Create an account to join the conversation.
function ($scope, $stateParams, Session, $state) {
$scope.data = {
'username': '',
'password': ''
}
$scope.error = '';
$scope.login = function(){
$scope.error = '';
Session.add($scope.data).then(function(){
$state.go('menu.home');
}, function(){
$scope.error = 'Error logging in.';
})
}
}
angular.module('app.services', [])
.service('Session', ['$http', function($http){
var api_url = 'http://xxx/portal/index.php/api/';
var ret = {
add: function(data){
return $http.get(api_url+'post/user/login?username='+data.username+'&password='+data.password).then(function(resp){
console.log(resp);
//if (resp.data.status == 'ko') return 0;
//return resp.data;
});
},
}
return ret;
}]);
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
angular.module('app.services', [])
.service('LoginCtrl', ['$http', '$q', function($http, $q){
var api_url = 'https://xxxx/api/';
var SessID = null;
var ret = {
loginUser: function(data){
var deferred = $q.defer();
$http.post(api_url+'post/user/login?username='+data.username+'&password='+data.password).then(function(resp){
console.log(resp);
if (resp.data.status == 'ok') {
deferred.resolve(resp.data);
SessID = resp.data.session_id;
//console.log(SessID);
} else {
deferred.reject('Wrong credentials.');
}
});
return deferred.promise;
},
isAuthenticated: function(){
//console.log(SessID);
if (SessID !== null) {
return true;
} else {
return false;
}
},
logoutUser: function(){
var deferred = $q.defer();
$http.get(api_url+'get/user/logout?session_id='+SessID).then(function(resp){
console.log(resp);
SessID = null;
//console.log(SessID);
deferred.resolve(resp.data);
});
return deferred.promise;
},
}
return ret;
}]);
Please Log in or Create an account to join the conversation.
1) currently I can only access the SessID variable from within this angular module. Obviously, I will need to access it from every page of the app and in every module. What is the best way to make this variable "global" (is that even the right terminology? angular noob).
2) One page of my app uses an iframe to fetch an object from the website. About 50% of the time, I find that I am already logged in by nature of logging into the app. The rest of the time, I am presented with the login screen. I know the above functions rely on "session id," but is there a way to ensure that the proper cookie or session id is always passed to the iframe.
Please Log in or Create an account to join the conversation.