Javascript 检查用户是否';的电子邮件存在于数据库中
我有一个基本的登录表单,想验证数据库中是否存在用户的电子邮件,但不确定angular+节点的语法 Main.js我在运行此功能的submit按钮上单击了ng。我收到来自输入的电子邮件,不知何故需要将其传递给db检查Javascript 检查用户是否';的电子邮件存在于数据库中,javascript,angularjs,node.js,mongodb,authentication,Javascript,Angularjs,Node.js,Mongodb,Authentication,我有一个基本的登录表单,想验证数据库中是否存在用户的电子邮件,但不确定angular+节点的语法 Main.js我在运行此功能的submit按钮上单击了ng。我收到来自输入的电子邮件,不知何故需要将其传递给db检查 $scope.logIn = function() { var email = $scope.formInfo.email; $http.get('/findUser').success(function(response){ console.log
$scope.logIn = function() {
var email = $scope.formInfo.email;
$http.get('/findUser').success(function(response){
console.log('find user data');
console.log(response);
});
};
Server.js我已连接到数据库,但不确定如何与客户端和后端数据建立连接,也不确定语法是什么
app.get('/findUser', function(req, res){
//what do I do here?
db.rejoin_your_ex.find({ email: 'the user's email' }, function(err, docs){
res.json(docs);
});
});
客户端
$scope.logIn = function() {
var email = $scope.formInfo.email;
$http({
url: '/findUser',
method: "GET",
params: {"email": email}
}).success(function(response){
console.log('find user data');
console.log(response);
});
};
服务器端
$scope.logIn = function() {
var email = $scope.formInfo.email;
$http({
url: '/findUser',
method: "GET",
params: {"email": email}
}).success(function(response){
console.log('find user data');
console.log(response);
});
};
在后端,您可以使用模块进行mongodb特定的查询
var mongo = require('mongoskin');
var db = mongo.db("mongodb://localhost:27017/test");
db.bind('user');
app.get('/findUser', function(req, res){
//what do I do here?
db.user.find({ email: req.params.email }, function(err, user){
res.json(user);
});
});
希望对你有帮助