Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_account.py @ 3503:482098e521ff
plugin misc account: specify domain in new account email sent to admins
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 21 Apr 2021 11:36:26 +0200 |
parents | be6d91572633 |
children | 943de4f9ce50 |
comparison
equal
deleted
inserted
replaced
3502:6132d363f0e9 | 3503:482098e521ff |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 | 3 # Libervia plugin for account creation |
4 # SAT plugin for account creation (experimental) | |
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
6 | 5 |
7 # This program is free software: you can redistribute it and/or modify | 6 # This program is free software: you can redistribute it and/or modify |
8 # it under the terms of the GNU Affero General Public License as published by | 7 # it under the terms of the GNU Affero General Public License as published by |
9 # the Free Software Foundation, either version 3 of the License, or | 8 # the Free Software Foundation, either version 3 of the License, or |
46 C.PI_PROTOCOLS: [], | 45 C.PI_PROTOCOLS: [], |
47 C.PI_DEPENDENCIES: ["XEP-0077"], | 46 C.PI_DEPENDENCIES: ["XEP-0077"], |
48 C.PI_RECOMMENDATIONS: ["GROUPBLOG"], | 47 C.PI_RECOMMENDATIONS: ["GROUPBLOG"], |
49 C.PI_MAIN: "MiscAccount", | 48 C.PI_MAIN: "MiscAccount", |
50 C.PI_HANDLER: "no", | 49 C.PI_HANDLER: "no", |
51 C.PI_DESCRIPTION: _("""SàT account creation"""), | 50 C.PI_DESCRIPTION: _("""Libervia account creation"""), |
52 } | 51 } |
53 | 52 |
54 CONFIG_SECTION = "plugin account" | 53 CONFIG_SECTION = "plugin account" |
55 | 54 |
56 # You need do adapt the following consts to your server | 55 # You need do adapt the following consts to your server |
57 # all theses values (key=option name, value=default) can (and should) be overriden in sat.conf | 56 # all theses values (key=option name, value=default) can (and should) be overriden |
58 # in section CONFIG_SECTION | 57 # in libervia.conf in section CONFIG_SECTION |
59 | 58 |
60 default_conf = { | 59 default_conf = { |
61 "email_from": "NOREPLY@example.net", | 60 "email_from": "NOREPLY@example.net", |
62 "email_server": "localhost", | 61 "email_server": "localhost", |
63 "email_sender_domain": "", | 62 "email_sender_domain": "", |
304 | 303 |
305 # email to the administrators | 304 # email to the administrators |
306 admins_emails = self.getConfig("email_admins_list") | 305 admins_emails = self.getConfig("email_admins_list") |
307 if not admins_emails: | 306 if not admins_emails: |
308 log.warning( | 307 log.warning( |
309 "No known admin email, we can't send email to administrator(s).\nPlease fill email_admins_list parameter" | 308 "No known admin email, we can't send email to administrator(s).\n" |
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 body = """New account created: {profile} [{email}]""".format( | 314 # there is no email when an existing XMPP account is used |
315 profile=profile, | 315 body = f"New account created on {domain}: {profile} [{email or '<no email>'}]" |
316 # there is no email when an existing XMPP account is used | |
317 email=email or "<no email>", | |
318 ) | |
319 d_admin = sat_email.sendEmail( | 316 d_admin = sat_email.sendEmail( |
320 self.host.memory.config, admins_emails, subject, body) | 317 self.host.memory.config, admins_emails, subject, body) |
321 | 318 |
322 admins_emails_txt = ", ".join(["<" + addr + ">" for addr in admins_emails]) | 319 admins_emails_txt = ", ".join(["<" + addr + ">" for addr in admins_emails]) |
323 d_admin.addCallbacks( | 320 d_admin.addCallbacks( |