comparison src/stdui/ui_profile_manager.py @ 1263:cfd636203e8f frontends_multi_profiles

core: misc improvments: - added some constants for message types and presence - removed profile authentification specific methods in favor of a more generic "validated" key
author Goffi <goffi@goffi.org>
date Wed, 10 Dec 2014 18:36:11 +0100
parents 628e320eab1f
children a8d7500090f6
comparison
equal deleted inserted replaced
1262:f8a8434dbac7 1263:cfd636203e8f
46 @return: deferred dict 46 @return: deferred dict
47 """ 47 """
48 def gotProfileCipher(profile_cipher): 48 def gotProfileCipher(profile_cipher):
49 if self.host.memory.auth_sessions.profileGetUnique(profile): 49 if self.host.memory.auth_sessions.profileGetUnique(profile):
50 # case 1: profile already authenticated 50 # case 1: profile already authenticated
51 return {'authenticated_profile': profile, 'caller': data['caller']} 51 return {'validated': C.str(True)}
52 self.profile_ciphers[profile] = profile_cipher 52 self.profile_ciphers[profile] = profile_cipher
53 if 'profile_password' in data: 53 if 'profile_password' in data:
54 # case 2: password is provided by the caller 54 # case 2: password is provided by the caller
55 return self._verifyPassword(data, profile) 55 return self._verifyPassword(data, profile)
56 56
57 def check_empty_password(empty_password_result): 57 def check_empty_password(verify_password_result):
58 if 'authenticated_profile' in empty_password_result: 58 validated = C.bool(verify_password_result['validated'])
59 if validated:
59 # case 3: there's no password for this profile 60 # case 3: there's no password for this profile
60 return empty_password_result 61 return verify_password_result
61 62
62 # case 4: prompt the user for a password 63 # case 4: prompt the user for a password
63 def xmlui_cb(data_, profile): 64 def xmlui_cb(data_, profile):
64 data_['caller'] = data['caller']
65 return self._verifyPassword(data_, profile) 65 return self._verifyPassword(data_, profile)
66 66
67 callback_id = self.host.registerCallback(xmlui_cb, with_data=True, one_shot=True) 67 callback_id = self.host.registerCallback(xmlui_cb, with_data=True, one_shot=True)
68 form_ui = xml_tools.XMLUI("form", title=D_('Profile password for %s') % profile, submit_id=callback_id) 68 form_ui = xml_tools.XMLUI("form", title=D_('Profile password for %s') % profile, submit_id=callback_id)
69 form_ui.addPassword('profile_password', value='') 69 form_ui.addPassword('profile_password', value='')
70 return {'xmlui': form_ui.toXml()} 70 return {'xmlui': form_ui.toXml()}
71 71
72 check_empty_data = {'profile_password': '', 'caller': data['caller']} 72 check_empty_data = {'profile_password': ''}
73 d = self._verifyPassword(check_empty_data, profile) 73 d = self._verifyPassword(check_empty_data, profile)
74 return d.addCallback(check_empty_password) 74 return d.addCallback(check_empty_password)
75 75
76 assert(data['caller'])
77 d = self.host.memory.asyncGetStringParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile) 76 d = self.host.memory.asyncGetStringParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile)
78 d.addCallback(gotProfileCipher) 77 d.addCallback(gotProfileCipher)
79 d.addErrback(self.getParamError) 78 d.addErrback(self.getParamError)
80 return d 79 return d
81 80
82 def getParamError(self, failure): 81 def getParamError(self, failure):
83 _dialog = xml_tools.XMLUI('popup', title=D_('Error')) 82 _dialog = xml_tools.XMLUI('popup', title=D_('Error'))
84 _dialog.addText(D_("Can't get profile parameter.")) 83 _dialog.addText(D_("Can't get profile parameter."))
85 return {'xmlui': _dialog.toXml()} 84 return {'xmlui': _dialog.toXml(), 'validated': C.str(False)}
86 85
87 @defer.inlineCallbacks 86 @defer.inlineCallbacks
88 def _verifyPassword(self, data, profile): 87 def _verifyPassword(self, data, profile):
89 """Verify the given password 88 """Verify the given password
90 89
91 @param data (dict) 90 @param data (dict)
92 @param profile: %(doc_profile)s 91 @param profile: %(doc_profile)s
93 @return: deferred dict 92 @return: deferred dict
94 """ 93 """
95 assert(profile in self.profile_ciphers) 94 assert(profile in self.profile_ciphers)
96 assert(data['caller'])
97 95
98 try: 96 try:
99 profile_password = data[xml_tools.formEscape('profile_password')] 97 profile_password = data[xml_tools.formEscape('profile_password')]
100 except KeyError: 98 except KeyError:
101 profile_password = data['profile_password'] # not received from a user input 99 profile_password = data['profile_password'] # not received from a user input
102 verified = yield PasswordHasher.verify(profile_password, self.profile_ciphers[profile]) 100 verified = yield PasswordHasher.verify(profile_password, self.profile_ciphers[profile])
103 if not verified: 101 if not verified:
104 _dialog = xml_tools.XMLUI('popup', title=D_('Connection error')) 102 _dialog = xml_tools.XMLUI('popup', title=D_('Connection error'))
105 _dialog.addText(D_("The provided profile password doesn't match.")) 103 _dialog.addText(D_("The provided profile password doesn't match."))
106 defer.returnValue({'xmlui': _dialog.toXml()}) 104 defer.returnValue({'xmlui': _dialog.toXml(), 'validated': C.str(False)})
107 105
108 yield self.host.memory.newAuthSession(profile_password, profile) 106 yield self.host.memory.newAuthSession(profile_password, profile)
109 defer.returnValue({'authenticated_profile': profile, 'caller': data['caller']}) 107 defer.returnValue({'validated': C.str(True)})
110 108
111 def _changeXMPPPassword(self, data, profile): 109 def _changeXMPPPassword(self, data, profile):
112 session_data = self._sessions.profileGetUnique(profile) 110 session_data = self._sessions.profileGetUnique(profile)
113 if not session_data: 111 if not session_data:
114 server = self.host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile) 112 server = self.host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile)