我对Angular.js Application.Suppose在登录用户必须进入仪表板页面后使用会话数据存在疑问。当用户登录时,会在会话中保存以下数据。
$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...';
}
我需要当用户进入仪表板页面时,它将首先检查会话数据(如果存在),然后将显示仪表板页面,否则它将再次重定向到登录页面。我正在解释下面的控制器文件。
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);
});
}
})
这里我还需要设置自动销毁会话的时间。请帮我解决这个问题。