summaryrefslogtreecommitdiff
path: root/addons/google_account/controllers
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/google_account/controllers
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/google_account/controllers')
-rw-r--r--addons/google_account/controllers/__init__.py1
-rw-r--r--addons/google_account/controllers/main.py30
2 files changed, 31 insertions, 0 deletions
diff --git a/addons/google_account/controllers/__init__.py b/addons/google_account/controllers/__init__.py
new file mode 100644
index 00000000..12a7e529
--- /dev/null
+++ b/addons/google_account/controllers/__init__.py
@@ -0,0 +1 @@
+from . import main
diff --git a/addons/google_account/controllers/main.py b/addons/google_account/controllers/main.py
new file mode 100644
index 00000000..94aeacd2
--- /dev/null
+++ b/addons/google_account/controllers/main.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import json
+from werkzeug.utils import redirect
+
+from odoo import http, registry
+from odoo.http import request
+
+
+class GoogleAuth(http.Controller):
+
+ @http.route('/google_account/authentication', type='http', auth="public")
+ def oauth2callback(self, **kw):
+ """ This route/function is called by Google when user Accept/Refuse the consent of Google """
+ state = json.loads(kw['state'])
+ dbname = state.get('d')
+ service = state.get('s')
+ url_return = state.get('f')
+
+ with registry(dbname).cursor() as cr:
+ if kw.get('code'):
+ access_token, refresh_token, ttl = request.env['google.service']._get_google_tokens(kw['code'], service)
+ # LUL TODO only defined in google_calendar
+ request.env.user._set_auth_tokens(access_token, refresh_token, ttl)
+ return redirect(url_return)
+ elif kw.get('error'):
+ return redirect("%s%s%s" % (url_return, "?error=", kw['error']))
+ else:
+ return redirect("%s%s" % (url_return, "?error=Unknown_error"))