[FIX] Fixed oauth in order to reload provider on database selection. Also avoid to crash on database not having oauth installed or not even openerp database.

bzr revid: fme@openerp.com-20120927123429-nzau63yeo2zyn7ck
This commit is contained in:
Fabien Meghazi 2012-09-27 14:34:29 +02:00
parent f8c80b9af6
commit 1319a9423a
4 changed files with 25 additions and 11 deletions

View File

@ -16,10 +16,13 @@ class OAuthController(openerpweb.Controller):
@openerpweb.jsonrequest
def list_providers(self, req, dbname):
registry = openerp.modules.registry.RegistryManager.get(dbname)
with registry.cursor() as cr:
providers = registry.get('auth.oauth.provider')
l = providers.read(cr, SUPERUSER_ID, providers.search(cr, SUPERUSER_ID, [('enabled','=',True)]))
try:
registry = openerp.modules.registry.RegistryManager.get(dbname)
with registry.cursor() as cr:
providers = registry.get('auth.oauth.provider')
l = providers.read(cr, SUPERUSER_ID, providers.search(cr, SUPERUSER_ID, [('enabled','=',True)]))
except Exception:
l = []
return l
@openerpweb.httprequest

View File

@ -2,13 +2,13 @@
font: white;
}
.zocial.openerp:before {
.openerp .zocial.openerp:before {
content: "\E02E";
font-style: italic;
text-shadow: 0 1px 1px black;
}
a.zocial.openerp {
.openerp a.zocial.openerp {
float: right;
border: 1px solid #222222;
color: white;
@ -29,3 +29,7 @@ a.zocial.openerp {
text-shadow: none;
font-weight: normal;
}
.openerp .oe_login .oe_oauth_provider_login_button {
margin-top: 4px;
}

View File

@ -1,8 +1,9 @@
openerp.auth_oauth = function(instance) {
var QWeb = instance.web.qweb;
instance.web.Login = instance.web.Login.extend({
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 = [];
@ -11,7 +12,13 @@ openerp.auth_oauth = function(instance) {
} else if(this.params.oauth_error === 2) {
this.do_warn("Authentication error","");
}
return d.then(this.do_oauth_load);
return d.then(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();
@ -21,6 +28,7 @@ openerp.auth_oauth = function(instance) {
},
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);
},
@ -33,7 +41,7 @@ openerp.auth_oauth = function(instance) {
var state_object = {
d: dbname,
p: p.id
}
};
var state = JSON.stringify(state_object);
var params = {
response_type: 'token',

View File

@ -2,8 +2,7 @@
<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/>
<a href="#" t-attf-class="oe_oauth_provider_login_button #{p.css_class}" t-att-data-index="p_index"><t t-esc="p.body"/></a>
</t>
</t>
</templates>