[IMP]Odoo Auth plugin : add init section to share odoo connection
This commit is contained in:
parent
b54d005919
commit
2fa9f8e577
@ -26,22 +26,25 @@ from radicale.auth import BaseAuth
|
|||||||
class Auth(BaseAuth):
|
class Auth(BaseAuth):
|
||||||
""" BaseAuth implementation for Odoo Radicale Authentication """
|
""" BaseAuth implementation for Odoo Radicale Authentication """
|
||||||
|
|
||||||
def is_authenticated(self, user, password):
|
def __init__(self, configuration, logger):
|
||||||
""" Is authenticated main function """
|
super(Auth, self).__init__(configuration, logger)
|
||||||
host = self.configuration.get('auth', 'host', fallback='127.0.0.1')
|
host = self.configuration.get('auth', 'host', fallback='127.0.0.1')
|
||||||
port = self.configuration.get('auth', 'port', fallback=8069)
|
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'):
|
if not self.configuration.has_option('auth', 'database'):
|
||||||
raise RuntimeError('Database is needed for Odoo Authentication')
|
raise RuntimeError('Database is needed for Odoo Authentication')
|
||||||
database = self.configuration.get('auth', 'database')
|
database = self.configuration.get('auth', 'database')
|
||||||
if not user or not password:
|
if not user or not password:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
odoo = ODOO(host, port=port)
|
self.odoo.login(database, user, password)
|
||||||
except RPCError as rpcerr:
|
|
||||||
self.logger.error(rpcerr)
|
|
||||||
raise RuntimeError(rpcerr)
|
|
||||||
try:
|
|
||||||
odoo.login(database, user, password)
|
|
||||||
self.logger.info('Login successfull for {} on database {}'.format(user, database))
|
self.logger.info('Login successfull for {} on database {}'.format(user, database))
|
||||||
return True
|
return True
|
||||||
except RPCError as rpcerr:
|
except RPCError as rpcerr:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user