Answer the question
In order to leave comments, you need to log in
Run a function in an Angular.js run block?
After server reboot. The session on the server is lost. And the cookie remains on the client. I want to log in the user once when starting the application.
MainController it's my parent over ng-view
$rootScope.reLogin = function relog(){
console.log('try to login');
var userCookie = $cookies.getObject('user');
if(!userCookie){
return false;
}
var user = {username: userCookie.username , password: userCookie.password};
authService.login(user)
.then(function(response){
if(response.state === 'success'){
return true;
}
else{
$rootScope.authenticated = false;
$rootScope.current_user = {};
$rootScope.error_message = response.message;
$cookies.remove('user');
}
},
function(response){
$rootScope.error_message = "Some error with login " + response.status;
}
);
};
$rootScope.reLogin();
$rootScope.$on('$routeChangeSuccess', function() {});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question