I have a login application where I need to implement session and cookies using angular.js. Below is the code for my login functionality.
loginController.js:
var loginAdmin=angular.module('Channabasavashwara');
loginAdmin.controller('loginController',function($scope,$http,$location){
$scope.user_name = '';
$scope.user_pass = '';
$scope.user_login=function(){
if($scope.user_name==''){
alert('Username field should not be blank');
}else if($scope.user_pass==''){
alert('Password field should not be blank');
}else{
var userData={'user_name':$scope.user_name,'user_pass':$scope.user_pass};
console.log('user',userData);
$http({
method: 'POST',
url: "php/Login/login.php",
data: userData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
console.log('response',response);
alert(response.data['msg']);
$location.path('dashboard');
},function errorCallback(response) {
alert(response.data['msg']);
});
}
}
});
My goal is to store the session when the user successfully logs in, and logout automatically after an expiration time (let's say 10 minutes) using cookies with an alert message. Any help would be appreciated!