Since login page is my index page, i want to authenticate user name and password using mongodb.
Res/res works fine when url is something like this localhost:3000/#/login . But same not working on localhost:3000/#/ url why..
Below is my code
server.get('/', function(req, res)
{
console.log("A")
var status=""
user.findOne({name: req.query.username}, function(err, users)
{
if( err || !users)
{
console.log("No users found");
status="failed"
res.send(status);
}
else
{
if(users.password===req.query.password)
{
status="success"
res.send(status);
}
else
{
status="failed"
res.send(status);
}
}
})
});
Http get Request
angular.module("Fms").controller('LoginCtrl',['$scope','$http','$location',function($scope,$http,$location)
{
$scope.results ="";
$scope.name ="";
$scope.pass ="";
$scope.errormessage="";
$scope.login=function()
{
$http(
{
method: 'get',
url: '/',
params : {username:$scope.name,password:$scope.pass},
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
}).
success(function(response)
{
if(response=="success")
{
$scope.errormessage="";
$location.path("/home")
}
else
{
$scope.errormessage="Enter valid Username & Password";
}
}).
error(function(response)
{
});
}
}]);