[IMP]Odoo Auth plugin : add init section to share odoo connection

This commit is contained in:
Fabien BOURGEOIS 2018-05-04 15:16:48 +02:00
parent b54d005919
commit 2fa9f8e577
1 changed files with 11 additions and 8 deletions

View File

@ -26,22 +26,25 @@ from radicale.auth import BaseAuth
class Auth(BaseAuth):
""" BaseAuth implementation for Odoo Radicale Authentication """
def is_authenticated(self, user, password):
""" Is authenticated main function """
def __init__(self, configuration, logger):
super(Auth, self).__init__(configuration, logger)
host = self.configuration.get('auth', 'host', fallback='127.0.0.1')
port = self.configuration.get('auth', 'port', fallback=8069)
try:
self.odoo = ODOO(host, port=port)
except RPCError as rpcerr:
self.logger.error(rpcerr)
raise RuntimeError(rpcerr)
def is_authenticated(self, user, password):
""" Is authenticated main function """
if not self.configuration.has_option('auth', 'database'):
raise RuntimeError('Database is needed for Odoo Authentication')
database = self.configuration.get('auth', 'database')
if not user or not password:
return False
try:
odoo = ODOO(host, port=port)
except RPCError as rpcerr:
self.logger.error(rpcerr)
raise RuntimeError(rpcerr)
try:
odoo.login(database, user, password)
self.odoo.login(database, user, password)
self.logger.info('Login successfull for {} on database {}'.format(user, database))
return True
except RPCError as rpcerr: