From 9442d4e9cd038b98e140bc2deddc907dfd89c067 Mon Sep 17 00:00:00 2001 From: "Atul Patel (OpenERP)" Date: Thu, 3 Mar 2011 16:28:21 +0530 Subject: [PATCH] [IMP]: Add exception when login failed. bzr revid: atp@tinyerp.com-20110303105821-xuceqxbc9f5j2me8 --- addons/sugarcrm_syncro/sugar.py | 64 +++++++++++++------ .../sugarcrm_syncro/wizard/sugarcrm_login.py | 2 +- .../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 (). +# +# 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 . +# +############################################################################## + 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(); + loc = sugarsoapLocator() - portType = loc.getsugarsoapPortType(); - request = loginRequest(); - uauth = ns0.user_auth_Def(request); - request._user_auth = uauth; + portType = loc.getsugarsoapPortType() + request = loginRequest() + uauth = ns0.user_auth_Def(request) + request._user_auth = uauth - uauth._user_name = username; - uauth._password = hashlib.md5(password).hexdigest(); - uauth._version = '1.1'; - - 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 @@