diff options
| author | Atul Patel (OpenERP) <atp@tinyerp.com> | 2011-03-03 16:28:21 +0530 |
|---|---|---|
| committer | Atul Patel (OpenERP) <atp@tinyerp.com> | 2011-03-03 16:28:21 +0530 |
| commit | 9442d4e9cd038b98e140bc2deddc907dfd89c067 (patch) | |
| tree | c25c07677c4e11b34addddd4b998d2d95ac17dab | |
| parent | bb00f787ee62dc55b955cbca344eaff557ada8d7 (diff) | |
[IMP]: Add exception when login failed.
bzr revid: atp@tinyerp.com-20110303105821-xuceqxbc9f5j2me8
| -rw-r--r-- | addons/sugarcrm_syncro/sugar.py | 64 | ||||
| -rw-r--r-- | addons/sugarcrm_syncro/wizard/sugarcrm_login.py | 2 | ||||
| -rw-r--r-- | addons/sugarcrm_syncro/wizard/sugarcrm_login_view.xml | 2 |
3 files changed, 46 insertions, 22 deletions
diff --git a/addons/sugarcrm_syncro/sugar.py b/addons/sugarcrm_syncro/sugar.py index 5a556f245fe..6e9835823ee 100644 --- a/addons/sugarcrm_syncro/sugar.py +++ b/addons/sugarcrm_syncro/sugar.py @@ -1,43 +1,67 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + import hashlib from sugarsoap_services import * -from sugarsoap_services_types import *; - +from sugarsoap_services_types import * +from osv import fields, osv +from tools.translate import _ import sys; class LoginError(Exception): pass def login(username, password): - loc = sugarsoapLocator(); - - portType = loc.getsugarsoapPortType(); - request = loginRequest(); - uauth = ns0.user_auth_Def(request); - request._user_auth = uauth; + loc = sugarsoapLocator() - uauth._user_name = username; - uauth._password = hashlib.md5(password).hexdigest(); - uauth._version = '1.1'; + portType = loc.getsugarsoapPortType() + request = loginRequest() + uauth = ns0.user_auth_Def(request) + request._user_auth = uauth - response = portType.login(request); + uauth._user_name = username + uauth._password = hashlib.md5(password).hexdigest() + uauth._version = '1.1' + try: + response = portType.login(request) + except: + raise osv.except_osv(_('Error !'), _('Authentication error !\nBad Username or Password !')) if -1 == response._return._id: - raise LoginError(response._return._error._description); - return (portType, response._return._id); + raise LoginError(response._return._error._description) + return (portType, response._return._id) def search(portType, sessionid, module_name=None): - se_req = get_entry_listRequest(); + se_req = get_entry_listRequest() se_req._session = sessionid se_req._module_name = module_name - se_resp = portType.get_entry_list(se_req); + se_resp = portType.get_entry_list(se_req) ans_list = [] if se_resp: - list = se_resp._return._entry_list; + list = se_resp._return._entry_list for i in list: - ans_dir = {}; + ans_dir = {} for j in i._name_value_list: ans_dir[j._name.encode('utf-8')] = j._value.encode('utf-8') #end for - ans_list.append(ans_dir); + ans_list.append(ans_dir) #end for - return ans_list; + return ans_list diff --git a/addons/sugarcrm_syncro/wizard/sugarcrm_login.py b/addons/sugarcrm_syncro/wizard/sugarcrm_login.py index 11473930976..b60f9db7f99 100644 --- a/addons/sugarcrm_syncro/wizard/sugarcrm_login.py +++ b/addons/sugarcrm_syncro/wizard/sugarcrm_login.py @@ -37,7 +37,7 @@ class sugarcrm_login(osv.osv): for current in self.browse(cr, uid, ids, context): PortType,sessionid = sugar.login(current.username, current.password) if sessionid == '-1': - raise osv.except_osv(_('Error !'), _('Wrong username and password')) + raise osv.except_osv(_('Error !'), _('Authentication error !\nBad Username or Password !')) obj_model = self.pool.get('ir.model.data') model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','import.sugarcrm.form')]) diff --git a/addons/sugarcrm_syncro/wizard/sugarcrm_login_view.xml b/addons/sugarcrm_syncro/wizard/sugarcrm_login_view.xml index 6aae5e249e2..1e0cc0306c9 100644 --- a/addons/sugarcrm_syncro/wizard/sugarcrm_login_view.xml +++ b/addons/sugarcrm_syncro/wizard/sugarcrm_login_view.xml @@ -19,7 +19,7 @@ <group colspan="4" > <label string="" colspan="2"/> <button icon="gtk-cancel" special="cancel" string="_Cancel"/> - <button name="open_import" string="Login" + <button name="open_import" string="_Login" type="object" icon="gtk-ok"/> </group> </form> |
