Angularjs Session Management with Login Authentication using PHP
In this Post We Will Explain About is Angularjs Session Management with Login Authentication using PHP With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to User authentication using AngularJS, PHP, MySQLExample
In this post we will show you Best way to implement How To Handle User Authentication With AngularJS, hear for Simple Angularjs login and logout script using php session and databasewith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
Implementing Authentication in Angular Applications
index.html
[php]
http://live/app/js/jquery.min.js
http://live/app/js/bootstrap.min.js
http://lib/angular/angular.js
http://lib/angular/angular-route.js
http://live/app/js/Chart.min.js
http://live/app/js/angular-chart.js
http://live/app/js/app.js
http://live/app/js/directives/loginDrc.js
http://live/app/js/controllers/loginCtrl.js
http://live/app/js/controllers/homeCtrl.js
http://live/app/js/services/loginService.js
http://live/app/js/services/sessionService.js
[/php]
live_check_session.php
[php]
[/php]
live_destroy_session.php
[php]
[/php]
employer.php
[php]
mail==’admin@gmail.com’ && $employer->pass==’123456789′)
session_start();
$_SESSION[’empid’]=uniqid(‘ang_’);
print $_SESSION[’empid’];
?>
[/php]
homeCtrl.js
[php]
‘use strict’;
app.controller(‘homeCtrl’, [‘$scope’,’$http’,’loginService’, function($scope,$http,loginService){
$scope.txt=’infinityknow.com Page Home’;
$scope.logout=function(){
loginService.logout();
}
}])
[/php]
loginCtrl.js
[php]
‘use strict’;
app.controller(‘loginCtrl’, [‘$scope’,’loginService’, function ($scope,loginService) {
$scope.msgtxt=’infinityknow.com Login’;
$scope.login=function(data){
loginService.login(data,$scope); //infinityknow.com call login service
};
}]);
[/php]
app.js
[php]
‘use strict’;
var app= angular.module(‘liveApp’, [‘ngRoute’,’chart.js’]);
app.config([‘$routeProvider’, function($routeProvider) {
$routeProvider.when(‘/login’, {templateUrl: ‘partials/login.html’, controller: ‘loginCtrl’});
$routeProvider.when(‘/home’, {templateUrl: ‘partials/home.html’, controller: ‘homeCtrl’});
$routeProvider.otherwise({redirectTo: ‘/login’});
}]);
app.run(function($rootScope, $location, loginService){
var routespermission=[‘/home’];
var routesloginpermission=[‘/login’];
$rootScope.$on(‘$routeChangeStart’, function(){
if( routespermission.indexOf($location.path()) !=-1)
{
var connected=loginService.islogged();
connected.then(function(msg){
if(!msg.data) $location.path(‘/login’);
});
}
if( routesloginpermission.indexOf($location.path()) !=-1)
{
var connected=loginService.islogged();
connected.then(function(msg){
if(msg.data) $location.path(‘/home’);
});
}
});
});
[/php]
loginService.js
[php]
‘use strict’;
app.factory(‘loginService’,function($http, $location, sessionService){
return{
login:function(data,scope){
var $promise=$http.post(‘data/employer.php’,data); //send data to employer.php
$promise.then(function(msg){
var empid=msg.data;
if(empid){
sessionService.set(’empid’,empid);
$location.path(‘/home’);
}
else {
scope.msgtxt=’infinityknow.com incorrect information’;
$location.path(‘/login’);
}
});
},
logout:function(){
sessionService.destroy(’empid’);
$location.path(‘/login’);
},
islogged:function(){
var $checkSessionServer=$http.post(‘data/live_check_session.php’);
return $checkSessionServer;
}
}
});
[/php]
sessionService.js
[php]
‘use strict’;
app.factory(‘sessionService’, [‘$http’, function($http){
return{
set:function(key,value){
return sessionStorage.setItem(key,value);
},
get:function(key){
return sessionStorage.getItem(key);
},
destroy:function(key){
$http.post(‘data/live_destroy_session.php’);
return sessionStorage.removeItem(key);
}
};
}])
[/php]
loginDirective.js
[php]
‘use strict’;
app.directive(‘loginDirective’,function(){
return{
templateUrl:’partials/tpl/login.tpl.html’
}
});
[/php]
login.html
[php]
[/php]
home.html
[php]
Your Demo
[/php]
login.tpl.html
[php]
[/php]
I hope you have Got What is Simple Angularjs login and logout script using php session and database And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.