1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from sugarsoap_services import *
25 from sugarsoap_services_types import *
26 from osv import fields, osv
27 from tools.translate import _
30 class LoginError(Exception): pass
32 def login(username, password):
33 loc = sugarsoapLocator()
35 portType = loc.getsugarsoapPortType()
36 request = loginRequest()
37 uauth = ns0.user_auth_Def(request)
38 request._user_auth = uauth
40 uauth._user_name = username
41 uauth._password = hashlib.md5(password).hexdigest()
42 uauth._version = '1.1'
44 response = portType.login(request)
46 raise osv.except_osv(_('Error !'), _('Authentication error !\nBad Username or Password !'))
47 if -1 == response._return._id:
48 raise LoginError(response._return._error._description)
49 return (portType, response._return._id)
51 def search(portType, sessionid, module_name=None):
52 se_req = get_entry_listRequest()
53 se_req._session = sessionid
54 se_req._module_name = module_name
55 se_resp = portType.get_entry_list(se_req)
58 list = se_resp._return._entry_list
61 for j in i._name_value_list:
62 ans_dir[j._name.encode('utf-8')] = j._value.encode('utf-8')
64 ans_list.append(ans_dir)