[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):
|
||||
""" 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:
|
||||
|
Loading…
Reference in New Issue
Block a user