【问题标题】:Ember-cli - Simple-Auth :: Location for factory authenticator:customEmber-cli - Simple-Auth :: 工厂验证器的位置:自定义
【发布时间】:2014-07-31 17:55:36
【问题描述】:

ember-cli 中工厂的正确位置在哪里。一旦我有了工厂的正确位置,我是否会在我的初始化程序中注册

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();
            });
        });
    },
});

谢谢!

【问题讨论】:

    标签: ember.js ember-simple-auth


    【解决方案1】:

    是的,你就是这样做的。确保在您跌倒 Ember.SimpleAuth.setup 之前调用 container.register。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 2018-03-30
      相关资源
      最近更新 更多