Mercurial > libervia-backend
annotate src/plugins/plugin_misc_account.py @ 1031:e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 12 May 2014 17:51:38 +0200 |
parents | 301b342c697a |
children | 76ad41b708e1 |
rev | line source |
---|---|
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
4 # SAT plugin for account creation (experimental) |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
20 from sat.core.i18n import _, D_ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
21 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
22 log = getLogger(__name__) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.core import exceptions |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.internet import reactor, defer, protocol |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from os.path import join, dirname |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from twisted.python.procutils import which |
644
53de6954e94e
plugin misc_account: fix for sending a failure message
souliane <souliane@mailoo.org>
parents:
641
diff
changeset
|
27 from twisted.python.failure import Failure |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
28 from email.mime.text import MIMEText |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
29 from twisted.mail.smtp import sendmail |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
30 from sat.tools import xml_tools |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
33 "name": "Account Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
34 "import_name": "MISC-ACCOUNT", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
35 "type": "MISC", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
36 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
37 "dependencies": [], |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
38 "recommendations": ['GROUPBLOG'], |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
39 "main": "MiscAccount", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
40 "handler": "no", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
41 "description": _(u"""SàT account creation""") |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 } |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
44 CONFIG_SECTION = "plugin account" |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
45 |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
46 # You need do adapt the following consts to your server |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
47 # all theses values (key=option name, value=default) can (and should) be overriden in sat.conf |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
48 # in section CONFIG_SECTION |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
50 default_conf = {"email_from": "NOREPLY@example.net", |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
51 "email_server": "localhost", |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
52 "admin_email": "admin@example.net", |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
53 "new_account_server": "localhost", |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
54 "new_account_domain": "example.net", |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
55 "new_account_resource": "libervia", |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
56 "prosody_path": None, # prosody path (where prosodyctl will be executed from), or None to automaticaly find it |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
57 "prosodyctl": "prosodyctl", |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
58 "reserved_list": ['libervia'] # profiles which can't be used |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
59 } |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
61 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
62 class PasswordsMatchingError(Exception): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
63 pass |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
64 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
65 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 class ProsodyRegisterProtocol(protocol.ProcessProtocol): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 """ Try to register an account with prosody """ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
68 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
69 def __init__(self, password=None, deferred=None): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
70 """ |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
71 @param password: new user password |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
72 @param deferred |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
73 """ |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 self.password = password |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 self.deferred = deferred |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 self.data = '' |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
77 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 def connectionMade(self): |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
79 if self.password is None: |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
80 return |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
81 self.transport.write("%s\n%s" % ((self.password.encode('utf-8'),) * 2)) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 self.transport.closeStdin() |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 def outReceived(self, data): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 self.data += data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
86 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 def errReceived(self, data): |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
88 self.data += data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
89 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 def processEnded(self, reason): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 if (reason.value.exitCode == 0): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
92 log.info(_('Prosody command succeed')) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 self.deferred.callback(None) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 else: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
95 log.error(_(u"Can't complete Prosody command (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data}) |
751
1def5b7edf9f
core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents:
733
diff
changeset
|
96 self.deferred.errback(Failure(exceptions.InternalError)) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
98 @classmethod |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
99 def prosodyctl(cls, plugin, command, password=None, profile=None): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
100 """Create a new ProsodyRegisterProtocol and execute the given prosodyctl command. |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
101 @param plugin: instance of MiscAccount |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
102 @param command: the command to execute: "adduser", "passwd" or "deluser" |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
103 @param password: the user new password (leave to None for "deluser" command) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
104 @param profile: the user profile |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
105 @return: a Deferred instance |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
106 """ |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
107 d = defer.Deferred() |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
108 prosody_reg = ProsodyRegisterProtocol(password, d) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
109 prosody_exe = join(plugin._prosody_path, plugin.getConfig('prosodyctl')) |
934
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
110 # TODO delete account which are not on the same host |
954
5925c9ebfcd2
plugin account: reverted patch abd3a75d629c
Goffi <goffi@goffi.org>
parents:
948
diff
changeset
|
111 reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, command, "%s@%s" % (profile, plugin.getConfig('new_account_domain'))], path=plugin._prosody_path) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
112 return d |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
113 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
115 class MiscAccount(object): |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 """Account plugin: create a SàT + Prosody account, used by Libervia""" |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 #XXX: This plugin is a Q&D one used for the demo. Something more generic (and not |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 # only focused on Prosody) is planed |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
121 log.info(_(u"Plugin Account initialization")) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 self.host = host |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
123 host.bridge.addMethod("registerSatAccount", ".plugin", in_sign='sss', out_sign='', method=self._registerAccount, async=True) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
954
diff
changeset
|
124 host.bridge.addMethod("getNewAccountDomain", ".plugin", in_sign='', out_sign='s', method=self.getNewAccountDomain, async=False) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
125 host.bridge.addMethod("getAccountDialogUI", ".plugin", in_sign='s', out_sign='s', method=self._getAccountDialogUI, async=False) |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
126 self._prosody_path = self.getConfig('prosody_path') |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
127 if self._prosody_path is None: |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
128 paths = which(self.getConfig('prosodyctl')) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 if not paths: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
130 log.error(_("Can't find %s") % (self.getConfig('prosodyctl'), )) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 else: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 self._prosody_path = dirname(paths[0]) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
133 log.info(_('Prosody path found: %s') % (self._prosody_path, )) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
135 self.__account_cb_id = host.registerCallback(self._accountDialogCb, with_data=True) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
136 self.__delete_account_id = host.registerCallback(self.__deleteAccountCb, with_data=True) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
137 |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
138 def deleteBlogCallback(posts, comments): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
139 return lambda data, profile: self.__deleteBlogPostsCb(posts, comments, data, profile) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
140 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
141 self.__delete_posts_comments_id = host.registerCallback(deleteBlogCallback(True, True), with_data=True) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
142 self.__delete_posts_id = host.registerCallback(deleteBlogCallback(True, False), with_data=True) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
143 self.__delete_comments_id = host.registerCallback(deleteBlogCallback(False, True), with_data=True) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
144 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
145 def getConfig(self, name): |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
146 return self.host.memory.getConfig(CONFIG_SECTION, name) or default_conf[name] |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
147 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 def _registerAccount(self, email, password, profile): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
149 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 #Password Generation |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 #_charset = [chr(i) for i in range(0x21,0x7F)] #XXX: this charset seems to have some issues with openfire |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 _charset = [chr(i) for i in range(0x30,0x3A) + range(0x41,0x5B) + range (0x61,0x7B)] |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 import random |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 random.seed() |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 password = ''.join([random.choice(_charset) for i in range(15)]) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 if not email or not password or not profile: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 raise exceptions.DataError |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
161 if profile.lower() in self.getConfig('reserved_list'): |
751
1def5b7edf9f
core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents:
733
diff
changeset
|
162 return defer.fail(Failure(exceptions.ConflictError)) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
164 d = self.host.memory.asyncCreateProfile(profile, password) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 d.addCallback(self._profileRegistered, email, password, profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 return d |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 def _profileRegistered(self, result, email, password, profile): |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
169 """Create the profile and the XMPP account. |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
170 |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
171 @param result: result of asyncCreateProfile |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
172 @param email: user email |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
173 @param password: chosen xmpp password |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
174 @param profile: %(doc_profile)s |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
175 @return: a deferred None value when all the processing is done |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
176 """ |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 #FIXME: values must be in a config file instead of hardcoded |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
178 self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, self.getConfig('new_account_domain'), self.getConfig('new_account_resource')), |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
179 "Connection", profile_key=profile) |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
180 self.host.memory.setParam("Server", self.getConfig('new_account_server'), |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
181 "Connection", profile_key=profile) |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
182 self.host.memory.setParam("Password", password, |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
183 "Connection", profile_key=profile) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 #and the account |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
185 |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
186 # XXX: we use "prosodyctl adduser" because "register" doesn't check conflict |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
187 # and just change the password if the account already exists |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
188 d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile) |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
189 d.addCallback(self._sendEmails, profile, email, password) |
733 | 190 d.addCallback(lambda ignore: None) |
191 return d | |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
193 def _sendEmails(self, result, login, email, password): |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
194 #time to send the email |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
195 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
196 _email_host = self.getConfig('email_server') |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
197 _email_from = self.getConfig("email_from") |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
198 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
199 def email_ok(ignore): |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
200 print ("Account creation email sent to %s" % email) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
202 def email_ko(ignore): |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
203 #TODO: return error code to user |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
204 log.error("Failed to send email to %s" % email) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
205 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
206 body = (u"""Welcome to Libervia, a Salut à Toi project part |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
207 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
208 /!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\ |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
210 Here are your connection informations: |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
211 --- |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
212 login: %(login)s |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
213 password: %(password)s |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
215 Your Jabber ID (JID) is: %(jid)s |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
216 --- |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 |
870
e030460e065e
plugin misc account: updated the welcome email
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
218 To try with some contacts, you can use the directory: subscribe in your parameters, and use it with the Communication/Search directory menu. |
e030460e065e
plugin misc account: updated the welcome email
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
219 |
e030460e065e
plugin misc account: updated the welcome email
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
220 SàT website: http://www.salut-a-toi.org |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
221 follow SàT news: http://www.goffi.org |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
222 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
223 Any feedback welcome |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
224 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
225 Cheers |
870
e030460e065e
plugin misc account: updated the welcome email
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
226 SàT team""" % {'login': login, 'password': password, 'jid': "%s@%s" % (login, self.getConfig('new_account_domain'))}).encode('utf-8') |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
227 msg = MIMEText(body, 'plain', 'UTF-8') |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
228 msg['Subject'] = 'Libervia account created' |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
229 msg['From'] = _email_from |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
230 msg['To'] = email |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
232 d_user = sendmail(_email_host, _email_from, email, msg.as_string()) |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
233 d_user.addCallbacks(email_ok, email_ko) |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
234 |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
235 #email to the administrator |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
236 body = (u"""New account created: %(login)s [%(email)s]""" % {'login': login, 'email': email}).encode('utf-8') |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
237 msg = MIMEText(body, 'plain', 'UTF-8') |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
238 msg['Subject'] = 'Libervia new account created' |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
239 msg['From'] = _email_from |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
240 msg['To'] = self.getConfig('admin_email') |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
242 d_admin = sendmail(_email_host, _email_from, self.getConfig('admin_email'), msg.as_string()) |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
243 d_admin.addCallbacks(email_ok, email_ko) |
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
244 return defer.DeferredList([d_user, d_admin]) |
672
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
245 |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
954
diff
changeset
|
246 def getNewAccountDomain(self): |
672
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
247 """@return: the domain that will be set to new account""" |
730
32bbabe809da
plugin account: configuration constants can be overriden in sat.conf (section "plugin account") + better deferred management in email sending
Goffi <goffi@goffi.org>
parents:
672
diff
changeset
|
248 return self.getConfig('new_account_domain') |
672
712e3782af12
plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents:
644
diff
changeset
|
249 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
250 def _getAccountDialogUI(self, profile): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
251 """Get the main dialog to manage your account |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
252 @param menu_data |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
253 @param profile: %(doc_profile)s |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
254 @return: XML of the dialog |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
255 """ |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
256 form_ui = xml_tools.XMLUI("form", "tabs", title=D_("Manage your XMPP account"), submit_id=self.__account_cb_id) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
257 tab_container = form_ui.current_container |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
258 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
259 tab_container.addTab("update", D_("Change your password"), container=xml_tools.PairsContainer) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
260 form_ui.addLabel(D_("Current password")) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
261 form_ui.addPassword("current_passwd", value="") |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
262 form_ui.addLabel(D_("New password")) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
263 form_ui.addPassword("new_passwd1", value="") |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
264 form_ui.addLabel(D_("New password (again)")) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
265 form_ui.addPassword("new_passwd2", value="") |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
266 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
267 if 'GROUPBLOG' in self.host.plugins: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
268 tab_container.addTab("delete_posts", D_("Delete your posts"), container=xml_tools.PairsContainer) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
269 form_ui.addLabel(D_("Current password")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
270 form_ui.addPassword("delete_posts_passwd", value="") |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
271 form_ui.addLabel(D_("Delete all your posts and their comments")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
272 form_ui.addBool("delete_posts_checkbox", "false") |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
273 form_ui.addLabel(D_("Delete all your comments on other's posts")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
274 form_ui.addBool("delete_comments_checkbox", "false") |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
275 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
276 tab_container.addTab("delete", D_("Delete your account"), container=xml_tools.PairsContainer) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
277 form_ui.addLabel(D_("Current password")) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
278 form_ui.addPassword("delete_passwd", value="") |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
279 form_ui.addLabel(D_("Delete your account")) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
280 form_ui.addBool("delete_checkbox", "false") |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
281 return form_ui.toXml() |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
282 |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
283 @defer.inlineCallbacks |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
284 def _accountDialogCb(self, data, profile): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
285 """Called when the user submits the main account dialog |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
286 @param data |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
287 @param profile |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
288 """ |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
289 password = yield self.host.memory.asyncGetParamA("Password", "Connection", profile_key=profile) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
290 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
291 def error_ui(): |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
292 error_ui = xml_tools.XMLUI("popup", title=D_("Error")) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
293 error_ui.addText(D_("Passwords don't match!")) |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
294 return {'xmlui': error_ui.toXml()} |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
295 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
296 # check for account deletion |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
297 delete_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_passwd'] |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
298 delete_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_checkbox'] |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
299 if delete_checkbox == 'true': |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
300 if password == delete_passwd: |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
301 defer.returnValue(self.__deleteAccount(profile)) |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
302 defer.returnValue(error_ui()) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
303 |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
304 # check for blog posts deletion |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
305 if 'GROUPBLOG' in self.host.plugins: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
306 delete_posts_passwd = data[xml_tools.SAT_FORM_PREFIX + 'delete_posts_passwd'] |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
307 delete_posts_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_posts_checkbox'] |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
308 delete_comments_checkbox = data[xml_tools.SAT_FORM_PREFIX + 'delete_comments_checkbox'] |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
309 posts = delete_posts_checkbox == 'true' |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
310 comments = delete_comments_checkbox == 'true' |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
311 if posts or comments: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
312 if password == delete_posts_passwd: |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
313 defer.returnValue(self.__deleteBlogPosts(posts, comments, profile)) |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
314 defer.returnValue(error_ui()) |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
315 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
316 # check for password modification |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
317 current_passwd = data[xml_tools.SAT_FORM_PREFIX + 'current_passwd'] |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
318 new_passwd1 = data[xml_tools.SAT_FORM_PREFIX + 'new_passwd1'] |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
319 new_passwd2 = data[xml_tools.SAT_FORM_PREFIX + 'new_passwd2'] |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
320 if new_passwd1 or new_passwd2: |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
321 if password == current_passwd and new_passwd1 == new_passwd2: |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
322 data = yield self.__changePassword(new_passwd1, profile=profile) |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
323 defer.returnValue(data) |
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
324 defer.returnValue(error_ui()) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
325 |
1031
e90125d07072
plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
326 defer.returnValue({}) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
327 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
328 def __changePassword(self, password, profile): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
329 """Actually change the user XMPP account and SàT profile password |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
330 @param password: new password |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
331 @profile |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
332 """ |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
333 def passwordChanged(result): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
334 self.host.memory.setParam("Password", password, "Connection", profile_key=profile) |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
335 confirm_ui = xml_tools.XMLUI("popup", title=D_("Confirmation")) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
336 confirm_ui.addText(D_("Your password has been changed.")) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
337 return defer.succeed({'xmlui': confirm_ui.toXml()}) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
338 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
339 def errback(failure): |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
340 error_ui = xml_tools.XMLUI("popup", title=D_("Error")) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
341 error_ui.addText(D_("Your password could not be changed: %s") % failure.getErrorMessage()) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
342 return defer.succeed({'xmlui': error_ui.toXml()}) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
343 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
344 d = ProsodyRegisterProtocol.prosodyctl(self, 'passwd', password, profile=profile) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
345 d.addCallbacks(passwordChanged, errback) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
346 return d |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
347 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
348 def __deleteAccount(self, profile): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
349 """Ask for a confirmation before deleting the XMPP account and SàT profile |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
350 @param profile |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
351 """ |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
352 form_ui = xml_tools.XMLUI("form", title=D_("Delete your account?"), submit_id=self.__delete_account_id) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
353 form_ui.addText(D_("If you confirm this dialog, you will be disconnected and then your XMPP account AND your SàT profile will both be DELETED.")) |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
354 target = D_('contact list, messages history, blog posts and comments' if 'GROUPBLOG' in self.host.plugins else D_('contact list and messages history')) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
954
diff
changeset
|
355 form_ui.addText(D_("All your data stored on %(server)s, including your %(target)s will be erased.") % {'server': self.getNewAccountDomain(), 'target': target}) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
356 form_ui.addText(D_("There is no other confirmation dialog, this is the very last one! Are you sure?")) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
357 return {'xmlui': form_ui.toXml()} |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
358 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
359 def __deleteAccountCb(self, data, profile): |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
360 """Actually delete the XMPP account and SàT profile |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
361 @param data |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
362 @param profile |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
363 """ |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
364 def userDeleted(result): |
934
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
365 client = self.host.profiles[profile] |
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
366 |
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
367 for jid_ in client.roster._jids: # empty roster |
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
368 client.presence.unsubscribe(jid_) |
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
369 |
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
370 for jid_ in self.host.memory.getWaitingSub(profile): # delete waiting subscriptions |
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
371 self.host.memory.delWaitingSub(jid_) |
34dd9287dfe5
plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents:
895
diff
changeset
|
372 |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
373 delete_profile = lambda: self.host.memory.asyncDeleteProfile(profile, force=True) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
374 if 'GROUPBLOG' in self.host.plugins: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
375 d = self.host.plugins['GROUPBLOG'].deleteAllGroupBlogsAndComments(profile_key=profile) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
376 d.addCallback(lambda dummy: delete_profile()) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
377 else: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
378 delete_profile() |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
379 |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
380 return defer.succeed({}) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
381 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
382 def errback(failure): |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
383 error_ui = xml_tools.XMLUI("popup", title=D_("Error")) |
895
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
384 error_ui.addText(D_("Your XMPP account could not be deleted: %s") % failure.getErrorMessage()) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
385 return defer.succeed({'xmlui': error_ui.toXml()}) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
386 |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
387 d = ProsodyRegisterProtocol.prosodyctl(self, 'deluser', profile=profile) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
388 d.addCallbacks(userDeleted, errback) |
52ee240acc9c
plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents:
870
diff
changeset
|
389 return d |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
390 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
391 def __deleteBlogPosts(self, posts, comments, profile): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
392 """Ask for a confirmation before deleting the blog posts |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
393 @param posts: delete all posts of the user (and their comments) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
394 @param comments: delete all the comments of the user on other's posts |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
395 @param data |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
396 @param profile |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
397 """ |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
398 if posts: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
399 if comments: # delete everything |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
400 form_ui = xml_tools.XMLUI("form", title=D_("Delete all your (micro-)blog posts and comments?"), submit_id=self.__delete_posts_comments_id) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
401 form_ui.addText(D_("If you confirm this dialog, all the (micro-)blog data you submitted will be erased.")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
402 form_ui.addText(D_("These are the public and private posts and comments you sent to any group.")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
403 form_ui.addText(D_("There is no other confirmation dialog, this is the very last one! Are you sure?")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
404 else: # delete only the posts |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
405 form_ui = xml_tools.XMLUI("form", title=D_("Delete all your (micro-)blog posts?"), submit_id=self.__delete_posts_id) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
406 form_ui.addText(D_("If you confirm this dialog, all the public and private posts you sent to any group will be erased.")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
407 form_ui.addText(D_("There is no other confirmation dialog, this is the very last one! Are you sure?")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
408 elif comments: # delete only the comments |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
409 form_ui = xml_tools.XMLUI("form", title=D_("Delete all your (micro-)blog comments?"), submit_id=self.__delete_comments_id) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
410 form_ui.addText(D_("If you confirm this dialog, all the public and private comments you made on other people's posts will be erased.")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
411 form_ui.addText(D_("There is no other confirmation dialog, this is the very last one! Are you sure?")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
412 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
413 return {'xmlui': form_ui.toXml()} |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
414 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
415 def __deleteBlogPostsCb(self, posts, comments, data, profile): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
416 """Actually delete the XMPP account and SàT profile |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
417 @param posts: delete all posts of the user (and their comments) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
418 @param comments: delete all the comments of the user on other's posts |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
419 @param profile |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
420 """ |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
421 if posts: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
422 if comments: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
423 target = D_('blog posts and comments') |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
424 d = self.host.plugins['GROUPBLOG'].deleteAllGroupBlogsAndComments(profile_key=profile) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
425 else: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
426 target = D_('blog posts') |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
427 d = self.host.plugins['GROUPBLOG'].deleteAllGroupBlogs(profile_key=profile) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
428 elif comments: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
429 target = D_('comments') |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
430 d = self.host.plugins['GROUPBLOG'].deleteAllGroupBlogsComments(profile_key=profile) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
431 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
432 def deleted(result): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
433 ui = xml_tools.XMLUI("popup", title=D_("Deletion confirmation")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
434 # TODO: change the message when delete/retract notifications are done with XEP-0060 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
435 ui.addText(D_("Your %(target)s have been deleted.") % {'target': target}) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
436 ui.addText(D_("Known issue of the demo version: you need to refresh the page to make the deleted posts actually disappear.")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
437 return defer.succeed({'xmlui': ui.toXml()}) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
438 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
439 def errback(failure): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
440 error_ui = xml_tools.XMLUI("popup", title=D_("Error")) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
441 error_ui.addText(D_("Your %(target)s could not be deleted: %(message)s") % {'target': target, 'message': failure.getErrorMessage()}) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
442 return defer.succeed({'xmlui': error_ui.toXml()}) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
443 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
444 d.addCallbacks(deleted, errback) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
445 return d |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
934
diff
changeset
|
446 |