main.py 1.26 KB
Newer Older
Arturo Jasso Origel committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

import json
import logging
import xmlrpc.client
import odoo
import odoo.modules.registry
from odoo import http
from odoo.exceptions import AccessError
from odoo.http import request
from odoo.addons.web.controllers.main import Home
_logger = logging.getLogger(__name__)



class HomeInherit(Home):
    @http.route('/web/login', type='http', auth="none")
    def web_login(self, redirect=None, **kw):
        if 'login' in kw and 'password' in kw:
            uid = self.auth_user_rpc(kw['login'],kw['password'])
            if uid != 0:
                return super(HomeInherit, self).web_login(redirect=redirect, **kw)
            else:
                return request.redirect('/web/login?error=access')
        else:
            return super(HomeInherit, self).web_login(redirect=redirect, **kw)
       
    def auth_user_rpc(self,username,password):
        uid = 0
        companies_url = request.env['res.company'].sudo().search([]).filtered(lambda c: c.login_url and c.login_db)
        if companies_url:
            for c in companies_url:
                common = xmlrpc.client.ServerProxy(c.login_url+"/xmlrpc/2/common")
                uid = common.authenticate(c.login_db,username,password,{})   
                if uid != 0:
                    break
        return uid