【发布时间】:2017-07-26 15:26:03
【问题描述】:
我无法根据身份验证时使用的电子邮件 ID 从 mongodb 检索数据。我正在创建一个简单的网络应用程序,用户可以在其中捐赠他们的书籍。
用户必须首先使用电子邮件和密码凭据登录应用程序。 当用户捐赠一本书时,数据会以下列方式(angularjs)存储在 mongodb 中名为“books”的表中:
Description of book:
<form id="myForm" name="myForm" action="" method="">
<table class="responstable">
<tr><td>Book's name:</td>
<td><input type="text" ng-model="don.donor"/></td></tr>
<tr><td>Donor's phone number:</td>
<td><input type="text" ng-model="don.phone" /></td></tr>
<tr><td>Your email_id</td>
<td ng-init="des.email = '<%= user.local.email %>'">{{don.email}}</td></tr>
</table><br>
<center><input id="check" name="check"type="submit" value="Donate" ng-click="donate();"/></center>
</form>
用户的电子邮件 ID 会在他每次捐赠一本书时被存储。
这是 server.js 文件中的代码:
var dbdes= mongojs('books' , ['books']);
app.post('/books', function(req, res){
console.log(req.body);
dbdes.books.insert(req.body, function(err, doc){
res.json(doc);
})
});
这是controller.js文件中的代码:
$scope.donate = function(event){
console.log($scope.don);
event.preventDefault();
$http.post('/books', $scope.don).success(function(response){
console.log(response);
});
};
该应用有另一个标签历史记录。在点击历史记录时,用户必须能够查看他捐赠的所有书籍的详细信息。
历史按钮:
<a ng-click=" gethistory('<%= user.local.email %>');" ></span><span class="r">History</a>
我正在使用下表:
<table>
<tr> <td>Name of the book:</td> </tr>
<tr ng-repeat="y in books">
<td>{{y.name}}</td> </tr>
</table>
以下代码正在正确获取电子邮件(如控制台显示:GET /books/srinidhiraichur1234@gmail.com 304 14ms),但条目未显示在网页上。为了检索用户的个人捐赠,我应该对服务器和控制器文件进行哪些更改。
server.js:
app.get('/books', function (req , res){
dbdes.books.find(function(err,docs){
console.log(docs);
res.json(docs);
});
});
controller.js:
$scope.gethistory = function(email){
console.log(email);
$http.get('/books/' + email).success(function(response){
//this line is printing. but i cant see the details on the web page
console.log("i got the data requested - history");
$scope.books = response;
$scope.y = "";
})
};
【问题讨论】:
-
你如何验证你的用户?
-
注册时,用户必须输入他的emailid和密码,这些密码存储在一个表格中。虽然捐赠用户的电子邮件 ID 完美地存储在字段名称电子邮件下的书籍中。@Varedis
标签: angularjs node.js mongodb express mongoose