我正在尝试用护照教程复制这个本地身份验证。
但与angularJS前端而不是EJS,直到现在一切都工作,但我有一个问题,当我想在配置文件页面显示用户数据(成功登录后)
我说的是这段代码
// =====================================
// PROFILE SECTION =====================
// =====================================
// we will want this protected so you have to be logged in to visit
// we will use route middleware to verify this (the isLoggedIn function)
app.get('/profile', isLoggedIn, function(req, res) {
res.render('profile.ejs', {
user : req.user // get the user out of session and pass to template
});
});
我理解用户是我需要的数据,但在EJS的示例中是这样使用的:
<!-- LOCAL INFORMATION -->
<div class="col-sm-6">
<div class="well">
<h3><span class="fa fa-user"></span> Local</h3>
<p>
<strong>id</strong>: <%= user._id %><br>
<strong>email</strong>: <%= user.local.email %><br>
<strong>password</strong>: <%= user.local.password %>
</p>
</div>
</div>
我可以用AngularJS访问相同的数据吗?我是新手,我不明白
是的,你也可以在Angular中获取数据。希望你已经引导了你的angular应用。使用:
当地
<p>
<strong>id</strong>: {{user._id}}<br>
<strong>email</strong>: {{user.local.email}}<br>
<strong>password</strong>: {{user.local.password}}
</p>
</div>
</div>
这个'user'将使用你在控制器中定义的scope变量
<<p> 控制器功能/strong>function test($scope) {
$scope.user = user; //Need to get this user from the server call (by $http or a service)
}