如何获得等同于"req.something"的信息从与nodejs的角度 [英] How to get equivalent of "req.something" from in angular with nodejs

查看:81
本文介绍了如何获得等同于"req.something"的信息从与nodejs的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注有关如何使用nodejs和通行证设置身份验证的教程. ( http://scotch.io/tutorials/javascript/easy-节点身份验证设置和本地)

I'm following a tutorial on how to set up authentication with nodejs and passport. (http://scotch.io/tutorials/javascript/easy-node-authentication-setup-and-local)

本教程让我使用ejs渲染模板并传递Flash数据.

The tutorial has me rendering templates with ejs and passing in flash data.

相反,我想使用angularjs.我遇到麻烦的部分是获取闪存数据.我知道如何使用模板和发送变量,但是在下面的代码中,什么用角度替换"req.flash('signupMessage')"?

Instead of this, I'd like to use angularjs. The part I'm having trouble with is getting the flash data. I know how to use templates and send variables, but what in angular replaces the "req.flash('signupMessage')" in the below code?

这是本教程显示的代码:

This is the code the tutorial shows:

app.get('/signup', function(req, res) {
  // render the page and pass in any flash data if it exists
  res.render('signup.ejs', { message: req.flash('signupMessage') });    
});

这是我设置路线的代码

// public/js/appRoutes.js
angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

$routeProvider

    // show signup form
    .when('/signup', {
        templateUrl: 'views/signup.html',
        controller: 'SignupController'  
    });
$locationProvider.html5Mode(true);

}]);

这是控制器:

 // public/js/controllers/SetupCtrl.js
 angular.module('SignupCtrl', []).controller('SignupController', function($scope) {
     $scope.tagline = 'TEST';
 });

推荐答案

在这里回答了类似的问题:

A similar question was answered here: What is the proper way to log in users using Angular & Express?

TLDR:发布的答案是指向以下链接的,作者在其中描述您需要将所有通行证材料保留在服务器端,然后允许客户端(有角度的材料)请求有关会话的信息. http://vickev.com/#!/article/authentication-in-single-page-applications-node-js-passportjs-angularjs

TLDR: the answer posted was to the following link, where the author describes that you need to keep all the passport stuff on the server side, and then allow the client side (angular stuff) to request information about the session. http://vickev.com/#!/article/authentication-in-single-page-applications-node-js-passportjs-angularjs

这篇关于如何获得等同于"req.something"的信息从与nodejs的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆