summaryrefslogtreecommitdiff
path: root/addons/auth_oauth/controllers/main.py
diff options
context:
space:
mode:
authorAtul Patel (OpenERP) <atp@tinyerp.com>2012-08-16 10:50:21 +0530
committerAtul Patel (OpenERP) <atp@tinyerp.com>2012-08-16 10:50:21 +0530
commit22a810507cc6b4e48a067b6baaf9869d72e5a38e (patch)
tree1808e0671b83dec971ae431b6ab1f09cfbfb44e8 /addons/auth_oauth/controllers/main.py
parent1d2168a02ebeeb7441c9171bd9dcda8226d29cdc (diff)
parentf4f7de136921528f4b465629ff756b367ee0bba7 (diff)
[MERGE]: Merged with lp:openobject-addons
bzr revid: atp@tinyerp.com-20120816052021-igdj7knaimwg9x7z
Diffstat (limited to 'addons/auth_oauth/controllers/main.py')
-rw-r--r--addons/auth_oauth/controllers/main.py47
1 files changed, 47 insertions, 0 deletions
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: