0

我正在尝试在 Simple Auth 的 login-controller-mixin 中调用 authenticate 方法。

这是我的控制器:

ApplicationController = Ember.Controller.extend(
  LoginControllerMixin,
  authenticator: 'simple-auth-authenticator:devise'
  actions:
    relayAuthentication: (id, password) ->
      @_actions.authenticate()
)

@_actions.authenticate()似乎确实有效,但我的上下文变得一团糟。

更一般地说,这是调用已混入 Ember 控制器的方法的正确方法吗?


这是我最终想要做的事情:

我有一个处理登录的组件。这是模板:

{{#if isFormOpen}}

  <div class="row">
    <form class="large-4 columns" {{action 'authenticate' on='submit'}}>
      <label for="identification">Login</label>
      {{input id='identification' placeholder='Enter Login' value=identification}}
      <label for="password">Password</label>
      {{input id='password' placeholder='Enter Password' type='password' value=password}}
      <button type="submit">Login</button>
      <button type="button" {{action 'toggleForm'}}>Cancel</button>
    </form>
  </div>

{{else}}

  {{#if session.isAuthenticated}}
    <a class="button tiny" {{action 'invalidateSession'}}>Logout</a>
  {{else}}
    <a class="button tiny" {{action 'toggleForm'}}>Login</a>
  {{/if}}

{{/if}}

这是组件本身:

`import Ember from 'ember'`

LoginComponent = Ember.Component.extend(
  actions:
    toggleForm: ->
      @toggleProperty('isFormOpen')
    authenticate: ->
      @sendAction('action', @identification, @password)
)

`export default LoginComponent`

使用身份验证操作时将其传递给组件 ( {{login-form action="authenticate"}})

该身份验证方法来自应用程序控制器上的Simple Auth mixin 。

我不确定如何为原始的身份验证方法(来自mixin)提供它想要的东西,即:上下文。

4

1 回答 1

1

不,这不对。如果它是一个方法,你只需以正常方式调用它。如果它是一个动作,你只需以正常方式发送它。

actions:
  relayAuthentication: (id, password) ->
    @send 'authenticate', id, password

但是在这种情况下,为什么不authenticate直接在模板中直接指定操作而不是通过relayAuthentication呢?

于 2014-08-08T03:57:41.630 回答