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

Update e-mail address when user logs in.

We could simply query the forum database every time we need the e-mail
address, but I think it's better to keep interaction with forum database
to a minimum.  Besides, changing the e-mail address happens very rarely
and at least we now have this case covered.
parent b92d27f5
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -51,10 +51,20 @@ Users.prototype = {
        // great also.
        this.add(user, function(err, user_id) {
            if (err) {
                this.get(user, function(err, u) {
                    callback(err, u.id);
                this.get(user, function(err, localUser) {
                    // It might be that user has changed his e-mail
                    // address in the forum database. In such case
                    // update the local e-mail address accordingly.
                    if (user.email === localUser.email) {
                        callback(err, localUser.id);
                    }
                    else {
                        this.updateEmail(localUser.id, user.email, function(err) {
                            callback(err, localUser.id);
                        });
                    }
                }.bind(this));
            }
            else {
                callback(err, user_id);
            }
@@ -67,6 +77,10 @@ Users.prototype = {

    get: function(user, callback) {
        this.db.queryOne('SELECT * FROM users WHERE external_id = ?', [user.external_id], callback);
    },

    updateEmail: function(user_id, email, callback) {
        this.db.update("users", {id: user_id, email: email}, callback);
    }

};