diff options
| author | Ajay Chauhan (OpenERP) <cha@tinyerp.com> | 2012-08-16 14:21:47 +0530 |
|---|---|---|
| committer | Ajay Chauhan (OpenERP) <cha@tinyerp.com> | 2012-08-16 14:21:47 +0530 |
| commit | e1e730ffbcaf58ffcc92b7bdf88b779bb3ec714c (patch) | |
| tree | 1349327760559ba5eec43934bd48d4f03b4fede6 /addons/auth_oauth/controllers | |
| parent | 463d06651ad84d62dcc9476d19962e18dec6ae92 (diff) | |
| parent | f4f7de136921528f4b465629ff756b367ee0bba7 (diff) | |
[Merge] Merge with main addons.
bzr revid: cha@tinyerp.com-20120816085147-o1wzevd3cj85vm2y
Diffstat (limited to 'addons/auth_oauth/controllers')
| -rw-r--r-- | addons/auth_oauth/controllers/__init__.py | 3 | ||||
| -rw-r--r-- | addons/auth_oauth/controllers/main.py | 47 |
2 files changed, 50 insertions, 0 deletions
diff --git a/addons/auth_oauth/controllers/__init__.py b/addons/auth_oauth/controllers/__init__.py new file mode 100644 index 00000000000..e11f9ba81bb --- /dev/null +++ b/addons/auth_oauth/controllers/__init__.py @@ -0,0 +1,3 @@ +import main + +# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/auth_oauth/controllers/main.py b/addons/auth_oauth/controllers/main.py new file mode 100644 index 00000000000..28f550b4bda --- /dev/null +++ b/addons/auth_oauth/controllers/main.py @@ -0,0 +1,47 @@ +import logging + +import simplejson +import werkzeug.urls +import werkzeug.utils + +import openerp.modules.registry +import openerp.addons.web.controllers.main +import openerp.addons.web.common.http as openerpweb + +_logger = logging.getLogger(__name__) + +class OAuthController(openerpweb.Controller): + _cp_path = '/auth_oauth' + + @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, 1, providers.search(cr, 1, [])) + return l + + @openerpweb.httprequest + def signin(self, req, **kw): + state = simplejson.loads(kw['state']) + dbname = state['d'] + provider = state['p'] + registry = openerp.modules.registry.RegistryManager.get(dbname) + with registry.cursor() as cr: + try: + u = registry.get('res.users') + credentials = u.auth_oauth(cr, 1, provider, kw) + cr.commit() + return openerp.addons.web.controllers.main.login_and_redirect(req, *credentials) + except AttributeError: + # auth_signup is not installed + _logger.error("auth_signup not installed on database %s: oauth sign up cancelled."%dbname) + url = "/#action=login&oauth_error=1" + except Exception,e: + # signup error + _logger.exception('oops') + url = "/#action=login&oauth_error=2" + return openerp.addons.web.controllers.main.set_cookie_and_redirect(req, url) + + +# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: |
