flectra/addons/google_account/controllers/main.py

29 lines
1.0 KiB
Python
Raw Permalink Normal View History

# -*- coding: utf-8 -*-
2018-01-16 11:34:37 +01:00
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
import json
from werkzeug.utils import redirect
2018-01-16 11:34:37 +01:00
from flectra import http, registry
from flectra.http import request
class GoogleAuth(http.Controller):
@http.route('/google_account/authentication', type='http', auth="none")
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'):
request.env(cr, request.session.uid)['google.%s' % service].set_all_tokens(kw['code'])
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"))