diff options
Diffstat (limited to 'addons/auth_oauth')
| -rw-r--r-- | addons/auth_oauth/controllers/main.py | 35 | ||||
| -rw-r--r-- | addons/auth_oauth/static/src/js/auth_oauth.js | 8 |
2 files changed, 25 insertions, 18 deletions
diff --git a/addons/auth_oauth/controllers/main.py b/addons/auth_oauth/controllers/main.py index 3f7ef2f3f0c..35a06871696 100644 --- a/addons/auth_oauth/controllers/main.py +++ b/addons/auth_oauth/controllers/main.py @@ -7,7 +7,8 @@ from werkzeug.exceptions import BadRequest import openerp from openerp import SUPERUSER_ID -import openerp.addons.web.http as oeweb +import openerp.addons.web.http as http +from openerp.addons.web.http import request from openerp.addons.web.controllers.main import db_monodb, set_cookie_and_redirect, login_and_redirect from openerp.modules.registry import RegistryManager @@ -18,7 +19,7 @@ _logger = logging.getLogger(__name__) #---------------------------------------------------------- def fragment_to_query_string(func): @functools.wraps(func) - def wrapper(self, req, **kw): + def wrapper(self, **kw): if not kw: return """<html><head><script> var l = window.location; @@ -30,18 +31,17 @@ def fragment_to_query_string(func): } window.location = r; </script></head><body></body></html>""" - return func(self, req, **kw) + return func(self, **kw) return wrapper #---------------------------------------------------------- # Controller #---------------------------------------------------------- -class OAuthController(oeweb.Controller): - _cp_path = '/auth_oauth' +class OAuthController(http.Controller): - @oeweb.jsonrequest - def list_providers(self, req, dbname): + @http.route('/auth_oauth/list_providers', type='json', auth='none') + def list_providers(self, dbname): try: registry = RegistryManager.get(dbname) with registry.cursor() as cr: @@ -51,9 +51,9 @@ class OAuthController(oeweb.Controller): l = [] return l - @oeweb.httprequest + @http.route('/auth_oauth/signin', type='http', auth='none') @fragment_to_query_string - def signin(self, req, **kw): + def signin(self, **kw): state = simplejson.loads(kw['state']) dbname = state['d'] provider = state['p'] @@ -71,7 +71,7 @@ class OAuthController(oeweb.Controller): url = '/#action=%s' % action elif menu: url = '/#menu_id=%s' % menu - return login_and_redirect(req, *credentials, redirect_url=url) + return login_and_redirect(*credentials, redirect_url=url) except AttributeError: # auth_signup is not installed _logger.error("auth_signup not installed on database %s: oauth sign up cancelled." % (dbname,)) @@ -88,21 +88,24 @@ class OAuthController(oeweb.Controller): _logger.exception("OAuth2: %s" % str(e)) url = "/#action=login&oauth_error=2" - return set_cookie_and_redirect(req, url) + return set_cookie_and_redirect(url) - @oeweb.httprequest - def oea(self, req, **kw): + @http.route('/auth_oauth/oea', type='http', auth='none') + def oea(self, **kw): """login user via OpenERP Account provider""" dbname = kw.pop('db', None) if not dbname: - dbname = db_monodb(req) + dbname = db_monodb() if not dbname: return BadRequest() registry = RegistryManager.get(dbname) with registry.cursor() as cr: IMD = registry['ir.model.data'] - model, provider_id = IMD.get_object_reference(cr, SUPERUSER_ID, 'auth_oauth', 'provider_openerp') + try: + model, provider_id = IMD.get_object_reference(cr, SUPERUSER_ID, 'auth_oauth', 'provider_openerp') + except ValueError: + return set_cookie_and_redirect('/?db=%s' % dbname) assert model == 'auth.oauth.provider' state = { @@ -112,6 +115,6 @@ class OAuthController(oeweb.Controller): } kw['state'] = simplejson.dumps(state) - return self.signin(req, **kw) + return self.signin(**kw) # vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/auth_oauth/static/src/js/auth_oauth.js b/addons/auth_oauth/static/src/js/auth_oauth.js index 131ae5c1c42..5046469a5dc 100644 --- a/addons/auth_oauth/static/src/js/auth_oauth.js +++ b/addons/auth_oauth/static/src/js/auth_oauth.js @@ -1,4 +1,6 @@ openerp.auth_oauth = function(instance) { + var _t = instance.web._t, + _lt = instance.web._lt; var QWeb = instance.web.qweb; instance.web.Login.include({ @@ -9,9 +11,11 @@ openerp.auth_oauth = function(instance) { 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."); + this.do_warn(_t("Sign up error"),_t("Sign up is not allowed on this database."), true); } else if(this.params.oauth_error === 2) { - this.do_warn("Authentication error",""); + this.do_warn(_t("Authentication error"),_t("Access Denied"), true); + } else if(this.params.oauth_error === 3) { + this.do_warn(_t("Authentication error"),_t("You do not have access to this database or your invitation has expired. Please ask for an invitation and be sure to follow the link in your invitation email."), true); } return d.done(this.do_oauth_load).fail(function() { self.do_oauth_load([]); |
