我正在尝试在 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)提供它想要的东西,即:上下文。