src/eric7/WebBrowser/Passwords/PasswordManager.py

branch
eric7
changeset 10436
f6881d10e995
parent 10373
093dcebe5ecb
child 10439
21c28b0f9e41
equal deleted inserted replaced
10435:c712d09cc839 10436:f6881d10e995
43 43
44 def __init__(self, parent=None): 44 def __init__(self, parent=None):
45 """ 45 """
46 Constructor 46 Constructor
47 47
48 @param parent reference to the parent object (QObject) 48 @param parent reference to the parent object
49 @type QObject
49 """ 50 """
50 super().__init__(parent) 51 super().__init__(parent)
51 52
52 # setup userscript to monitor forms 53 # setup userscript to monitor forms
53 script = QWebEngineScript() 54 script = QWebEngineScript()
84 85
85 def getLogin(self, url, realm): 86 def getLogin(self, url, realm):
86 """ 87 """
87 Public method to get the login credentials. 88 Public method to get the login credentials.
88 89
89 @param url URL to get the credentials for (QUrl) 90 @param url URL to get the credentials for
90 @param realm realm to get the credentials for (string) 91 @type QUrl
91 @return tuple containing the user name (string) and password (string) 92 @param realm realm to get the credentials for
93 @type str
94 @return tuple containing the user name (string) and password
95 @rtype str
92 """ 96 """
93 if not self.__loaded: 97 if not self.__loaded:
94 self.__load() 98 self.__load()
95 99
96 key = self.__createKey(url, realm) 100 key = self.__createKey(url, realm)
103 107
104 def setLogin(self, url, realm, username, password): 108 def setLogin(self, url, realm, username, password):
105 """ 109 """
106 Public method to set the login credentials. 110 Public method to set the login credentials.
107 111
108 @param url URL to set the credentials for (QUrl) 112 @param url URL to set the credentials for
109 @param realm realm to set the credentials for (string) 113 @type QUrl
110 @param username username for the login (string) 114 @param realm realm to set the credentials for
111 @param password password for the login (string) 115 @type str
116 @param username username for the login
117 @type str
118 @param password password for the login
119 @type str
112 """ 120 """
113 if not self.__loaded: 121 if not self.__loaded:
114 self.__load() 122 self.__load()
115 123
116 key = self.__createKey(url, realm) 124 key = self.__createKey(url, realm)
122 130
123 def __createKey(self, url, realm): 131 def __createKey(self, url, realm):
124 """ 132 """
125 Private method to create the key string for the login credentials. 133 Private method to create the key string for the login credentials.
126 134
127 @param url URL to get the credentials for (QUrl) 135 @param url URL to get the credentials for
128 @param realm realm to get the credentials for (string) 136 @type QUrl
129 @return key string (string) 137 @param realm realm to get the credentials for
138 @type str
139 @return key string
140 @rtype str
130 """ 141 """
131 authority = url.authority() 142 authority = url.authority()
132 if authority.startswith("@"): 143 if authority.startswith("@"):
133 authority = authority[1:] 144 authority = authority[1:]
134 key = ( 145 key = (
140 151
141 def getFileName(self): 152 def getFileName(self):
142 """ 153 """
143 Public method to get the file name of the passwords file. 154 Public method to get the file name of the passwords file.
144 155
145 @return name of the passwords file (string) 156 @return name of the passwords file
157 @rtype str
146 """ 158 """
147 return os.path.join(Globals.getConfigDir(), "web_browser", "logins.xml") 159 return os.path.join(Globals.getConfigDir(), "web_browser", "logins.xml")
148 160
149 def save(self): 161 def save(self):
150 """ 162 """
216 228
217 def removePassword(self, site): 229 def removePassword(self, site):
218 """ 230 """
219 Public method to remove a password entry. 231 Public method to remove a password entry.
220 232
221 @param site web site name (string) 233 @param site web site name
234 @type str
222 """ 235 """
223 if site in self.__logins: 236 if site in self.__logins:
224 del self.__logins[site] 237 del self.__logins[site]
225 if site in self.__loginForms: 238 if site in self.__loginForms:
226 del self.__loginForms[site] 239 del self.__loginForms[site]
228 241
229 def allSiteNames(self): 242 def allSiteNames(self):
230 """ 243 """
231 Public method to get a list of all site names. 244 Public method to get a list of all site names.
232 245
233 @return sorted list of all site names (list of strings) 246 @return sorted list of all site names
247 @rtype list of str
234 """ 248 """
235 if not self.__loaded: 249 if not self.__loaded:
236 self.__load() 250 self.__load()
237 251
238 return sorted(self.__logins) 252 return sorted(self.__logins)
239 253
240 def sitesCount(self): 254 def sitesCount(self):
241 """ 255 """
242 Public method to get the number of available sites. 256 Public method to get the number of available sites.
243 257
244 @return number of sites (integer) 258 @return number of sites
259 @rtype int
245 """ 260 """
246 if not self.__loaded: 261 if not self.__loaded:
247 self.__load() 262 self.__load()
248 263
249 return len(self.__logins) 264 return len(self.__logins)
250 265
251 def siteInfo(self, site): 266 def siteInfo(self, site):
252 """ 267 """
253 Public method to get a reference to the named site. 268 Public method to get a reference to the named site.
254 269
255 @param site web site name (string) 270 @param site web site name
256 @return tuple containing the user name (string) and password (string) 271 @type str
272 @return tuple containing the user name (string) and password
273 @rtype str
257 """ 274 """
258 if not self.__loaded: 275 if not self.__loaded:
259 self.__load() 276 self.__load()
260 277
261 if site not in self.__logins: 278 if site not in self.__logins:
337 354
338 def __stripUrl(self, url): 355 def __stripUrl(self, url):
339 """ 356 """
340 Private method to strip off all unneeded parts of a URL. 357 Private method to strip off all unneeded parts of a URL.
341 358
342 @param url URL to be stripped (QUrl) 359 @param url URL to be stripped
343 @return stripped URL (QUrl) 360 @type QUrl
361 @return stripped URL
362 @rtype QUrl
344 """ 363 """
345 cleanUrl = QUrl(url) 364 cleanUrl = QUrl(url)
346 cleanUrl.setQuery("") 365 cleanUrl.setQuery("")
347 cleanUrl.setUserInfo("") 366 cleanUrl.setUserInfo("")
348 367
357 376
358 def completePage(self, page): 377 def completePage(self, page):
359 """ 378 """
360 Public slot to complete login forms with saved data. 379 Public slot to complete login forms with saved data.
361 380
362 @param page reference to the web page (WebBrowserPage) 381 @param page reference to the web page
382 @type WebBrowserPage
363 """ 383 """
364 if page is None: 384 if page is None:
365 return 385 return
366 386
367 if not self.__loaded: 387 if not self.__loaded:
385 405
386 def mainPasswordChanged(self, oldPassword, newPassword): 406 def mainPasswordChanged(self, oldPassword, newPassword):
387 """ 407 """
388 Public slot to handle the change of the main password. 408 Public slot to handle the change of the main password.
389 409
390 @param oldPassword current main password (string) 410 @param oldPassword current main password
391 @param newPassword new main password (string) 411 @type str
412 @param newPassword new main password
413 @type str
392 """ 414 """
393 if not self.__loaded: 415 if not self.__loaded:
394 self.__load() 416 self.__load()
395 417
396 progress = EricProgressDialog( 418 progress = EricProgressDialog(

eric ide

mercurial