comparison easyhg.py @ 470:0714a86b8077

Check for repeated request (thus failed login) before looking up cached data, so we can cache in confidence without resending invalid login details (fixing #205)
author Chris Cannam
date Mon, 11 Jul 2011 15:15:31 +0100
parents 33a1c7c9d9d9
children 1e735168df81
comparison
equal deleted inserted replaced
469:d63711ff6740 470:0714a86b8077
228 auth_store = None 228 auth_store = None
229 229
230 def __init__(self, ui, url, user, passwd): 230 def __init__(self, ui, url, user, passwd):
231 self.auth_store = EasyHgAuthStore(ui, url, user, passwd) 231 self.auth_store = EasyHgAuthStore(ui, url, user, passwd)
232 232
233 def ask(self, force_dialog): 233 def ask(self, repeat):
234 234
235 if self.auth_store.user and self.auth_store.passwd and self.auth_store.remember: 235 if self.auth_store.user and self.auth_store.passwd and self.auth_store.remember:
236 if not force_dialog: 236 if not repeat:
237 return (self.auth_store.user, self.auth_store.passwd) 237 return (self.auth_store.user, self.auth_store.passwd)
238 238
239 dialog = QtGui.QDialog() 239 dialog = QtGui.QDialog()
240 layout = QtGui.QGridLayout() 240 layout = QtGui.QGridLayout()
241 dialog.setLayout(layout) 241 dialog.setLayout(layout)
242 242
243 layout.addWidget(QtGui.QLabel(_('<h3>Login required</h3><p>Please provide your login details for the repository at<br><code>%s</code>:') % self.auth_store.argless_url()), 0, 0, 1, 2) 243 heading = _('Login required')
244 if repeat:
245 heading = _('Login failed: please try again')
246 label_text = _(('<h3>%s</h3><p>Please provide your login details for the repository at<br><code>%s</code>:') % (heading, self.auth_store.argless_url()))
247 layout.addWidget(QtGui.QLabel(label_text), 0, 0, 1, 2)
244 248
245 user_field = QtGui.QLineEdit() 249 user_field = QtGui.QLineEdit()
246 if self.auth_store.user: user_field.setText(self.auth_store.user) 250 if self.auth_store.user: user_field.setText(self.auth_store.user)
247 layout.addWidget(QtGui.QLabel(_('User:')), 1, 0) 251 layout.addWidget(QtGui.QLabel(_('User:')), 1, 0)
248 layout.addWidget(user_field, 1, 1) 252 layout.addWidget(user_field, 1, 1)
332 336
333 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( 337 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
334 self, realm, authuri) 338 self, realm, authuri)
335 user, passwd = authinfo 339 user, passwd = authinfo
336 340
337 if user and passwd: 341 repeat = False
338 # self.ui.write("note: user and passwd both provided\n")
339 return orig_find(self, realm, authuri)
340
341 # self.ui.write("want username and/or password for %s\n" % authuri)
342
343 force_dialog = False
344
345 # if self.__easyhg_last:
346 # self.ui.write("last = realm '%s' authuri '%s'\n" % self.__easyhg_last)
347 # self.ui.write("me = realm '%s' authuri '%s'\n" % (realm, authuri))
348 342
349 if (realm, authuri) == self.__easyhg_last: 343 if (realm, authuri) == self.__easyhg_last:
350 # If we are called again just after identical previous 344 # If we are called again just after identical previous
351 # request, then the previously returned auth must have been 345 # request, then the previously returned auth must have been
352 # wrong. So we note this to force password prompt (and avoid 346 # wrong. So we note this to force password prompt (and avoid
353 # reusing bad password indefinitely). Thanks to 347 # reusing bad password indefinitely). Thanks to
354 # mercurial_keyring (Marcin Kasperski) for this logic 348 # mercurial_keyring (Marcin Kasperski) for this logic
355 # self.ui.write("same again!\n") 349 repeat = True
356 force_dialog = True 350
351 if user and passwd and not repeat:
352 return orig_find(self, realm, authuri)
357 353
358 dialog = EasyHgAuthDialog(self.ui, authuri, user, passwd) 354 dialog = EasyHgAuthDialog(self.ui, authuri, user, passwd)
359 355
360 (user, passwd) = dialog.ask(force_dialog) 356 (user, passwd) = dialog.ask(repeat)
361 357
362 # self.add_password(realm, authuri, user, passwd) 358 self.add_password(realm, authuri, user, passwd)
363 self.__easyhg_last = (realm, authuri) 359 self.__easyhg_last = (realm, authuri)
364 # self.ui.write("done = realm '%s' authuri '%s'\n" % self.__easyhg_last)
365 return (user, passwd) 360 return (user, passwd)
366 361
367 362