Mercurial > hg > easyhg
comparison easyhg.py @ 459:ee06f9275c99
Use cached password directly, without asking the user, if it's available and the requested realm/uri are not the same as an immediately preceding one
author | Chris Cannam |
---|---|
date | Thu, 30 Jun 2011 00:04:33 +0100 |
parents | c22cef015d73 |
children | 9f738c3ae9ba |
comparison
equal
deleted
inserted
replaced
458:c22cef015d73 | 459:ee06f9275c99 |
---|---|
166 self.auth_config.add_section(sect) | 166 self.auth_config.add_section(sect) |
167 self.auth_config.set(sect, key, data) | 167 self.auth_config.set(sect, key, data) |
168 | 168 |
169 def remote_key(self, url, user): | 169 def remote_key(self, url, user): |
170 # generate a "safe-for-config-file" key representing uri+user | 170 # generate a "safe-for-config-file" key representing uri+user |
171 self.ui.write('generating remote_key for url %s and user %s\n' % (url, user)) | 171 # self.ui.write('generating remote_key for url %s and user %s\n' % (url, user)) |
172 s = '%s@@%s' % (url, user) | 172 s = '%s@@%s' % (url, user) |
173 h = hashlib.sha1() | 173 h = hashlib.sha1() |
174 h.update(self.auth_key) | 174 h.update(self.auth_key) |
175 h.update(s) | 175 h.update(s) |
176 hx = h.hexdigest() | 176 hx = h.hexdigest() |
205 self.load_config() | 205 self.load_config() |
206 if not self.auth_config: return | 206 if not self.auth_config: return |
207 | 207 |
208 self.set_to_config('preferences', 'remember', self.remember) | 208 self.set_to_config('preferences', 'remember', self.remember) |
209 | 209 |
210 self.ui.write('aiming to store details for user %s\n' % self.user) | 210 # self.ui.write('aiming to store details for user %s\n' % self.user) |
211 | 211 |
212 if self.remember and self.user: | 212 if self.remember and self.user: |
213 d = self.encrypt(self.user) | 213 d = self.encrypt(self.user) |
214 self.set_to_config('user', self.remote_user_key(), d) | 214 self.set_to_config('user', self.remote_user_key(), d) |
215 else: | 215 else: |
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): | 233 def ask(self, force_dialog): |
234 | |
235 if self.auth_store.user and self.auth_store.passwd: | |
236 if not force_dialog: | |
237 return (self.auth_store.user, self.auth_store.passwd) | |
238 | |
234 dialog = QtGui.QDialog() | 239 dialog = QtGui.QDialog() |
235 layout = QtGui.QGridLayout() | 240 layout = QtGui.QGridLayout() |
236 dialog.setLayout(layout) | 241 dialog.setLayout(layout) |
237 | 242 |
238 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 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) |
315 orig_find = passwordmgr.find_user_password | 320 orig_find = passwordmgr.find_user_password |
316 | 321 |
317 @monkeypatch_method(passwordmgr) | 322 @monkeypatch_method(passwordmgr) |
318 def find_user_password(self, realm, authuri): | 323 def find_user_password(self, realm, authuri): |
319 | 324 |
325 if not hasattr(self, '__easyhg_last'): | |
326 self.__easyhg_last = None | |
327 | |
320 if not self.ui.interactive(): | 328 if not self.ui.interactive(): |
321 return orig_find(self, realm, authuri) | 329 return orig_find(self, realm, authuri) |
322 if not easyhg_pyqt_ok: | 330 if not easyhg_pyqt_ok: |
323 return orig_find(self, realm, authuri) | 331 return orig_find(self, realm, authuri) |
324 | 332 |
325 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( | 333 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password( |
326 self, realm, authuri) | 334 self, realm, authuri) |
327 user, passwd = authinfo | 335 user, passwd = authinfo |
328 | 336 |
329 if user and passwd: | 337 if user and passwd: |
330 self.ui.write("note: user and passwd both provided\n") | 338 # self.ui.write("note: user and passwd both provided\n") |
331 return orig_find(self, realm, authuri) | 339 return orig_find(self, realm, authuri) |
332 | 340 |
333 self.ui.write("want username and/or password for %s\n" % authuri) | 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 | |
349 if (realm, authuri) == self.__easyhg_last: | |
350 # If we are called again just after identical previous | |
351 # request, then the previously returned auth must have been | |
352 # wrong. So we note this to force password prompt (and avoid | |
353 # reusing bad password indefinitely). Thanks to | |
354 # mercurial_keyring (Marcin Kasperski) for this logic | |
355 # self.ui.write("same again!\n") | |
356 force_dialog = True | |
334 | 357 |
335 dialog = EasyHgAuthDialog(self.ui, authuri, user, passwd) | 358 dialog = EasyHgAuthDialog(self.ui, authuri, user, passwd) |
336 | 359 |
337 (user, passwd) = dialog.ask() | 360 (user, passwd) = dialog.ask(force_dialog) |
338 | 361 |
339 self.add_password(realm, authuri, user, passwd) | 362 # self.add_password(realm, authuri, user, passwd) |
363 self.__easyhg_last = (realm, authuri) | |
364 # self.ui.write("done = realm '%s' authuri '%s'\n" % self.__easyhg_last) | |
340 return (user, passwd) | 365 return (user, passwd) |
341 | 366 |
342 | 367 |