<commit_before>openerp.auth_oauth = function(instance) {
    var QWeb = instance.web.qweb;

    instance.web.Login.include({
        start: function(parent, params) {
            var self = this;
            var d = this._super.apply(this, arguments);
            this.$el.on('click', 'a.zocial', this.on_oauth_sign_in);
            this.oauth_providers = [];
            if(this.params.oauth_error === 1) {
                this.do_warn("Sign up error.","Sign up is not allowed on this database.");
            } else if(this.params.oauth_error === 2) {
                this.do_warn("Authentication error","");
            }
            return d.done(this.do_oauth_load).fail(function() {
                self.do_oauth_load([]);
            });
        },
        on_db_loaded: function(result) {
            this._super.apply(this, arguments);
            this.$("form [name=db]").change(this.do_oauth_load);
        },
        do_oauth_load: function() {
            var db = this.$("form [name=db]").val();
            if (db) {
                this.rpc("/auth_oauth/list_providers", { dbname: db }).done(this.on_oauth_loaded);
            }
        },
        on_oauth_loaded: function(result) {
            this.oauth_providers = result;
            this.$('.oe_oauth_provider_login_button').remove();
            var buttons = QWeb.render("auth_oauth.Login.button",{"widget":this});
            this.$(".oe_login_pane form ul").after(buttons);
        },
        on_oauth_sign_in: function(ev) {
            ev.preventDefault();
            var index = $(ev.target).data('index');
            var p = this.oauth_providers[index];
            var ret = _.str.sprintf('%s//%s/auth_oauth/signin', location.protocol, location.host);
            if (instance.session.debug) {
                ret += '?debug';
            }
            var dbname = self.$("form [name=db]").val();
            var state_object = {
                d: dbname,
                p: p.id
            };
            var state = JSON.stringify(state_object);
            var params = {
                response_type: 'token',
                client_id: p.client_id,
                redirect_uri: ret,
                scope: p.scope,
                state: state,
            };
            var url = p.auth_endpoint + '?' + $.param(params);
            window.location = url;
        },
    });

};<commit_msg>[IMP] auth_oauth: refactor js method on_oauth_sign_in() to enable overriding of the oauth state definition<commit_after>openerp.auth_oauth = function(instance) {
    var QWeb = instance.web.qweb;

    instance.web.Login.include({
        start: function(parent, params) {
            var self = this;
            var d = this._super.apply(this, arguments);
            this.$el.on('click', 'a.zocial', this.on_oauth_sign_in);
            this.oauth_providers = [];
            if(this.params.oauth_error === 1) {
                this.do_warn("Sign up error.","Sign up is not allowed on this database.");
            } else if(this.params.oauth_error === 2) {
                this.do_warn("Authentication error","");
            }
            return d.done(this.do_oauth_load).fail(function() {
                self.do_oauth_load([]);
            });
        },
        on_db_loaded: function(result) {
            this._super.apply(this, arguments);
            this.$("form [name=db]").change(this.do_oauth_load);
        },
        do_oauth_load: function() {
            var db = this.$("form [name=db]").val();
            if (db) {
                this.rpc("/auth_oauth/list_providers", { dbname: db }).done(this.on_oauth_loaded);
            }
        },
        on_oauth_loaded: function(result) {
            this.oauth_providers = result;
            this.$('.oe_oauth_provider_login_button').remove();
            var buttons = QWeb.render("auth_oauth.Login.button",{"widget":this});
            this.$(".oe_login_pane form ul").after(buttons);
        },
        on_oauth_sign_in: function(ev) {
            ev.preventDefault();
            var index = $(ev.target).data('index');
            var provider = this.oauth_providers[index];
            var return_url = _.str.sprintf('%s//%s/auth_oauth/signin', location.protocol, location.host);
            if (instance.session.debug) {
                return_url += '?debug';
            }
            var state = self._oauth_state();
            var params = {
                response_type: 'token',
                client_id: provider.client_id,
                redirect_uri: return_url,
                scope: provider.scope,
                state: JSON.stringify(state),
            };
            var url = provider.auth_endpoint + '?' + $.param(params);
            window.location = url;
        },
        _oauth_state: function(provider) {
            // return the state object sent back with the redirected uri
            var dbname = self.$("form [name=db]").val();
            return {
                d: dbname,
                p: provider.id,
            };
        },
    });

};
{'fraction_non_alphanumeric': 0.1384371281237604, 'fraction_numerical': 0.0007933359777865926, 'mean_word_length': 1.6881663113006398, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6977577', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1446, 'n_words': 260}