Guess i didn't have enough sleep and cannot figure out it. Followed web login online samples, login button works, but not the logout button, the logout is not called in server.js.
Thanks very much !
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider.when('/login', {
templateUrl: '/partials/login.html',
controller: 'authController'
});
$routeProvider.when('/logout', {
templateUrl: '/partials/logout.html',
controller: 'authController',
});
...
);
app.controller('authController', function($scope, $http, $location, $window) {
$scope.user = {username:'', password:''};
$scope.alert = '';
$scope.login = function(user) {
$http.post('/auth/login', user).
success(function(data) {
console.log("you are at /auth/login 0");
$scope.loggedUser = data;
$window.location.href = "/index.html#/systemStatus";
}).
error(function() {
console.log("you are at /auth/login 1");
$scope.alert = 'Login failed'
});
};
$scope.logout = function() {
$http.get('/auth/logout').
success(function() {
console.log("you are at /auth/logout 0");
$scope.loggedUser = {};
}).
error(function() {
console.log("you are at /auth/logout 1");
$scope.alert = 'Logout failed'
});
};
});
login.html (This is the default page, always need to login 1st)
<div ng-controller="authController">
<div style="margin-top:10px" class="form-group">
<div class="col-sm-12 controls">
<a id="btn-login" class="btn btn-success" ng-click="login(user)">Login </a>
</div>
</div>
</div>
main.html (This is the 1st page after successful login)
<html ng-app="myModule" ng-controller="MainCtrl">
...
<div class="container" ng-controller="authController">
<a class="btn btn-md btn-info custom-btn" ng-href="#/logout">Logout</a>
</div>
...
</html>
server.js
app.get('/auth/logout', function(req, res)
{
console.log("logging out ......");
req.session.distory();
req.logout();
//res.redirect('/login.html');
res.send(200);
});