Commit d2e30512 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Avoid creating excessive amounts of sessions.

Store the session cookie also when user is not logged in - just to keep
his session ID and not create a new session for each and every request.

Additionally use Ext.JSON instead of JSON.
parent 39f7a44f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -64,11 +64,12 @@ app.get('/auth/session', function(req, res) {
        if (user) {
            res.json({
                userName: user.username,
                mod: user.moderator
                mod: user.moderator,
                sessionID: req.sessionID
            });
        }
        else {
            res.json(false);
            res.json({sessionID: req.sessionID});
        }
    });
});
+13 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ Ext.define('Docs.controller.Auth', {

    init: function() {
        this.sid = Ext.util.Cookies.get('sid');
        this.currentUser = {};

        this.addEvents(
            /**
@@ -79,13 +80,20 @@ Ext.define('Docs.controller.Auth', {
            cors: true,
            callback: function(options, success, response) {
                if (response && response.responseText) {
                    this.currentUser = JSON.parse(response.responseText);
                    this.fireEvent('available');
                    if (this.currentUser) {
                    var data = Ext.JSON.decode(response.responseText);

                    if (data && data.sessionID) {
                        this.setSid(data.sessionID);
                    }

                    if (data && data.userName) {
                        this.currentUser = data;
                        this.setLoggedIn();
                    } else {
                        this.setLoggedOut();
                    }

                    this.fireEvent('available');
                }
            },
            scope: this
@@ -109,7 +117,7 @@ Ext.define('Docs.controller.Auth', {
                password: password
            },
            callback: function(options, success, response) {
                var data = JSON.parse(response.responseText);
                var data = Ext.JSON.decode(response.responseText);
                if (data.success) {
                    this.currentUser = data;
                    this.setSid(data.sessionID, { remember: remember });
@@ -155,7 +163,6 @@ Ext.define('Docs.controller.Auth', {
     */
    setLoggedOut: function(user) {
        this.currentUser = {};
        this.setSid(null);
        this.getAuth().showLoggedOut();
        this.fireEvent('loggedOut');
    },
@@ -165,7 +172,7 @@ Ext.define('Docs.controller.Auth', {
     * @return {Boolean} true if the user is logged in
     */
    isLoggedIn: function() {
        return Boolean(this.sid);
        return !!this.currentUser.userName;
    },

    /**