diff options
| author | Tejas Tank <tta@openerp.com> | 2012-08-17 16:16:10 +0530 |
|---|---|---|
| committer | Tejas Tank <tta@openerp.com> | 2012-08-17 16:16:10 +0530 |
| commit | f4f0d42a70d62320b0d0b0d3aab16336b696a485 (patch) | |
| tree | ac01c07c02a5284eb67d044e92e3255506e70a08 /addons/auth_oauth/static/src | |
| parent | ae1ed5900caf1d0429ef731343af4ae364d989ae (diff) | |
| parent | 6666d5993f9753c6ec3aec721b41ebd3fbc6c18c (diff) | |
Merged with latest.
bzr revid: tta@openerp.com-20120817104610-h7pova57capzm1by
Diffstat (limited to 'addons/auth_oauth/static/src')
| -rw-r--r-- | addons/auth_oauth/static/src/js/auth_oauth.js | 64 | ||||
| -rw-r--r-- | addons/auth_oauth/static/src/xml/auth_oauth.xml | 9 |
2 files changed, 73 insertions, 0 deletions
diff --git a/addons/auth_oauth/static/src/js/auth_oauth.js b/addons/auth_oauth/static/src/js/auth_oauth.js new file mode 100644 index 00000000000..eae423fae1f --- /dev/null +++ b/addons/auth_oauth/static/src/js/auth_oauth.js @@ -0,0 +1,64 @@ +openerp.auth_oauth = function(instance) { + var QWeb = instance.web.qweb; + + instance.web.Login = instance.web.Login.extend({ + start: function(parent, params) { + var d = this._super.apply(this, arguments); + this.$element.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.then(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 }).then(this.on_oauth_loaded); + } + }, + on_oauth_loaded: function(result) { + this.oauth_providers = result; + console.log(result); + var buttons = QWeb.render("auth_oauth.Login.button",{"widget":this}); + console.log(buttons); + 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 = location.protocol+"//"+location.host+"/"; + 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; + }, + }); + + instance.web.WebClient = instance.web.WebClient.extend({ + start: function() { + this._super.apply(this, arguments); + var params = $.deparam(window.location.hash.substring(1)); + // alert(JSON.stringify(params)); + if (params.hasOwnProperty('access_token')) { + var url = "/auth_oauth/signin" + '?' + $.param(params); + window.location = url; + } + }, + }); + +}; diff --git a/addons/auth_oauth/static/src/xml/auth_oauth.xml b/addons/auth_oauth/static/src/xml/auth_oauth.xml new file mode 100644 index 00000000000..c2693804e59 --- /dev/null +++ b/addons/auth_oauth/static/src/xml/auth_oauth.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<templates id="template" xml:space="preserve"> +<t t-name="auth_oauth.Login.button"> + <t t-foreach="widget.oauth_providers" t-as="p"> + <a href="#" t-att-class="p.css_class" t-att-data-index="p_index"><t t-esc="p.body"/></a> + <br/> + </t> +</t> +</templates> |
