I have one doubt regarding using of session data in Angular.js Application.Suppose after login user has to get into to the dashboard page.When user logged in it save the following data in session.
$selquery = "SELECT * FROM db_user WHERE login_name='".$user_name."' and password='".$password."'";
$selres = mysql_query($selquery);
if(mysql_num_rows($selres ) > 0){
$result=mysql_fetch_array($selres);
$_SESSION["admin_id"]=$result['user_id'];
$_SESSION["admin_user_name"]=$result['first_name']." ".$result['last_name'];
$_SESSION["admin_user_type"]=$result['user_type'];
$_SESSION["admin_email_id"]=$result['email_id'];
$_SESSION["admin_role_id"]=$result['role_id'];
$_SESSION["admin_clg_id"]=$result['colg_id'];
$_SESSION["admin_dept_id"]=$result['dept_id'];
//$result['msg'] = 'Login successfull...';
}else{
header("HTTP/1.0 401 Unauthorized");
$result['msg'] = 'Invalid username or password, Please try again...';
}
I need when user will enter into dashboard page it will check first the session data if present then the dashboard page will display otherwise it will again redirect to login page. I am explaining my controller file below.
dashboardController.js:
var dashboard=angular.module('Channabasavashwara');
dashboard.controller('adminController',function($scope,$http,$state,$window){
//$scope.submenu=false;
//$state.go('dashboard',{}, { reload: true });
$scope.no_of_college=0;
$scope.no_of_stream=0;
$scope.no_of_department=0;
$scope.no_of_course=0;
$scope.no_of_users=0;
//alert("aaaa");
$http({
method: 'GET',
url: 'php/college/getAdminSummery.php',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
$scope.no_of_college = response.data['no_college'];
$scope.no_of_stream = response.data['no_stream'];
$scope.no_of_department = response.data['no_department'];
$scope.no_of_course = response.data['no_course'];
$scope.no_of_users = response.data['no_user'];
//alert("::"+$scope.no_of_college);
},function errorCallback(response) {
$state.go('/',{}, { reload: true });
});
$http({
method: 'GET',
url: 'php/Login/session.php',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
//console.log('session',response);
$scope.userType=response.data[0].first_name+" "+response.data[0].last_name;
},function errorCallback(response) {
$state.go('/',{}, { reload: true });
});
$scope.logout=function(){
$http({
method: 'POST',
url: 'php/Login/logout.php',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
//console.log('session',response);
//alert(response);
},function errorCallback(response) {
//console.log('session',response);
//alert(response);
});
}
})
Here also i need to set the time to destroy the session automatically. Please help me to resolve this issue.