summaryrefslogtreecommitdiff
path: root/addons/auth_oauth
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2014-02-12 11:15:47 +0100
committerFabien Meghazi <fme@openerp.com>2014-02-12 11:15:47 +0100
commit33bfec21743c9200f491bd0ddcc6d368cd948f85 (patch)
treeec649b7f20a673774917df6be0a08a38307704bf /addons/auth_oauth
parent795c8fc0d9f2f592acbfca01a603fa1d3195562c (diff)
[IMP] Make auth_oauth depends of auth_signup, merge and remove auth_oauth_signup link module
bzr revid: fme@openerp.com-20140212101547-i4bcz9lcrut11kpu
Diffstat (limited to 'addons/auth_oauth')
-rw-r--r--addons/auth_oauth/__openerp__.py2
-rw-r--r--addons/auth_oauth/controllers/main.py26
-rw-r--r--addons/auth_oauth/res_users.py40
-rw-r--r--addons/auth_oauth/views/auth_oauth_login.xml32
4 files changed, 84 insertions, 16 deletions
diff --git a/addons/auth_oauth/__openerp__.py b/addons/auth_oauth/__openerp__.py
index 76f15687eb9..64068fa9b5e 100644
--- a/addons/auth_oauth/__openerp__.py
+++ b/addons/auth_oauth/__openerp__.py
@@ -31,7 +31,7 @@ Allow users to login through OAuth2 Provider.
'author': 'OpenERP s.a.',
'maintainer': 'OpenERP s.a.',
'website': 'http://www.openerp.com',
- 'depends': ['base', 'web', 'base_setup'],
+ 'depends': ['base', 'web', 'base_setup', 'auth_signup'],
'data': [
'res_users.xml',
'auth_oauth_data.xml',
diff --git a/addons/auth_oauth/controllers/main.py b/addons/auth_oauth/controllers/main.py
index e660fd8363b..2672d95ccde 100644
--- a/addons/auth_oauth/controllers/main.py
+++ b/addons/auth_oauth/controllers/main.py
@@ -61,10 +61,14 @@ class OAuthLogin(openerp.addons.web.controllers.main.Home):
return providers
def get_state(self, provider):
- return dict(
+ state = dict(
d=request.session.db,
p=provider['id']
)
+ token = request.params.get('token')
+ if token:
+ state['t'] = token
+ return state
@http.route()
def web_login(self, *args, **kw):
@@ -88,6 +92,26 @@ class OAuthLogin(openerp.addons.web.controllers.main.Home):
return response
+ @http.route()
+ def web_auth_signup(self, *args, **kw):
+ providers = self.list_providers()
+ if len(providers) == 1:
+ werkzeug.exceptions.abort(werkzeug.utils.redirect(providers[0]['auth_link'], 303))
+ response = super(OAuthLogin, self).web_auth_signup(*args, **kw)
+ if isinstance(response, LazyResponse):
+ response.params['values'].update(providers=providers)
+ return response
+
+ @http.route()
+ def web_auth_reset_password(self, *args, **kw):
+ providers = self.list_providers()
+ if len(providers) == 1:
+ werkzeug.exceptions.abort(werkzeug.utils.redirect(providers[0]['auth_link'], 303))
+ response = super(OAuthLogin, self).web_auth_reset_password(*args, **kw)
+ if isinstance(response, LazyResponse):
+ response.params['values'].update(providers=providers)
+ return response
+
class OAuthController(http.Controller):
@http.route('/auth_oauth/signin', type='http', auth='none')
diff --git a/addons/auth_oauth/res_users.py b/addons/auth_oauth/res_users.py
index f58473b24a4..8d57a23f702 100644
--- a/addons/auth_oauth/res_users.py
+++ b/addons/auth_oauth/res_users.py
@@ -6,6 +6,7 @@ import urllib2
import simplejson
import openerp
+from openerp.addons.auth_signup.res_users import SignupError
from openerp.osv import osv, fields
from openerp import SUPERUSER_ID
@@ -55,14 +56,37 @@ class res_users(osv.Model):
This method can be overridden to add alternative signin methods.
"""
- oauth_uid = validation['user_id']
- user_ids = self.search(cr, uid, [("oauth_uid", "=", oauth_uid), ('oauth_provider_id', '=', provider)])
- if not user_ids:
- raise openerp.exceptions.AccessDenied()
- assert len(user_ids) == 1
- user = self.browse(cr, uid, user_ids[0], context=context)
- user.write({'oauth_access_token': params['access_token']})
- return user.login
+ try:
+ oauth_uid = validation['user_id']
+ user_ids = self.search(cr, uid, [("oauth_uid", "=", oauth_uid), ('oauth_provider_id', '=', provider)])
+ if not user_ids:
+ raise openerp.exceptions.AccessDenied()
+ assert len(user_ids) == 1
+ user = self.browse(cr, uid, user_ids[0], context=context)
+ user.write({'oauth_access_token': params['access_token']})
+ return user.login
+ except openerp.exceptions.AccessDenied, access_denied_exception:
+ if context and context.get('no_user_creation'):
+ return None
+ state = simplejson.loads(params['state'])
+ token = state.get('t')
+ oauth_uid = validation['user_id']
+ email = validation.get('email', 'provider_%s_user_%s' % (provider, oauth_uid))
+ name = validation.get('name', email)
+ values = {
+ 'name': name,
+ 'login': email,
+ 'email': email,
+ 'oauth_provider_id': provider,
+ 'oauth_uid': oauth_uid,
+ 'oauth_access_token': params['access_token'],
+ 'active': True,
+ }
+ try:
+ _, login, _ = self.signup(cr, uid, values, token, context=context)
+ return login
+ except SignupError:
+ raise access_denied_exception
def auth_oauth(self, cr, uid, provider, params, context=None):
# Advice by Google (to avoid Confused Deputy Problem)
diff --git a/addons/auth_oauth/views/auth_oauth_login.xml b/addons/auth_oauth/views/auth_oauth_login.xml
index f969d2f5eed..6c5deca924c 100644
--- a/addons/auth_oauth/views/auth_oauth_login.xml
+++ b/addons/auth_oauth/views/auth_oauth_login.xml
@@ -3,15 +3,35 @@
-->
<openerp>
<data>
+ <template id="auth_oauth.providers" name="OAuth Providers">
+ <div t-foreach="providers" t-as="p">
+ <a t-att-href="p['auth_link']" class="btn btn-link">
+ <i t-att-class="p['css_class']"/>
+ <t t-esc="p['body']"/>
+ </a>
+ </div>
+ </template>
+
<template id="auth_oauth.login" inherit_id="web.login" name="OAuth Login buttons">
<xpath expr="//button[@type='submit']" position="before">
<div class="pull-right">
- <div t-foreach="providers" t-as="p">
- <a t-att-href="p['auth_link']" class="btn btn-link">
- <i t-att-class="p['css_class']"/>
- <t t-esc="p['body']"/>
- </a>
- </div>
+ <t t-call="auth_oauth.providers"/>
+ </div>
+ </xpath>
+ </template>
+
+ <template id="auth_oauth.signup" inherit_id="auth_signup.signup" name="OAuth Signup buttons">
+ <xpath expr="//button[@type='submit']" position="before">
+ <div class="pull-right">
+ <t t-call="auth_oauth.providers"/>
+ </div>
+ </xpath>
+ </template>
+
+ <template id="auth_oauth.reset_password" inherit_id="auth_signup.reset_password" name="OAuth Reset Password buttons">
+ <xpath expr="//button[@type='submit']" position="before">
+ <div class="pull-right">
+ <t t-call="auth_oauth.providers"/>
</div>
</xpath>
</template>