comparison easyhg.py @ 450:568abb678073

Remember username as well as password
author Chris Cannam
date Wed, 29 Jun 2011 13:36:07 +0100
parents f778dfb6a42f
children 8156537329ff
comparison
equal deleted inserted replaced
449:f778dfb6a42f 450:568abb678073
172 short_uri = canonical_url(authuri) 172 short_uri = canonical_url(authuri)
173 173
174 authkey = self.ui.config('easyhg', 'authkey') 174 authkey = self.ui.config('easyhg', 'authkey')
175 authfile = self.ui.config('easyhg', 'authfile') 175 authfile = self.ui.config('easyhg', 'authfile')
176 use_authfile = (easyhg_authfile_imports_ok and authkey and authfile) 176 use_authfile = (easyhg_authfile_imports_ok and authkey and authfile)
177 if authfile: 177 if authfile: authfile = os.path.expanduser(authfile)
178 authfile = os.path.expanduser(authfile)
179 authdata = None
180 178
181 dialog = QtGui.QDialog() 179 dialog = QtGui.QDialog()
182 layout = QtGui.QGridLayout() 180 layout = QtGui.QGridLayout()
183 dialog.setLayout(layout) 181 dialog.setLayout(layout)
184 182
200 user_field.connect(user_field, Qt.SIGNAL("textChanged(QString)"), 198 user_field.connect(user_field, Qt.SIGNAL("textChanged(QString)"),
201 passwd_field, Qt.SLOT("clear()")) 199 passwd_field, Qt.SLOT("clear()"))
202 200
203 remember_field = None 201 remember_field = None
204 remember = False 202 remember = False
203
205 authconfig = None 204 authconfig = None
205 authdata = None
206 206
207 if use_authfile: 207 if use_authfile:
208
208 authconfig = ConfigParser.RawConfigParser() 209 authconfig = ConfigParser.RawConfigParser()
209 load_config(authconfig, authfile) 210 load_config(authconfig, authfile)
210 remember = get_boolean_from_config(authconfig, 'preferences', 211 remember = get_boolean_from_config(authconfig, 'preferences',
211 'remember', False) 212 'remember', False)
212 authdata = get_from_config(authconfig, 'auth', 213
213 remote_key(short_uri, user, authkey)) 214 if not user:
214 if authdata: 215 authdata = get_from_config(authconfig, 'user',
215 cachedpwd = decrypt_salted(authdata, authkey) 216 remote_key(short_uri, '', authkey))
216 passwd_field.setText(cachedpwd) 217 if authdata:
218 user = decrypt_salted(authdata, authkey)
219 user_field.setText(user)
220
221 if not passwd:
222 authdata = get_from_config(authconfig, 'auth',
223 remote_key(short_uri, user, authkey))
224 if authdata:
225 passwd = decrypt_salted(authdata, authkey)
226 passwd_field.setText(passwd)
227
217 remember_field = QtGui.QCheckBox() 228 remember_field = QtGui.QCheckBox()
218 remember_field.setChecked(remember) 229 remember_field.setChecked(remember)
219 remember_field.setText(_('Remember passwords while EasyMercurial is running')) 230 remember_field.setText(_('Remember these details while EasyMercurial is running'))
220 layout.addWidget(remember_field, 3, 1) 231 layout.addWidget(remember_field, 3, 1)
221 232
222 bb = QtGui.QDialogButtonBox() 233 bb = QtGui.QDialogButtonBox()
223 ok = bb.addButton(bb.Ok) 234 ok = bb.addButton(bb.Ok)
224 cancel = bb.addButton(bb.Cancel) 235 cancel = bb.addButton(bb.Cancel)
234 245
235 if not user: 246 if not user:
236 user_field.setFocus(True) 247 user_field.setFocus(True)
237 elif not passwd: 248 elif not passwd:
238 passwd_field.setFocus(True) 249 passwd_field.setFocus(True)
250 else:
251 ok.setFocus(True)
239 252
240 dialog.raise_() 253 dialog.raise_()
241 ok = dialog.exec_() 254 ok = dialog.exec_()
242 if not ok: 255 if not ok:
243 raise util.Abort(_('password entry cancelled')) 256 raise util.Abort(_('password entry cancelled'))
247 260
248 if use_authfile: 261 if use_authfile:
249 remember = remember_field.isChecked() 262 remember = remember_field.isChecked()
250 set_to_config(authconfig, 'preferences', 'remember', remember) 263 set_to_config(authconfig, 'preferences', 'remember', remember)
251 if user: 264 if user:
252 if passwd and remember: 265 if remember:
266 authdata = encrypt_salted(user, authkey)
267 set_to_config(authconfig, 'user', remote_key(short_uri, '', authkey), authdata)
268 else:
269 set_to_config(authconfig, 'user', remote_key(short_uri, '', authkey), '')
270 if passwd:
271 if remember:
253 authdata = encrypt_salted(passwd, authkey) 272 authdata = encrypt_salted(passwd, authkey)
254 set_to_config(authconfig, 'auth', remote_key(short_uri, user, authkey), authdata) 273 set_to_config(authconfig, 'auth', remote_key(short_uri, user, authkey), authdata)
255 else: 274 else:
256 set_to_config(authconfig, 'auth', remote_key(short_uri, user, authkey), '') 275 set_to_config(authconfig, 'auth', remote_key(short_uri, user, authkey), '')
257 save_config(self.ui, authconfig, authfile) 276 save_config(self.ui, authconfig, authfile)