Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_account.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 943de4f9ce50 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
106 # TODO: cleaning, separate email handling, more configuration/tests, fixes | 106 # TODO: cleaning, separate email handling, more configuration/tests, fixes |
107 | 107 |
108 def __init__(self, host): | 108 def __init__(self, host): |
109 log.info(_("Plugin Account initialization")) | 109 log.info(_("Plugin Account initialization")) |
110 self.host = host | 110 self.host = host |
111 host.bridge.addMethod( | 111 host.bridge.add_method( |
112 "registerSatAccount", | 112 "libervia_account_register", |
113 ".plugin", | 113 ".plugin", |
114 in_sign="sss", | 114 in_sign="sss", |
115 out_sign="", | 115 out_sign="", |
116 method=self._registerAccount, | 116 method=self._register_account, |
117 async_=True, | 117 async_=True, |
118 ) | 118 ) |
119 host.bridge.addMethod( | 119 host.bridge.add_method( |
120 "getNewAccountDomain", | 120 "account_domain_new_get", |
121 ".plugin", | 121 ".plugin", |
122 in_sign="", | 122 in_sign="", |
123 out_sign="s", | 123 out_sign="s", |
124 method=self.getNewAccountDomain, | 124 method=self.account_domain_new_get, |
125 async_=False, | 125 async_=False, |
126 ) | 126 ) |
127 host.bridge.addMethod( | 127 host.bridge.add_method( |
128 "getAccountDialogUI", | 128 "account_dialog_ui_get", |
129 ".plugin", | 129 ".plugin", |
130 in_sign="s", | 130 in_sign="s", |
131 out_sign="s", | 131 out_sign="s", |
132 method=self._getAccountDialogUI, | 132 method=self._get_account_dialog_ui, |
133 async_=False, | 133 async_=False, |
134 ) | 134 ) |
135 host.bridge.addMethod( | 135 host.bridge.add_method( |
136 "asyncConnectWithXMPPCredentials", | 136 "credentials_xmpp_connect", |
137 ".plugin", | 137 ".plugin", |
138 in_sign="ss", | 138 in_sign="ss", |
139 out_sign="b", | 139 out_sign="b", |
140 method=self.asyncConnectWithXMPPCredentials, | 140 method=self.credentials_xmpp_connect, |
141 async_=True, | 141 async_=True, |
142 ) | 142 ) |
143 | 143 |
144 self.fixEmailAdmins() | 144 self.fix_email_admins() |
145 self._sessions = Sessions() | 145 self._sessions = Sessions() |
146 | 146 |
147 self.__account_cb_id = host.registerCallback( | 147 self.__account_cb_id = host.register_callback( |
148 self._accountDialogCb, with_data=True | 148 self._account_dialog_cb, with_data=True |
149 ) | 149 ) |
150 self.__change_password_id = host.registerCallback( | 150 self.__change_password_id = host.register_callback( |
151 self.__changePasswordCb, with_data=True | 151 self.__change_password_cb, with_data=True |
152 ) | 152 ) |
153 | 153 |
154 def deleteBlogCallback(posts, comments): | 154 def delete_blog_callback(posts, comments): |
155 return lambda data, profile: self.__deleteBlogPostsCb( | 155 return lambda data, profile: self.__delete_blog_posts_cb( |
156 posts, comments, data, profile | 156 posts, comments, data, profile |
157 ) | 157 ) |
158 | 158 |
159 self.__delete_posts_id = host.registerCallback( | 159 self.__delete_posts_id = host.register_callback( |
160 deleteBlogCallback(True, False), with_data=True | 160 delete_blog_callback(True, False), with_data=True |
161 ) | 161 ) |
162 self.__delete_comments_id = host.registerCallback( | 162 self.__delete_comments_id = host.register_callback( |
163 deleteBlogCallback(False, True), with_data=True | 163 delete_blog_callback(False, True), with_data=True |
164 ) | 164 ) |
165 self.__delete_posts_comments_id = host.registerCallback( | 165 self.__delete_posts_comments_id = host.register_callback( |
166 deleteBlogCallback(True, True), with_data=True | 166 delete_blog_callback(True, True), with_data=True |
167 ) | 167 ) |
168 | 168 |
169 self.__delete_account_id = host.registerCallback( | 169 self.__delete_account_id = host.register_callback( |
170 self.__deleteAccountCb, with_data=True | 170 self.__delete_account_cb, with_data=True |
171 ) | 171 ) |
172 | 172 |
173 # FIXME: remove this after some time, when the deprecated parameter is really abandoned | 173 # FIXME: remove this after some time, when the deprecated parameter is really abandoned |
174 def fixEmailAdmins(self): | 174 def fix_email_admins(self): |
175 """Handle deprecated config option "admin_email" to fix the admin emails list""" | 175 """Handle deprecated config option "admin_email" to fix the admin emails list""" |
176 admin_email = self.getConfig("admin_email") | 176 admin_email = self.config_get("admin_email") |
177 if not admin_email: | 177 if not admin_email: |
178 return | 178 return |
179 log.warning( | 179 log.warning( |
180 "admin_email parameter is deprecated, please use email_admins_list instead" | 180 "admin_email parameter is deprecated, please use email_admins_list instead" |
181 ) | 181 ) |
182 param_name = "email_admins_list" | 182 param_name = "email_admins_list" |
183 try: | 183 try: |
184 section = "" | 184 section = "" |
185 value = self.host.memory.getConfig(section, param_name, Exception) | 185 value = self.host.memory.config_get(section, param_name, Exception) |
186 except (configparser.NoOptionError, configparser.NoSectionError): | 186 except (configparser.NoOptionError, configparser.NoSectionError): |
187 section = CONFIG_SECTION | 187 section = CONFIG_SECTION |
188 value = self.host.memory.getConfig( | 188 value = self.host.memory.config_get( |
189 section, param_name, default_conf[param_name] | 189 section, param_name, default_conf[param_name] |
190 ) | 190 ) |
191 | 191 |
192 value = set(value) | 192 value = set(value) |
193 value.add(admin_email) | 193 value.add(admin_email) |
194 self.host.memory.config.set(section, param_name, ",".join(value)) | 194 self.host.memory.config.set(section, param_name, ",".join(value)) |
195 | 195 |
196 def getConfig(self, name, section=CONFIG_SECTION): | 196 def config_get(self, name, section=CONFIG_SECTION): |
197 if name.startswith("email_"): | 197 if name.startswith("email_"): |
198 # XXX: email_ parameters were first in [plugin account] section | 198 # XXX: email_ parameters were first in [plugin account] section |
199 # but as it make more sense to have them in common with other plugins, | 199 # but as it make more sense to have them in common with other plugins, |
200 # they can now be in [DEFAULT] section | 200 # they can now be in [DEFAULT] section |
201 try: | 201 try: |
202 value = self.host.memory.getConfig(None, name, Exception) | 202 value = self.host.memory.config_get(None, name, Exception) |
203 except (configparser.NoOptionError, configparser.NoSectionError): | 203 except (configparser.NoOptionError, configparser.NoSectionError): |
204 pass | 204 pass |
205 else: | 205 else: |
206 return value | 206 return value |
207 | 207 |
208 if section == CONFIG_SECTION: | 208 if section == CONFIG_SECTION: |
209 default = default_conf[name] | 209 default = default_conf[name] |
210 else: | 210 else: |
211 default = None | 211 default = None |
212 return self.host.memory.getConfig(section, name, default) | 212 return self.host.memory.config_get(section, name, default) |
213 | 213 |
214 def _registerAccount(self, email, password, profile): | 214 def _register_account(self, email, password, profile): |
215 return self.registerAccount(email, password, None, profile) | 215 return self.registerAccount(email, password, None, profile) |
216 | 216 |
217 def registerAccount(self, email, password, jid_s, profile): | 217 def registerAccount(self, email, password, jid_s, profile): |
218 """Register a new profile, its associated XMPP account, send the confirmation emails. | 218 """Register a new profile, its associated XMPP account, send the confirmation emails. |
219 | 219 |
224 - non empty value: bind this JID to the new sat profile | 224 - non empty value: bind this JID to the new sat profile |
225 - None or "": register a new JID on the local XMPP server | 225 - None or "": register a new JID on the local XMPP server |
226 @param profile | 226 @param profile |
227 @return Deferred | 227 @return Deferred |
228 """ | 228 """ |
229 d = self.createProfile(password, jid_s, profile) | 229 d = self.create_profile(password, jid_s, profile) |
230 d.addCallback(lambda __: self.sendEmails(email, profile)) | 230 d.addCallback(lambda __: self.send_emails(email, profile)) |
231 return d | 231 return d |
232 | 232 |
233 def createProfile(self, password, jid_s, profile): | 233 def create_profile(self, password, jid_s, profile): |
234 """Register a new profile and its associated XMPP account. | 234 """Register a new profile and its associated XMPP account. |
235 | 235 |
236 @param password (unicode): password chosen by the user | 236 @param password (unicode): password chosen by the user |
237 while be used for profile *and* XMPP account | 237 while be used for profile *and* XMPP account |
238 @param jid_s (unicode): JID to re-use or to register: | 238 @param jid_s (unicode): JID to re-use or to register: |
242 @return Deferred | 242 @return Deferred |
243 """ | 243 """ |
244 if not password or not profile: | 244 if not password or not profile: |
245 raise exceptions.DataError | 245 raise exceptions.DataError |
246 | 246 |
247 if profile.lower() in self.getConfig("reserved_list"): | 247 if profile.lower() in self.config_get("reserved_list"): |
248 return defer.fail(Failure(exceptions.ConflictError)) | 248 return defer.fail(Failure(exceptions.ConflictError)) |
249 | 249 |
250 d = self.host.memory.createProfile(profile, password) | 250 d = self.host.memory.create_profile(profile, password) |
251 d.addCallback(lambda __: self.profileCreated(password, jid_s, profile)) | 251 d.addCallback(lambda __: self.profile_created(password, jid_s, profile)) |
252 return d | 252 return d |
253 | 253 |
254 def profileCreated(self, password, jid_s, profile): | 254 def profile_created(self, password, jid_s, profile): |
255 """Create the XMPP account and set the profile connection parameters. | 255 """Create the XMPP account and set the profile connection parameters. |
256 | 256 |
257 @param password (unicode): password chosen by the user | 257 @param password (unicode): password chosen by the user |
258 @param jid_s (unicode): JID to re-use or to register: | 258 @param jid_s (unicode): JID to re-use or to register: |
259 - non empty value: bind this JID to the new sat profile | 259 - non empty value: bind this JID to the new sat profile |
263 """ | 263 """ |
264 if jid_s: | 264 if jid_s: |
265 d = defer.succeed(None) | 265 d = defer.succeed(None) |
266 jid_ = jid.JID(jid_s) | 266 jid_ = jid.JID(jid_s) |
267 else: | 267 else: |
268 jid_s = profile + "@" + self.getNewAccountDomain() | 268 jid_s = profile + "@" + self.account_domain_new_get() |
269 jid_ = jid.JID(jid_s) | 269 jid_ = jid.JID(jid_s) |
270 d = self.host.plugins["XEP-0077"].registerNewAccount(jid_, password) | 270 d = self.host.plugins["XEP-0077"].register_new_account(jid_, password) |
271 | 271 |
272 def setParams(__): | 272 def setParams(__): |
273 self.host.memory.setParam( | 273 self.host.memory.param_set( |
274 "JabberID", jid_s, "Connection", profile_key=profile | 274 "JabberID", jid_s, "Connection", profile_key=profile |
275 ) | 275 ) |
276 d = self.host.memory.setParam( | 276 d = self.host.memory.param_set( |
277 "Password", password, "Connection", profile_key=profile | 277 "Password", password, "Connection", profile_key=profile |
278 ) | 278 ) |
279 return d | 279 return d |
280 | 280 |
281 def removeProfile(failure): | 281 def remove_profile(failure): |
282 self.host.memory.asyncDeleteProfile(profile) | 282 self.host.memory.profile_delete_async(profile) |
283 return failure | 283 return failure |
284 | 284 |
285 d.addCallback(lambda __: self.host.memory.startSession(password, profile)) | 285 d.addCallback(lambda __: self.host.memory.start_session(password, profile)) |
286 d.addCallback(setParams) | 286 d.addCallback(setParams) |
287 d.addCallback(lambda __: self.host.memory.stopSession(profile)) | 287 d.addCallback(lambda __: self.host.memory.stop_session(profile)) |
288 d.addErrback(removeProfile) | 288 d.addErrback(remove_profile) |
289 return d | 289 return d |
290 | 290 |
291 def _sendEmailEb(self, failure_, email): | 291 def _send_email_eb(self, failure_, email): |
292 # TODO: return error code to user | 292 # TODO: return error code to user |
293 log.error( | 293 log.error( |
294 _("Failed to send account creation confirmation to {email}: {msg}").format( | 294 _("Failed to send account creation confirmation to {email}: {msg}").format( |
295 email=email, msg=failure_ | 295 email=email, msg=failure_ |
296 ) | 296 ) |
297 ) | 297 ) |
298 | 298 |
299 def sendEmails(self, email, profile): | 299 def send_emails(self, email, profile): |
300 # time to send the email | 300 # time to send the email |
301 | 301 |
302 domain = self.getNewAccountDomain() | 302 domain = self.account_domain_new_get() |
303 | 303 |
304 # email to the administrators | 304 # email to the administrators |
305 admins_emails = self.getConfig("email_admins_list") | 305 admins_emails = self.config_get("email_admins_list") |
306 if not admins_emails: | 306 if not admins_emails: |
307 log.warning( | 307 log.warning( |
308 "No known admin email, we can't send email to administrator(s).\n" | 308 "No known admin email, we can't send email to administrator(s).\n" |
309 "Please fill email_admins_list parameter" | 309 "Please fill email_admins_list parameter" |
310 ) | 310 ) |
311 d_admin = defer.fail(exceptions.DataError("no admin email")) | 311 d_admin = defer.fail(exceptions.DataError("no admin email")) |
312 else: | 312 else: |
313 subject = _("New Libervia account created") | 313 subject = _("New Libervia account created") |
314 # there is no email when an existing XMPP account is used | 314 # there is no email when an existing XMPP account is used |
315 body = f"New account created on {domain}: {profile} [{email or '<no email>'}]" | 315 body = f"New account created on {domain}: {profile} [{email or '<no email>'}]" |
316 d_admin = sat_email.sendEmail( | 316 d_admin = sat_email.send_email( |
317 self.host.memory.config, admins_emails, subject, body) | 317 self.host.memory.config, admins_emails, subject, body) |
318 | 318 |
319 admins_emails_txt = ", ".join(["<" + addr + ">" for addr in admins_emails]) | 319 admins_emails_txt = ", ".join(["<" + addr + ">" for addr in admins_emails]) |
320 d_admin.addCallbacks( | 320 d_admin.addCallbacks( |
321 lambda __: log.debug( | 321 lambda __: log.debug( |
331 ) | 331 ) |
332 if not email: | 332 if not email: |
333 # TODO: if use register with an existing account, an XMPP message should be sent | 333 # TODO: if use register with an existing account, an XMPP message should be sent |
334 return d_admin | 334 return d_admin |
335 | 335 |
336 jid_s = self.host.memory.getParamA( | 336 jid_s = self.host.memory.param_get_a( |
337 "JabberID", "Connection", profile_key=profile | 337 "JabberID", "Connection", profile_key=profile |
338 ) | 338 ) |
339 subject = _("Your Libervia account has been created") | 339 subject = _("Your Libervia account has been created") |
340 body = _(WELCOME_MSG).format(profile=profile, jid=jid_s, domain=domain) | 340 body = _(WELCOME_MSG).format(profile=profile, jid=jid_s, domain=domain) |
341 | 341 |
342 # XXX: this will not fail when the email address doesn't exist | 342 # XXX: this will not fail when the email address doesn't exist |
343 # FIXME: check email reception to validate email given by the user | 343 # FIXME: check email reception to validate email given by the user |
344 # FIXME: delete the profile if the email could not been sent? | 344 # FIXME: delete the profile if the email could not been sent? |
345 d_user = sat_email.sendEmail(self.host.memory.config, [email], subject, body) | 345 d_user = sat_email.send_email(self.host.memory.config, [email], subject, body) |
346 d_user.addCallbacks( | 346 d_user.addCallbacks( |
347 lambda __: log.debug( | 347 lambda __: log.debug( |
348 "Account creation confirmation sent to <{}>".format(email) | 348 "Account creation confirmation sent to <{}>".format(email) |
349 ), | 349 ), |
350 self._sendEmailEb, | 350 self._send_email_eb, |
351 errbackArgs=[email] | 351 errbackArgs=[email] |
352 ) | 352 ) |
353 return defer.DeferredList([d_user, d_admin]) | 353 return defer.DeferredList([d_user, d_admin]) |
354 | 354 |
355 def getNewAccountDomain(self): | 355 def account_domain_new_get(self): |
356 """get the domain that will be set to new account""" | 356 """get the domain that will be set to new account""" |
357 | 357 |
358 domain = self.getConfig("new_account_domain") or self.getConfig( | 358 domain = self.config_get("new_account_domain") or self.config_get( |
359 "xmpp_domain", None | 359 "xmpp_domain", None |
360 ) | 360 ) |
361 if not domain: | 361 if not domain: |
362 log.warning( | 362 log.warning( |
363 _( | 363 _( |
365 ).format(default=DEFAULT_DOMAIN) | 365 ).format(default=DEFAULT_DOMAIN) |
366 ) | 366 ) |
367 return DEFAULT_DOMAIN | 367 return DEFAULT_DOMAIN |
368 return domain | 368 return domain |
369 | 369 |
370 def _getAccountDialogUI(self, profile): | 370 def _get_account_dialog_ui(self, profile): |
371 """Get the main dialog to manage your account | 371 """Get the main dialog to manage your account |
372 @param menu_data | 372 @param menu_data |
373 @param profile: %(doc_profile)s | 373 @param profile: %(doc_profile)s |
374 @return: XML of the dialog | 374 @return: XML of the dialog |
375 """ | 375 """ |
379 title=D_("Manage your account"), | 379 title=D_("Manage your account"), |
380 submit_id=self.__account_cb_id, | 380 submit_id=self.__account_cb_id, |
381 ) | 381 ) |
382 tab_container = form_ui.current_container | 382 tab_container = form_ui.current_container |
383 | 383 |
384 tab_container.addTab( | 384 tab_container.add_tab( |
385 "update", D_("Change your password"), container=xml_tools.PairsContainer | 385 "update", D_("Change your password"), container=xml_tools.PairsContainer |
386 ) | 386 ) |
387 form_ui.addLabel(D_("Current profile password")) | 387 form_ui.addLabel(D_("Current profile password")) |
388 form_ui.addPassword("current_passwd", value="") | 388 form_ui.addPassword("current_passwd", value="") |
389 form_ui.addLabel(D_("New password")) | 389 form_ui.addLabel(D_("New password")) |
392 form_ui.addPassword("new_passwd2", value="") | 392 form_ui.addPassword("new_passwd2", value="") |
393 | 393 |
394 # FIXME: uncomment and fix these features | 394 # FIXME: uncomment and fix these features |
395 """ | 395 """ |
396 if 'GROUPBLOG' in self.host.plugins: | 396 if 'GROUPBLOG' in self.host.plugins: |
397 tab_container.addTab("delete_posts", D_("Delete your posts"), container=xml_tools.PairsContainer) | 397 tab_container.add_tab("delete_posts", D_("Delete your posts"), container=xml_tools.PairsContainer) |
398 form_ui.addLabel(D_("Current profile password")) | 398 form_ui.addLabel(D_("Current profile password")) |
399 form_ui.addPassword("delete_posts_passwd", value="") | 399 form_ui.addPassword("delete_posts_passwd", value="") |
400 form_ui.addLabel(D_("Delete all your posts and their comments")) | 400 form_ui.addLabel(D_("Delete all your posts and their comments")) |
401 form_ui.addBool("delete_posts_checkbox", "false") | 401 form_ui.addBool("delete_posts_checkbox", "false") |
402 form_ui.addLabel(D_("Delete all your comments on other's posts")) | 402 form_ui.addLabel(D_("Delete all your comments on other's posts")) |
403 form_ui.addBool("delete_comments_checkbox", "false") | 403 form_ui.addBool("delete_comments_checkbox", "false") |
404 | 404 |
405 tab_container.addTab("delete", D_("Delete your account"), container=xml_tools.PairsContainer) | 405 tab_container.add_tab("delete", D_("Delete your account"), container=xml_tools.PairsContainer) |
406 form_ui.addLabel(D_("Current profile password")) | 406 form_ui.addLabel(D_("Current profile password")) |
407 form_ui.addPassword("delete_passwd", value="") | 407 form_ui.addPassword("delete_passwd", value="") |
408 form_ui.addLabel(D_("Delete your account")) | 408 form_ui.addLabel(D_("Delete your account")) |
409 form_ui.addBool("delete_checkbox", "false") | 409 form_ui.addBool("delete_checkbox", "false") |
410 """ | 410 """ |
411 | 411 |
412 return form_ui.toXml() | 412 return form_ui.toXml() |
413 | 413 |
414 @defer.inlineCallbacks | 414 @defer.inlineCallbacks |
415 def _accountDialogCb(self, data, profile): | 415 def _account_dialog_cb(self, data, profile): |
416 """Called when the user submits the main account dialog | 416 """Called when the user submits the main account dialog |
417 @param data | 417 @param data |
418 @param profile | 418 @param profile |
419 """ | 419 """ |
420 sat_cipher = yield self.host.memory.asyncGetParamA( | 420 sat_cipher = yield self.host.memory.param_get_a_async( |
421 C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile | 421 C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile |
422 ) | 422 ) |
423 | 423 |
424 @defer.inlineCallbacks | 424 @defer.inlineCallbacks |
425 def verify(attempt): | 425 def verify(attempt): |
440 delete_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_checkbox'] | 440 delete_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_checkbox'] |
441 if delete_checkbox == 'true': | 441 if delete_checkbox == 'true': |
442 verified = yield verify(delete_passwd) | 442 verified = yield verify(delete_passwd) |
443 assert isinstance(verified, bool) | 443 assert isinstance(verified, bool) |
444 if verified: | 444 if verified: |
445 defer.returnValue(self.__deleteAccount(profile)) | 445 defer.returnValue(self.__delete_account(profile)) |
446 defer.returnValue(error_ui()) | 446 defer.returnValue(error_ui()) |
447 | 447 |
448 # check for blog posts deletion | 448 # check for blog posts deletion |
449 if 'GROUPBLOG' in self.host.plugins: | 449 if 'GROUPBLOG' in self.host.plugins: |
450 delete_posts_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_posts_passwd'] | 450 delete_posts_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_posts_passwd'] |
454 comments = delete_comments_checkbox == 'true' | 454 comments = delete_comments_checkbox == 'true' |
455 if posts or comments: | 455 if posts or comments: |
456 verified = yield verify(delete_posts_passwd) | 456 verified = yield verify(delete_posts_passwd) |
457 assert isinstance(verified, bool) | 457 assert isinstance(verified, bool) |
458 if verified: | 458 if verified: |
459 defer.returnValue(self.__deleteBlogPosts(posts, comments, profile)) | 459 defer.returnValue(self.__delete_blog_posts(posts, comments, profile)) |
460 defer.returnValue(error_ui()) | 460 defer.returnValue(error_ui()) |
461 """ | 461 """ |
462 | 462 |
463 # check for password modification | 463 # check for password modification |
464 current_passwd = data[xml_tools.SAT_FORM_PREFIX + "current_passwd"] | 464 current_passwd = data[xml_tools.SAT_FORM_PREFIX + "current_passwd"] |
467 if new_passwd1 or new_passwd2: | 467 if new_passwd1 or new_passwd2: |
468 verified = yield verify(current_passwd) | 468 verified = yield verify(current_passwd) |
469 assert isinstance(verified, bool) | 469 assert isinstance(verified, bool) |
470 if verified: | 470 if verified: |
471 if new_passwd1 == new_passwd2: | 471 if new_passwd1 == new_passwd2: |
472 data = yield self.__changePassword(new_passwd1, profile=profile) | 472 data = yield self.__change_password(new_passwd1, profile=profile) |
473 defer.returnValue(data) | 473 defer.returnValue(data) |
474 else: | 474 else: |
475 defer.returnValue( | 475 defer.returnValue( |
476 error_ui( | 476 error_ui( |
477 D_("The values entered for the new password are not equal.") | 477 D_("The values entered for the new password are not equal.") |
479 ) | 479 ) |
480 defer.returnValue(error_ui()) | 480 defer.returnValue(error_ui()) |
481 | 481 |
482 defer.returnValue({}) | 482 defer.returnValue({}) |
483 | 483 |
484 def __changePassword(self, password, profile): | 484 def __change_password(self, password, profile): |
485 """Ask for a confirmation before changing the XMPP account and SàT profile passwords. | 485 """Ask for a confirmation before changing the XMPP account and SàT profile passwords. |
486 | 486 |
487 @param password (str): the new password | 487 @param password (str): the new password |
488 @param profile (str): %(doc_profile)s | 488 @param profile (str): %(doc_profile)s |
489 """ | 489 """ |
490 session_id, __ = self._sessions.newSession( | 490 session_id, __ = self._sessions.new_session( |
491 {"new_password": password}, profile=profile | 491 {"new_password": password}, profile=profile |
492 ) | 492 ) |
493 form_ui = xml_tools.XMLUI( | 493 form_ui = xml_tools.XMLUI( |
494 "form", | 494 "form", |
495 title=D_("Change your password?"), | 495 title=D_("Change your password?"), |
502 ) | 502 ) |
503 ) | 503 ) |
504 form_ui.addText(D_("Continue with changing the password?")) | 504 form_ui.addText(D_("Continue with changing the password?")) |
505 return {"xmlui": form_ui.toXml()} | 505 return {"xmlui": form_ui.toXml()} |
506 | 506 |
507 def __changePasswordCb(self, data, profile): | 507 def __change_password_cb(self, data, profile): |
508 """Actually change the user XMPP account and SàT profile password | 508 """Actually change the user XMPP account and SàT profile password |
509 @param data (dict) | 509 @param data (dict) |
510 @profile (str): %(doc_profile)s | 510 @profile (str): %(doc_profile)s |
511 """ | 511 """ |
512 client = self.host.getClient(profile) | 512 client = self.host.get_client(profile) |
513 password = self._sessions.profileGet(data["session_id"], profile)["new_password"] | 513 password = self._sessions.profile_get(data["session_id"], profile)["new_password"] |
514 del self._sessions[data["session_id"]] | 514 del self._sessions[data["session_id"]] |
515 | 515 |
516 def passwordChanged(__): | 516 def password_changed(__): |
517 d = self.host.memory.setParam( | 517 d = self.host.memory.param_set( |
518 C.PROFILE_PASS_PATH[1], | 518 C.PROFILE_PASS_PATH[1], |
519 password, | 519 password, |
520 C.PROFILE_PASS_PATH[0], | 520 C.PROFILE_PASS_PATH[0], |
521 profile_key=profile, | 521 profile_key=profile, |
522 ) | 522 ) |
523 d.addCallback( | 523 d.addCallback( |
524 lambda __: self.host.memory.setParam( | 524 lambda __: self.host.memory.param_set( |
525 "Password", password, "Connection", profile_key=profile | 525 "Password", password, "Connection", profile_key=profile |
526 ) | 526 ) |
527 ) | 527 ) |
528 confirm_ui = xml_tools.XMLUI("popup", title=D_("Confirmation")) | 528 confirm_ui = xml_tools.XMLUI("popup", title=D_("Confirmation")) |
529 confirm_ui.addText(D_("Your password has been changed.")) | 529 confirm_ui.addText(D_("Your password has been changed.")) |
534 error_ui.addText( | 534 error_ui.addText( |
535 D_("Your password could not be changed: %s") % failure.getErrorMessage() | 535 D_("Your password could not be changed: %s") % failure.getErrorMessage() |
536 ) | 536 ) |
537 return defer.succeed({"xmlui": error_ui.toXml()}) | 537 return defer.succeed({"xmlui": error_ui.toXml()}) |
538 | 538 |
539 d = self.host.plugins["XEP-0077"].changePassword(client, password) | 539 d = self.host.plugins["XEP-0077"].change_password(client, password) |
540 d.addCallbacks(passwordChanged, errback) | 540 d.addCallbacks(password_changed, errback) |
541 return d | 541 return d |
542 | 542 |
543 def __deleteAccount(self, profile): | 543 def __delete_account(self, profile): |
544 """Ask for a confirmation before deleting the XMPP account and SàT profile | 544 """Ask for a confirmation before deleting the XMPP account and SàT profile |
545 @param profile | 545 @param profile |
546 """ | 546 """ |
547 form_ui = xml_tools.XMLUI( | 547 form_ui = xml_tools.XMLUI( |
548 "form", title=D_("Delete your account?"), submit_id=self.__delete_account_id | 548 "form", title=D_("Delete your account?"), submit_id=self.__delete_account_id |
559 ) | 559 ) |
560 form_ui.addText( | 560 form_ui.addText( |
561 D_( | 561 D_( |
562 "All your data stored on %(server)s, including your %(target)s will be erased." | 562 "All your data stored on %(server)s, including your %(target)s will be erased." |
563 ) | 563 ) |
564 % {"server": self.getNewAccountDomain(), "target": target} | 564 % {"server": self.account_domain_new_get(), "target": target} |
565 ) | 565 ) |
566 form_ui.addText( | 566 form_ui.addText( |
567 D_( | 567 D_( |
568 "There is no other confirmation dialog, this is the very last one! Are you sure?" | 568 "There is no other confirmation dialog, this is the very last one! Are you sure?" |
569 ) | 569 ) |
570 ) | 570 ) |
571 return {"xmlui": form_ui.toXml()} | 571 return {"xmlui": form_ui.toXml()} |
572 | 572 |
573 def __deleteAccountCb(self, data, profile): | 573 def __delete_account_cb(self, data, profile): |
574 """Actually delete the XMPP account and SàT profile | 574 """Actually delete the XMPP account and SàT profile |
575 | 575 |
576 @param data | 576 @param data |
577 @param profile | 577 @param profile |
578 """ | 578 """ |
579 client = self.host.getClient(profile) | 579 client = self.host.get_client(profile) |
580 | 580 |
581 def userDeleted(__): | 581 def user_deleted(__): |
582 | 582 |
583 # FIXME: client should be disconnected at this point, so 2 next loop should be removed (to be confirmed) | 583 # FIXME: client should be disconnected at this point, so 2 next loop should be removed (to be confirmed) |
584 for jid_ in client.roster._jids: # empty roster | 584 for jid_ in client.roster._jids: # empty roster |
585 client.presence.unsubscribe(jid_) | 585 client.presence.unsubscribe(jid_) |
586 | 586 |
587 for jid_ in self.host.memory.getWaitingSub( | 587 for jid_ in self.host.memory.sub_waiting_get( |
588 profile | 588 profile |
589 ): # delete waiting subscriptions | 589 ): # delete waiting subscriptions |
590 self.host.memory.delWaitingSub(jid_) | 590 self.host.memory.del_waiting_sub(jid_) |
591 | 591 |
592 delete_profile = lambda: self.host.memory.asyncDeleteProfile( | 592 delete_profile = lambda: self.host.memory.profile_delete_async( |
593 profile, force=True | 593 profile, force=True |
594 ) | 594 ) |
595 if "GROUPBLOG" in self.host.plugins: | 595 if "GROUPBLOG" in self.host.plugins: |
596 d = self.host.plugins["GROUPBLOG"].deleteAllGroupBlogsAndComments( | 596 d = self.host.plugins["GROUPBLOG"].deleteAllGroupBlogsAndComments( |
597 profile_key=profile | 597 profile_key=profile |
609 % failure.getErrorMessage() | 609 % failure.getErrorMessage() |
610 ) | 610 ) |
611 return defer.succeed({"xmlui": error_ui.toXml()}) | 611 return defer.succeed({"xmlui": error_ui.toXml()}) |
612 | 612 |
613 d = self.host.plugins["XEP-0077"].unregister(client, jid.JID(client.jid.host)) | 613 d = self.host.plugins["XEP-0077"].unregister(client, jid.JID(client.jid.host)) |
614 d.addCallbacks(userDeleted, errback) | 614 d.addCallbacks(user_deleted, errback) |
615 return d | 615 return d |
616 | 616 |
617 def __deleteBlogPosts(self, posts, comments, profile): | 617 def __delete_blog_posts(self, posts, comments, profile): |
618 """Ask for a confirmation before deleting the blog posts | 618 """Ask for a confirmation before deleting the blog posts |
619 @param posts: delete all posts of the user (and their comments) | 619 @param posts: delete all posts of the user (and their comments) |
620 @param comments: delete all the comments of the user on other's posts | 620 @param comments: delete all the comments of the user on other's posts |
621 @param data | 621 @param data |
622 @param profile | 622 @param profile |
676 ) | 676 ) |
677 ) | 677 ) |
678 | 678 |
679 return {"xmlui": form_ui.toXml()} | 679 return {"xmlui": form_ui.toXml()} |
680 | 680 |
681 def __deleteBlogPostsCb(self, posts, comments, data, profile): | 681 def __delete_blog_posts_cb(self, posts, comments, data, profile): |
682 """Actually delete the XMPP account and SàT profile | 682 """Actually delete the XMPP account and SàT profile |
683 @param posts: delete all posts of the user (and their comments) | 683 @param posts: delete all posts of the user (and their comments) |
684 @param comments: delete all the comments of the user on other's posts | 684 @param comments: delete all the comments of the user on other's posts |
685 @param profile | 685 @param profile |
686 """ | 686 """ |
721 return defer.succeed({"xmlui": error_ui.toXml()}) | 721 return defer.succeed({"xmlui": error_ui.toXml()}) |
722 | 722 |
723 d.addCallbacks(deleted, errback) | 723 d.addCallbacks(deleted, errback) |
724 return d | 724 return d |
725 | 725 |
726 def asyncConnectWithXMPPCredentials(self, jid_s, password): | 726 def credentials_xmpp_connect(self, jid_s, password): |
727 """Create and connect a new SàT profile using the given XMPP credentials. | 727 """Create and connect a new SàT profile using the given XMPP credentials. |
728 | 728 |
729 Re-use given JID and XMPP password for the profile name and profile password. | 729 Re-use given JID and XMPP password for the profile name and profile password. |
730 @param jid_s (unicode): JID | 730 @param jid_s (unicode): JID |
731 @param password (unicode): XMPP password | 731 @param password (unicode): XMPP password |
732 @return Deferred(bool) | 732 @return Deferred(bool) |
733 @raise exceptions.PasswordError, exceptions.ConflictError | 733 @raise exceptions.PasswordError, exceptions.ConflictError |
734 """ | 734 """ |
735 try: # be sure that the profile doesn't exist yet | 735 try: # be sure that the profile doesn't exist yet |
736 self.host.memory.getProfileName(jid_s) | 736 self.host.memory.get_profile_name(jid_s) |
737 except exceptions.ProfileUnknownError: | 737 except exceptions.ProfileUnknownError: |
738 pass | 738 pass |
739 else: | 739 else: |
740 raise exceptions.ConflictError | 740 raise exceptions.ConflictError |
741 | 741 |
742 d = self.createProfile(password, jid_s, jid_s) | 742 d = self.create_profile(password, jid_s, jid_s) |
743 d.addCallback( | 743 d.addCallback( |
744 lambda __: self.host.memory.getProfileName(jid_s) | 744 lambda __: self.host.memory.get_profile_name(jid_s) |
745 ) # checks if the profile has been successfuly created | 745 ) # checks if the profile has been successfuly created |
746 d.addCallback(lambda profile: defer.ensureDeferred( | 746 d.addCallback(lambda profile: defer.ensureDeferred( |
747 self.host.connect(profile, password, {}, 0))) | 747 self.host.connect(profile, password, {}, 0))) |
748 | 748 |
749 def connected(result): | 749 def connected(result): |
750 self.sendEmails(None, profile=jid_s) | 750 self.send_emails(None, profile=jid_s) |
751 return result | 751 return result |
752 | 752 |
753 def removeProfile( | 753 def remove_profile( |
754 failure | 754 failure |
755 ): # profile has been successfully created but the XMPP credentials are wrong! | 755 ): # profile has been successfully created but the XMPP credentials are wrong! |
756 log.debug( | 756 log.debug( |
757 "Removing previously auto-created profile: %s" % failure.getErrorMessage() | 757 "Removing previously auto-created profile: %s" % failure.getErrorMessage() |
758 ) | 758 ) |
759 self.host.memory.asyncDeleteProfile(jid_s) | 759 self.host.memory.profile_delete_async(jid_s) |
760 raise failure | 760 raise failure |
761 | 761 |
762 # FIXME: we don't catch the case where the JID host is not an XMPP server, and the user | 762 # FIXME: we don't catch the case where the JID host is not an XMPP server, and the user |
763 # has to wait until the DBUS timeout ; as a consequence, emails are sent to the admins | 763 # has to wait until the DBUS timeout ; as a consequence, emails are sent to the admins |
764 # and the profile is not deleted. When the host exists, removeProfile is well called. | 764 # and the profile is not deleted. When the host exists, remove_profile is well called. |
765 d.addCallbacks(connected, removeProfile) | 765 d.addCallbacks(connected, remove_profile) |
766 return d | 766 return d |