node.js - Ember.js 如何监听服务器发出的事件?

标签 node.js ember.js passport.js

我在服务器端使用 Node ,并在服务器端合并了 Passport Twitter 身份验证。我的问题是: 当 Twitter 回调响应时,如何向客户端发出信号?

我有两个api端点,一个是初始的twitter身份验证,第二个是回调。

app.get '/twitter', *calling twitter ...*

app.get '/twitter/callback', *callback from twitter ...*

那么ember如何监听服务端的回调事件呢?

最佳答案

我认为ember不能监听回调事件。但是,在回调中您可以更新 ember 对象中的值。

例如,这是 ember Controller 的一些代码和回调

Ember Controller

App.MyController = Em.ObjectController.extend({
  authenticated: false,
  updateAuthStatus: function() {
    Em.debug("We're auth status updated and is now: " + this.get('authenticated');
  }.observes('authenticated')
});

回调

function(authenticated) {
  if (!authenticated) {
    alert("Authentication failed")
  } else {
    App.__container__.lookup("controller:my").set('authenticated', true);
  }
}

更好的是,让您的 Passport 身份验证在 ember Controller 内运行,这样您就不必使用查找功能来查找 Controller (并且可能也是一个更简洁的设计)。

关于node.js - Ember.js 如何监听服务器发出的事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17066678/

相关文章:

ember.js - ember-data v1.0.0中的单表继承

node.js - 显示其他人的用户资料

javascript - 如何在node.js中导出http.request中的 block

node.js - Sequelize 。 GetOne 查询文本中具有 hasMany-association 的未知列

ember.js - 关于 Ember 中 Controller 的典型行为

linux - 错误 : EACCES when creating new Ember project

node.js - 登录一个 Express 应用程序会破坏其他应用程序(同一服务器)中的 session

javascript - FailureFlash 与 Passportjs 和 Express

node.js - 在 AWS 上运行的 Node.js 性能低下

node.js - Mongoose 鉴别器 : NodeJS/Express