2014-06-10 2 views
1

ember-cli의 공장 위치는 어디입니까? 공장 위치가 정해지면 이니셜 라이저에 등록해야합니까?Ember-cli - Simple-Auth :: 공장 인증 자용 위치 : 사용자 정의

container.register ('authenticator : custom', application.CustomAuthenticator);

// the custom authenticator that authenticates the session against the custom server 
App.CustomAuthenticator = Ember.SimpleAuth.Authenticators.Base.extend({ 
    tokenEndpoint: '/v4/session', 

    restore: function(data) { 
     return new Ember.RSVP.Promise(function(resolve, reject) { 
      if (!Ember.isEmpty(data.token)) { 
       resolve(data); 
      } else { 
       reject(); 
      } 
     }); 
    }, 

    authenticate: function(credentials) { 
     var _this = this; 
     return new Ember.RSVP.Promise(function(resolve, reject) { 
      Ember.$.ajax({ 
       url:   _this.tokenEndpoint, 
       type:  'POST', 
       data:  JSON.stringify({ session: { identification: credentials.identification, password: credentials.password } }), 
       contentType: 'application/json' 
      }).then(function(response) { 
       Ember.run(function() { 
       resolve({ token: response.session.token }); 
      }); 
     }, 
      function(xhr, status, error) { 
       var response = JSON.parse(xhr.responseText); 
       Ember.run(function() { 
        reject(response.error); 
       }); 
      }); 
     }); 
    }, 

    invalidate: function() { 
     var _this = this; 
     return new Ember.RSVP.Promise(function(resolve) { 
      Ember.$.ajax({ url: _this.tokenEndpoint, type: 'DELETE' }).always(function() { 
       resolve(); 
      }); 
     }); 
    }, 
}); 

감사!

답변

0

예, 그렇습니다. Ember.SimpleAuth.setup을 삭제하기 전에 container.register를 호출해야합니다.