【发布时间】:2015-06-08 07:59:53
【问题描述】:
我正在使用 ember 简单身份验证来使用 ember 制作自定义身份验证系统,一切正常,除了一个问题,无法将数据从身份验证承诺回调传递到登录控制器。
代码如下:
//the login goes here
authenticate: function(options) {
return new Ember.RSVP.Promise(function(resolve, reject) {
Ember.$.ajax({
type: "POST",
url: apis.login,
data: JSON.stringify({
username: options.identification,
password: options.password
})
}).then(function(response) {
// check the login status to check the status
if (response.status === "success") {
//pass the response in resolve callback
Ember.run(function() {
resolve(response);
});
} else {
//login failed, pass the response in reject callback
Ember.run(function() {
reject(response);
});
}
}, function(xhr, status, error) {
Ember.run(function() {
reject(xhr.responseJSON || xhr.responseText);
});
});
});
},
这里是控制器代码
actions: {
// display an error when authentication fails
authenticate: function() {
var _this = this;
var credentials = this.getProperties('identification', 'password');
this.get('session').authenticate('authenticator:custom', credentials).then(
function(message) {
//the issus happens here, the message here is undefined
console.log(message);
_this.get('session').set('username', message.username);
}, function(message) {
// but the reject callback works fine, the message is the right one
console.log(message);
_this.set('errorMessage', message.msg);
_this.set('identification', '');
_this.set('password', '');
});
}
}
有人可以帮我吗?
【问题讨论】:
标签: javascript authentication ember.js ember-simple-auth