问题:我不知道如何在控制器中获取当前会话。
我有一个自定义身份验证器、自定义会话和初始化程序,定义如下:
../app/authenticators/custom.js 中的自定义身份验证器
var CustomAuthenticator = Base.extend({
authenticate: function(credentials) {
return new Ember.RSVP.Promise(function (resolve, reject){
var loginPromise = Ember.$.post('/api/login', {'email':credentials.identification, 'password':credentials.password} );
loginPromise.then(function (data){
resolve({
token: data.user.api_key,
userData: data.user
});
}, function(error){
reject(error);
});
});
}
});
../app/sessions/custom.js 中的自定义会话
import Ember from 'ember';
import Session from 'simple-auth/session';
var CustomSession = Session.extend({
after:'simple-auth',
currentUser: function(){
return this.container.lookup('ember_simple_auth:session');
}.property('currentUser')
});
export default CustomSession;
../app/initializers/authentication.js 中的初始化程序
import CustomAuthenticator from '../authenticators/custom';
import CustomSession from '../sessions/custom';
export default {
name: 'authentication',
before: 'simple-auth',
initialize: function(container) {
container.register('authenticator:custom', CustomAuthenticator);
container.register('session:custom', CustomSession);
}
};
我正在尝试通过使用在我的一个控制器中获取token
and ,但它给了我以下信息:userData
this.get('session')
Class {store: Class, __ember1420041799205: "ember297", __nextSuper: undefined, __ember_meta__: Object, constructor: function…}
ember_simple_auth:session
我在本地浏览器存储中看到了键和值{"authenticator":"authenticator:custom","token":"123456789","userData":{"id":"1","email":"something@email.com","api_key":"123456789","expiry_time":"2014-12-31 14:02:56"}}
我基本上需要获取本地存储中的内容。我该怎么做呢?