我刚刚开始学习Ember,我正在尝试使用Ember Simple-auth和Laravel JWT软件包创建一个登录页面。问题是我的Ember提交动作发送了一个空的有效载荷。似乎getProperties函数没有获取输入值,为什么呢?我尝试过使用我找不到的每个Google示例都没有成功。
我的控制器:
// controllers/auth/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export default Ember.Controller.extend(LoginControllerMixin, {
actions: {
authenticate: function() {
var credentials = this.getProperties('username', 'password'),
authenticator = 'simple-auth-authenticator:token';
this.get('session').authenticate(authenticator, credentials);
}
}
});
我的登录模板:
// templates/auth/login.hbs
<form {{action "authenticate" on="submit"}}>
<div class="alerts"></div>
<div class="form-group">
<label>
<div class="title">Username</div>
{{input value=username type="text" class="form-control" placeholder="Username"}}
</label>
</div>
<div class="form-group">
<label>
<div class="title">Password</div>
{{input value=password type="password" class="form-control" placeholder="Password"}}
</label>
</div>
<button type="submit">Login</button>
</form>
环境
ENV['simple-auth'] = {
store: 'simple-auth-session-store:local-storage',
authorizer: 'simple-auth-authorizer:token'
};
ENV['simple-auth-token'] = {
refreshAccessTokens: true,
timeFactor: 1,
refreshLeeway: 300,
serverTokenEndpoint: '/api/authenticate/',
};
答案 0 :(得分:1)
最后解决了我必须更改表单模板。用户名输入值必须是识别符。