Commit 970871bd authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move the start of auth init into Appplication#launch.

The Docs.Auth is now observable and fires an "initialized" event
after it's been set up.
parent bfd8a21f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ Ext.define('Docs.Application', {

    requires: [
        'Docs.History',
        'Docs.Auth',
        'Docs.Settings'
    ],

@@ -40,6 +41,10 @@ Ext.define('Docs.Application', {

        Docs.History.init();

        if (Docs.enableComments) {
            Docs.Auth.init();
        }

        // When google analytics event tracking script present on page
        if (Docs.initEventTracking) {
            Docs.initEventTracking();
+16 −9
Original line number Diff line number Diff line
@@ -3,23 +3,30 @@
 */
Ext.define('Docs.Auth', {
    singleton: true,
    mixins: {
        observable: "Ext.util.Observable"
    },
    requires: [
        'Ext.Ajax',
        'Ext.JSON',
        'Ext.util.Cookies'
    ],

    /**
     * @event initialized
     * Fired after the connection to comments server is successfully
     * established.
     */

    constructor: function(config) {
        this.mixins.observable.constructor.call(this, config);
    },

    /**
     * Checks if a user is logged in server side and sets up a local
     * session if they are.
     * @param {Function} callback
     * @param {Object} scope
     */
    init: function(callback, scope) {
        if (!Docs.enableComments) {
            return;
        }

    init: function() {
        Ext.Ajax.request({
            url: Docs.baseUrl + '/session_new',
            params: { sid: this.getSid() },
@@ -37,11 +44,11 @@ Ext.define('Docs.Auth', {
                        this.currentUser = data;
                    }

                    callback && callback.call(scope);
                    this.fireEvent("initialized");
                }
                else {
                    // when comments server is down or something else
                    // is seriously wrong, don't fire the callback.
                    // is seriously wrong, don't fire the event.
                    // By this we stop the whole comments system.
                }
            },
+8 −11
Original line number Diff line number Diff line
@@ -18,17 +18,7 @@ Ext.define('Docs.controller.Auth', {
    ],

    init: function() {
        this.control({
            'authForm': {
                afterrender: this.initSession,
                login: this.login,
                logout: this.logout
            }
        });
    },

    initSession: function() {
        Docs.Auth.init(function() {
        Docs.Auth.on("initialized", function() {
            if (Docs.Auth.isLoggedIn()) {
                this.setLoggedIn();
            }
@@ -36,6 +26,13 @@ Ext.define('Docs.controller.Auth', {
                this.setLoggedOut();
            }
        }, this);

        this.control({
            'authForm': {
                login: this.login,
                logout: this.logout
            }
        });
    },

    login: function(username, password, remember) {