annotate src/plugins/plugin_misc_account.py @ 1932:44342730df66

jp (cmd/roster): fixes division by zero exceptions fix bug 135
author souliane <souliane@mailoo.org>
date Sun, 17 Apr 2016 13:00:44 +0200
parents 72837638f076
children 2daf7b4c6756
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1765
diff changeset
5 # Copyright (C) 2009-2016 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
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
24 from sat.tools import xml_tools
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
25 from sat.memory.memory import Sessions
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
26 from sat.memory.crypto import PasswordHasher
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
27 from sat.core.constants import Const as C
1855
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
28 import ConfigParser
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
29 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
30 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
31 from twisted.python.failure import Failure
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
32 from twisted.mail.smtp import sendmail
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
33 from os.path import join, dirname
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
34 from email.mime.text import MIMEText
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
35
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
36 import random
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
37
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
38
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
39 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
40 "name": "Account Plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
41 "import_name": "MISC-ACCOUNT",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
42 "type": "MISC",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
43 "protocols": [],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
44 "dependencies": [],
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
45 "recommendations": ['GROUPBLOG'],
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
46 "main": "MiscAccount",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
47 "handler": "no",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
48 "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
49 }
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
50
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
51 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
52
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 # 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
54 # 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
55 # 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
56
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
57 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
58 "email_server": "localhost",
1855
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
59 "email_sender_domain": "",
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
60 "email_port": 25,
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
61 "email_username": "",
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
62 "email_password": "",
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
63 "email_starttls": "false",
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
64 "email_auth": "false",
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
65 "email_admins_list": [],
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
66 "admin_email": "",
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
67 "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
68 "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
69 "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
70 "prosodyctl": "prosodyctl",
1727
68e498b3367e reverted revision 2ebe66a96d05
souliane <souliane@mailoo.org>
parents: 1726
diff changeset
71 "reserved_list": ['libervia'] # profiles which can't be used
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
72 }
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
73
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
74
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
75 class PasswordsMatchingError(Exception):
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
76 pass
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
77
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
78
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
79 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
80 """ Try to register an account with prosody """
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
81
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
82 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
83 """
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
84 @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
85 @param deferred
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
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 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
88 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
89 self.data = ''
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
90
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
91 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
92 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
93 return
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
94 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
95 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
96
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
97 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
98 self.data += data
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
99
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
100 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
101 self.data += data
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
102
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
103 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
104 if (reason.value.exitCode == 0):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 987
diff changeset
105 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
106 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
107 else:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 987
diff changeset
108 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
109 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
110
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
111 @classmethod
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
112 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
113 """Create a new ProsodyRegisterProtocol and execute the given prosodyctl command.
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
114
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
115 @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
116 @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
117 @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
118 @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
119 @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
120 """
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
121 d = defer.Deferred()
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
122 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
123 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
124 # 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
125 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
126 return d
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
127
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
128
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
129 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
130 """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
131 #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
132 # 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
133
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 987
diff changeset
135 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
136 self.host = host
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
137 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
138 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
139 host.bridge.addMethod("getAccountDialogUI", ".plugin", in_sign='s', out_sign='s', method=self._getAccountDialogUI, async=False)
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
140 host.bridge.addMethod("asyncConnectWithXMPPCredentials", ".plugin", in_sign='ss', out_sign='b', method=self.asyncConnectWithXMPPCredentials, async=True)
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
141 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
142 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
143 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
144 if not paths:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
145 log.error(_(u"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
146 else:
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
147 self._prosody_path = dirname(paths[0])
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
148 log.info(_(u'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
149
1892
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
150 self.fixEmailAdmins()
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
151 self._sessions = Sessions()
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
152
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
153 self.__account_cb_id = host.registerCallback(self._accountDialogCb, with_data=True)
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
154 self.__change_password_id = host.registerCallback(self.__changePasswordCb, with_data=True)
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
155
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
156 def deleteBlogCallback(posts, comments):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
157 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
158
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
159 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
160 self.__delete_comments_id = host.registerCallback(deleteBlogCallback(False, True), with_data=True)
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
161 self.__delete_posts_comments_id = host.registerCallback(deleteBlogCallback(True, True), with_data=True)
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
162
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
163 self.__delete_account_id = host.registerCallback(self.__deleteAccountCb, with_data=True)
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
164
1892
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
165
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
166 # FIXME: remove this after some time, when the deprecated parameter is really abandoned
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
167 def fixEmailAdmins(self):
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
168 """Handle deprecated config option "admin_email" to fix the admin emails list"""
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
169 admin_email = self.getConfig('admin_email')
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
170 if not admin_email:
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
171 return
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
172 log.warning(u"admin_email parameter is deprecated, please use email_admins_list instead")
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
173 param_name = "email_admins_list"
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
174 try:
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
175 section = ""
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
176 value = self.host.memory.getConfig(section, param_name, Exception)
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
177 except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
178 section = CONFIG_SECTION
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
179 value = self.host.memory.getConfig(section, param_name, default_conf[param_name])
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
180
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
181 value = set(value)
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
182 value.add(admin_email)
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
183 self.host.memory.config.set(section, param_name, ",".join(value))
8a5b178ff28b plugin misc_account: fixes handling of deprecater parameter "admin_email"
souliane <souliane@mailoo.org>
parents: 1856
diff changeset
184
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
185 def getConfig(self, name):
1855
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
186 if name.startswith("email_"):
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
187 # XXX: email_ parameters were first in [plugin account] section
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
188 # but as it make more sense to have them in common with other plugins,
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
189 # they can now be in [DEFAULT] section
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
190 try:
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
191 value = self.host.memory.getConfig(None, name, Exception)
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
192 except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
193 pass
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
194 else:
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
195 return value
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
196
1234
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1212
diff changeset
197 return self.host.memory.getConfig(CONFIG_SECTION, name, default_conf[name])
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
198
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
199 def generatePassword(self):
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
200 """Generate a password with random characters.
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
201
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
202 @return unicode
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
203 """
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
204 random.seed()
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
205 #charset = [chr(i) for i in range(0x21,0x7F)] #XXX: this charset seems to have some issues with openfire
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
206 charset = [chr(i) for i in range(0x30,0x3A) + range(0x41,0x5B) + range (0x61,0x7B)]
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
207 return ''.join([random.choice(charset) for i in range(15)])
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
208
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
209 def _registerAccount(self, email, password, profile):
1727
68e498b3367e reverted revision 2ebe66a96d05
souliane <souliane@mailoo.org>
parents: 1726
diff changeset
210 return self.registerAccount(email, password, None, profile)
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
211
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
212 def registerAccount(self, email, password, jid_s, profile):
1907
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
213 """Register a new profile, its associated XMPP account, send the confirmation emails.
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
214
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
215 @param email (unicode): where to send to confirmation email to
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
216 @param password (unicode): password chosen by the user
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
217 while be used for profile *and* XMPP account
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
218 @param jid_s (unicode): JID to re-use or to register:
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
219 - non empty value: bind this JID to the new sat profile
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
220 - None or "": register a new JID on the local XMPP server
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
221 @param profile
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
222 @return Deferred
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
223 """
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
224 d = self.createProfile(password, jid_s, profile)
1916
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
225 d.addCallback(lambda dummy: self.sendEmails(email, profile))
1907
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
226 return d
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
227
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
228 def createProfile(self, password, jid_s, profile):
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
229 """Register a new profile and its associated XMPP account.
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
230
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
231 @param password (unicode): password chosen by the user
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
232 while be used for profile *and* XMPP account
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
233 @param jid_s (unicode): JID to re-use or to register:
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
234 - non empty value: bind this JID to the new sat profile
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
235 - None or "": register a new JID on the local XMPP server
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
236 @param profile
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
237 @return Deferred
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
238 """
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
239 if not password or not 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
240 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
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 if profile.lower() in self.getConfig('reserved_list'):
751
1def5b7edf9f core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents: 733
diff changeset
243 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
244
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
245 d = self.host.memory.asyncCreateProfile(profile, password)
1907
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
246 d.addCallback(lambda dummy: self.profileCreated(password, jid_s, 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
247 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
248
1907
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
249 def profileCreated(self, password, jid_s, profile):
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
250 """Create the XMPP account and set the profile connection parameters.
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
251
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
252 @param password (unicode): password chosen by the user
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
253 @param jid_s (unicode): JID to re-use or to register:
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
254 - non empty value: bind this JID to the new sat profile
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
255 - None or empty: register a new JID on the local XMPP server
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
256 @param profile
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
257 @return: Deferred
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
258 """
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
259 # XXX: we use "prosodyctl adduser" because "register" doesn't check conflict and just change the password if the account already exists
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
260 if jid_s:
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
261 d = defer.succeed(None)
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
262 else:
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
263 d = ProsodyRegisterProtocol.prosodyctl(self, 'adduser', password, profile)
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
264 jid_s = "%s@%s" % (profile, self.getConfig('new_account_domain'))
1729
9037161e28f0 plugin misc_account: send email to the admins when a new profile is created for an external XMPP account
souliane <souliane@mailoo.org>
parents: 1727
diff changeset
265
1080
f25ec9fd7cc4 plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
souliane <souliane@mailoo.org>
parents: 1044
diff changeset
266 def setParams(dummy):
1091
2d035aaea13b plugin misc_account: delete the profile session after the registration is done
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
267 self.host.memory.setParam("JabberID", jid_s, "Connection", profile_key=profile)
2d035aaea13b plugin misc_account: delete the profile session after the registration is done
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
268 d = self.host.memory.setParam("Password", password, "Connection", profile_key=profile)
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
269 return d
1080
f25ec9fd7cc4 plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
souliane <souliane@mailoo.org>
parents: 1044
diff changeset
270
f25ec9fd7cc4 plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
souliane <souliane@mailoo.org>
parents: 1044
diff changeset
271 def removeProfile(failure):
f25ec9fd7cc4 plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
souliane <souliane@mailoo.org>
parents: 1044
diff changeset
272 self.host.memory.asyncDeleteProfile(profile)
f25ec9fd7cc4 plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
souliane <souliane@mailoo.org>
parents: 1044
diff changeset
273 return failure
f25ec9fd7cc4 plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
souliane <souliane@mailoo.org>
parents: 1044
diff changeset
274
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
275 d.addCallback(lambda dummy: self.host.memory.startSession(password, profile))
1080
f25ec9fd7cc4 plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
souliane <souliane@mailoo.org>
parents: 1044
diff changeset
276 d.addCallback(setParams)
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
277 d.addCallback(lambda dummy: self.host.memory.stopSession(profile))
1080
f25ec9fd7cc4 plugin misc_account: suppress the profile after its creation if the XMPP account registration failed
souliane <souliane@mailoo.org>
parents: 1044
diff changeset
278 d.addErrback(removeProfile)
733
fe05afc3f0df reverted last commit
Goffi <goffi@goffi.org>
parents: 732
diff changeset
279 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
280
1916
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
281 def sendEmails(self, email, profile):
1433
5d42e2219d7c plugin misc_account: change the message sent by email after an account creation
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
282 # time to send the email
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
283
1765
b9493cb6ce49 plugin misc_account: fixes login messages when sending emails
souliane <souliane@mailoo.org>
parents: 1729
diff changeset
284 email_host = self.getConfig('email_server')
b9493cb6ce49 plugin misc_account: fixes login messages when sending emails
souliane <souliane@mailoo.org>
parents: 1729
diff changeset
285 email_from = self.getConfig("email_from")
1855
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
286 email_sender_domain = self.getConfig("email_sender_domain") or None
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
287 email_port = int(self.getConfig("email_port"))
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
288 email_username = self.getConfig("email_username") or None
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
289 email_password = self.getConfig("email_password") or None
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
290 email_starttls = C.bool(self.getConfig("email_starttls"))
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
291 email_auth = C.bool(self.getConfig("email_auth"))
1433
5d42e2219d7c plugin misc_account: change the message sent by email after an account creation
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
292 domain = self.getConfig('new_account_domain')
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
293
1898
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
294 def sendEmail(recipients, msg):
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
295 return sendmail(email_host.encode("utf-8"),
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
296 email_from.encode("utf-8"),
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
297 [email.encode("utf-8") for email in recipients],
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
298 msg.as_string(),
1901
faa8427dd032 plugin misc account: fixed handling of None/empty values in sendEmails.sendEmail
Goffi <goffi@goffi.org>
parents: 1898
diff changeset
299 senderDomainName=email_sender_domain.encode("utf-8") if email_sender_domain else None,
1898
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
300 port=email_port,
1901
faa8427dd032 plugin misc account: fixed handling of None/empty values in sendEmails.sendEmail
Goffi <goffi@goffi.org>
parents: 1898
diff changeset
301 username=email_username.encode("utf-8") if email_username else None,
faa8427dd032 plugin misc account: fixed handling of None/empty values in sendEmails.sendEmail
Goffi <goffi@goffi.org>
parents: 1898
diff changeset
302 password=email_password.encode("utf-8") if email_password else None,
1898
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
303 requireAuthentication=email_starttls,
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
304 requireTransportSecurity=email_auth)
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
305
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
306 # email to the administrators
1855
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
307 admins_emails = self.getConfig('email_admins_list')
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
308 if not admins_emails:
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
309 log.warning(u"No known admin email, we can't send email to administrator(s).\nPlease fill email_admins_list parameter")
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
310 d_admin = defer.fail(exceptions.DataError("no admin email"))
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
311 else:
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
312 body = (u"""New account created: %(profile)s [%(email)s]""" % {'profile': profile, 'email': email}).encode('utf-8')
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
313 msg = MIMEText(body, 'plain', 'UTF-8')
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
314 msg['Subject'] = _('New Libervia account created')
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
315 msg['From'] = email_from
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
316 msg['To'] = ", ".join(admins_emails)
1729
9037161e28f0 plugin misc_account: send email to the admins when a new profile is created for an external XMPP account
souliane <souliane@mailoo.org>
parents: 1727
diff changeset
317
1898
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
318 d_admin = sendEmail(admins_emails, msg)
1855
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
319 admins_emails_txt = u', '.join([u"<{}>".format(addr) for addr in admins_emails])
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
320 d_admin.addCallbacks(lambda dummy: log.debug(u"Account creation notification sent to admin(s) {}".format(admins_emails_txt)),
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
321 lambda dummy: log.error(u"Failed to send account creation notification to admin {}".format(admins_emails_txt)))
1729
9037161e28f0 plugin misc_account: send email to the admins when a new profile is created for an external XMPP account
souliane <souliane@mailoo.org>
parents: 1727
diff changeset
322 if not email:
9037161e28f0 plugin misc_account: send email to the admins when a new profile is created for an external XMPP account
souliane <souliane@mailoo.org>
parents: 1727
diff changeset
323 return d_admin
9037161e28f0 plugin misc_account: send email to the admins when a new profile is created for an external XMPP account
souliane <souliane@mailoo.org>
parents: 1727
diff changeset
324
1916
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
325 jid_s = self.host.memory.getParamA("JabberID", "Connection", profile_key=profile)
1433
5d42e2219d7c plugin misc_account: change the message sent by email after an account creation
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
326 body = (_(u"""Welcome to Libervia, the web interface of Salut à Toi.
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
327
1897
e15c7d71ae76 plugin account: fixed use of {domain} instead of hardcoded libervia.org for welcoming e-mail.
Goffi <goffi@goffi.org>
parents: 1892
diff changeset
328 Your account on {domain} has been successfully created. This is a demonstration version to show you the current status of the project. It is still under development, please keep it in mind!
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
329
1040
76ad41b708e1 plugin misc_account: do not send the password with the confirmation email for account creation
souliane <souliane@mailoo.org>
parents: 1031
diff changeset
330 Here is your connection information:
1433
5d42e2219d7c plugin misc_account: change the message sent by email after an account creation
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
331
1897
e15c7d71ae76 plugin account: fixed use of {domain} instead of hardcoded libervia.org for welcoming e-mail.
Goffi <goffi@goffi.org>
parents: 1892
diff changeset
332 Login on {domain}: {profile}
e15c7d71ae76 plugin account: fixed use of {domain} instead of hardcoded libervia.org for welcoming e-mail.
Goffi <goffi@goffi.org>
parents: 1892
diff changeset
333 Jabber ID (JID): {jid}
1856
d7e29a12ec2c plugin account: modifications in welcoming email:
Goffi <goffi@goffi.org>
parents: 1855
diff changeset
334 Your password has been chosen by yourself during registration.
569
06faf5bffbc0 plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff changeset
335
1856
d7e29a12ec2c plugin account: modifications in welcoming email:
Goffi <goffi@goffi.org>
parents: 1855
diff changeset
336 In the beginning, you have nobody to talk to. To find some contacts, you may use the users' directory:
1707
94c450972346 primitivus and plugins: renamed a few menus:
souliane <souliane@mailoo.org>
parents: 1696
diff changeset
337 - make yourself visible in "Service / Directory subscription".
94c450972346 primitivus and plugins: renamed a few menus:
souliane <souliane@mailoo.org>
parents: 1696
diff changeset
338 - search for people with "Contacts" / Search directory".
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
339
1433
5d42e2219d7c plugin misc_account: change the message sent by email after an account creation
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
340 Any feedback welcome. Thank you!
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
341
1433
5d42e2219d7c plugin misc_account: change the message sent by email after an account creation
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
342 Salut à Toi association
5d42e2219d7c plugin misc_account: change the message sent by email after an account creation
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
343 http://www.salut-a-toi.org
1897
e15c7d71ae76 plugin account: fixed use of {domain} instead of hardcoded libervia.org for welcoming e-mail.
Goffi <goffi@goffi.org>
parents: 1892
diff changeset
344 """).format(profile=profile, jid=jid_s, domain=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
345 msg = MIMEText(body, 'plain', 'UTF-8')
1433
5d42e2219d7c plugin misc_account: change the message sent by email after an account creation
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
346 msg['Subject'] = _(u'Libervia account created')
1765
b9493cb6ce49 plugin misc_account: fixes login messages when sending emails
souliane <souliane@mailoo.org>
parents: 1729
diff changeset
347 msg['From'] = 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
348 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
349
1765
b9493cb6ce49 plugin misc_account: fixes login messages when sending emails
souliane <souliane@mailoo.org>
parents: 1729
diff changeset
350 def email_ko(dummy):
b9493cb6ce49 plugin misc_account: fixes login messages when sending emails
souliane <souliane@mailoo.org>
parents: 1729
diff changeset
351 # TODO: return error code to user
b9493cb6ce49 plugin misc_account: fixes login messages when sending emails
souliane <souliane@mailoo.org>
parents: 1729
diff changeset
352 log.error(u"Failed to send account creation confirmation to <%s>" % email)
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
353
1804
33e73c70d78a plugin misc_account: add a FIXME comment
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
354 # XXX: this will not fail when the email address doesn't exist
33e73c70d78a plugin misc_account: add a FIXME comment
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
355 # FIXME: check email reception to validate email given by the user
33e73c70d78a plugin misc_account: add a FIXME comment
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
356 # FIXME: delete the profile if the email could not been sent?
1898
31b8a58cfcf5 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
souliane <souliane@mailoo.org>
parents: 1897
diff changeset
357 d_user = sendEmail([email], msg)
1765
b9493cb6ce49 plugin misc_account: fixes login messages when sending emails
souliane <souliane@mailoo.org>
parents: 1729
diff changeset
358 d_user.addCallbacks(lambda dummy: log.debug(u"Account creation confirmation sent to <%s>" % email),
b9493cb6ce49 plugin misc_account: fixes login messages when sending emails
souliane <souliane@mailoo.org>
parents: 1729
diff changeset
359 email_ko)
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
360 return defer.DeferredList([d_user, d_admin])
672
712e3782af12 plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents: 644
diff changeset
361
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 954
diff changeset
362 def getNewAccountDomain(self):
672
712e3782af12 plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents: 644
diff changeset
363 """@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
364 return self.getConfig('new_account_domain')
672
712e3782af12 plugin misc_account: added method getNewAccountDomain
souliane <souliane@mailoo.org>
parents: 644
diff changeset
365
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
366 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
367 """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
368 @param menu_data
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
369 @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
370 @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
371 """
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
372 form_ui = xml_tools.XMLUI("form", "tabs", title=D_("Manage your account"), submit_id=self.__account_cb_id)
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
373 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
374
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
375 tab_container.addTab("update", D_("Change your password"), container=xml_tools.PairsContainer)
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
376 form_ui.addLabel(D_("Current profile password"))
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
377 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
378 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
379 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
380 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
381 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
382
1855
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
383 # FIXME: uncomment and fix these features
1713
0d972af37ff5 plugin misc_account: temporary disabling posts and account deletion
souliane <souliane@mailoo.org>
parents: 1707
diff changeset
384 """
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
385 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
386 tab_container.addTab("delete_posts", D_("Delete your posts"), container=xml_tools.PairsContainer)
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
387 form_ui.addLabel(D_("Current profile password"))
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
388 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
389 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
390 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
391 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
392 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
393
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
394 tab_container.addTab("delete", D_("Delete your account"), container=xml_tools.PairsContainer)
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
395 form_ui.addLabel(D_("Current profile password"))
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
396 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
397 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
398 form_ui.addBool("delete_checkbox", "false")
1713
0d972af37ff5 plugin misc_account: temporary disabling posts and account deletion
souliane <souliane@mailoo.org>
parents: 1707
diff changeset
399 """
0d972af37ff5 plugin misc_account: temporary disabling posts and account deletion
souliane <souliane@mailoo.org>
parents: 1707
diff changeset
400
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
401 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
402
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
403 @defer.inlineCallbacks
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
404 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
405 """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
406 @param data
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
407 @param profile
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
408 """
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
409 sat_cipher = yield self.host.memory.asyncGetParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], 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
410
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
411 @defer.inlineCallbacks
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
412 def verify(attempt):
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
413 auth = yield PasswordHasher.verify(attempt, sat_cipher)
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
414 defer.returnValue(auth)
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
415
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
416 def error_ui(message=None):
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
417 if not message:
1691
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
418 message = D_("The provided profile password doesn't match.")
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
419 error_ui = xml_tools.XMLUI("popup", title=D_("Attempt failure"))
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
420 error_ui.addText(message)
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
421 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
422
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
423 # check for account deletion
1855
1c9b2c184663 plugin account: email sending improvments:
Goffi <goffi@goffi.org>
parents: 1804
diff changeset
424 # FIXME: uncomment and fix these features
1713
0d972af37ff5 plugin misc_account: temporary disabling posts and account deletion
souliane <souliane@mailoo.org>
parents: 1707
diff changeset
425 """
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
426 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
427 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
428 if delete_checkbox == 'true':
1691
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
429 verified = yield verify(delete_passwd)
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
430 assert isinstance(verified, bool)
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
431 if verified:
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
432 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
433 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
434
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
435 # 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
436 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
437 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
438 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
439 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
440 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
441 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
442 if posts or comments:
1691
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
443 verified = yield verify(delete_posts_passwd)
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
444 assert isinstance(verified, bool)
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
445 if verified:
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
446 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
447 defer.returnValue(error_ui())
1713
0d972af37ff5 plugin misc_account: temporary disabling posts and account deletion
souliane <souliane@mailoo.org>
parents: 1707
diff changeset
448 """
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
449
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
450 # 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
451 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
452 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
453 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
454 if new_passwd1 or new_passwd2:
1691
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
455 verified = yield verify(current_passwd)
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
456 assert isinstance(verified, bool)
cec204c6360c plugin misc_account: fixed password verification
souliane <souliane@mailoo.org>
parents: 1653
diff changeset
457 if verified:
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
458 if new_passwd1 == new_passwd2:
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
459 data = yield self.__changePassword(new_passwd1, profile=profile)
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
460 defer.returnValue(data)
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
461 else:
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
462 defer.returnValue(error_ui(D_("The values entered for the new password are not equal.")))
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
463 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
464
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
465 defer.returnValue({})
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
466
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
467 def __changePassword(self, password, profile):
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
468 """Ask for a confirmation before changing the XMPP account and SàT profile passwords.
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
469
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
470 @param password (str): the new password
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
471 @param profile (str): %(doc_profile)s
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
472 """
1212
628e320eab1f memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents: 1091
diff changeset
473 session_id, dummy = self._sessions.newSession({'new_password': password}, profile=profile)
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
474 form_ui = xml_tools.XMLUI("form", title=D_("Change your password?"), submit_id=self.__change_password_id, session_id=session_id)
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
475 form_ui.addText(D_("Note for advanced users: this will actually change both your SàT profile password AND your XMPP account password."))
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
476 form_ui.addText(D_("Continue with changing the password?"))
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
477 return {'xmlui': form_ui.toXml()}
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
478
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
479 def __changePasswordCb(self, data, profile):
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
480 """Actually change the user XMPP account and SàT profile password
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
481 @param data (dict)
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
482 @profile (str): %(doc_profile)s
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
483 """
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
484 password = self._sessions.profileGet(data['session_id'], profile)['new_password']
1044
85c110c0be86 plugins misc_account, misc_register_account: manually delete the sessions when not needed anymore
souliane <souliane@mailoo.org>
parents: 1041
diff changeset
485 del self._sessions[data['session_id']]
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
486
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
487 def passwordChanged(result):
1041
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
488 d = self.host.memory.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=profile)
9095263011b6 plugin misc_accout: update relative to the introduction of profile password:
souliane <souliane@mailoo.org>
parents: 1040
diff changeset
489 d.addCallback(lambda dummy: 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
490 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
491 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
492 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
493
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
494 def errback(failure):
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
495 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
496 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
497 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
498
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
499 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
500 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
501 return d
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
502
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
503 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
504 """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
505 @param profile
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
506 """
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
507 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
508 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
509 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
510 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
511 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
512 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
513
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
514 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
515 """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
516 @param data
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
517 @param profile
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
518 """
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
519 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
520 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
521
34dd9287dfe5 plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents: 895
diff changeset
522 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
523 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
524
34dd9287dfe5 plugin account: bug fix profile deletion from the database + unsubscribe the contacts
souliane <souliane@mailoo.org>
parents: 895
diff changeset
525 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
526 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
527
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
528 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
529 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
530 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
531 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
532 else:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
533 delete_profile()
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
534
895
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
535 return defer.succeed({})
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
536
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
537 def errback(failure):
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
538 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
539 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
540 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
541
52ee240acc9c plugin account: user can change his password or delete his XMPP account
souliane <souliane@mailoo.org>
parents: 870
diff changeset
542 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
543 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
544 return d
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
545
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
546 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
547 """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
548 @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
549 @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
550 @param data
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
551 @param profile
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
552 """
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
553 if posts:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
554 if comments: # delete everything
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
555 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
556 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
557 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
558 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
559 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
560 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
561 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
562 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
563 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
564 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
565 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
566 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
567
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
568 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
569
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
570 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
571 """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
572 @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
573 @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
574 @param profile
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
575 """
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
576 if posts:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
577 if comments:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
578 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
579 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
580 else:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
581 target = D_('blog posts')
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
582 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
583 elif comments:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
584 target = D_('comments')
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
585 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
586
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
587 def deleted(result):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
588 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
589 # 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
590 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
591 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
592 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
593
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
594 def errback(failure):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
595 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
596 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
597 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
598
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
599 d.addCallbacks(deleted, errback)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
600 return d
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 934
diff changeset
601
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
602 def asyncConnectWithXMPPCredentials(self, jid_s, password):
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
603 """Create and connect a new SàT profile using the given XMPP credentials.
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
604
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
605 Re-use given JID and XMPP password for the profile name and profile password.
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
606 @param jid_s (unicode): JID
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
607 @param password (unicode): XMPP password
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
608 @return Deferred(bool)
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
609 @raise exceptions.PasswordError, exceptions.ConflictError
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
610 """
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
611 try: # be sure that the profile doesn't exist yet
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
612 self.host.memory.getProfileName(jid_s)
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
613 except exceptions.ProfileUnknownError:
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
614 pass
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
615 else:
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
616 raise exceptions.ConflictError
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
617
1907
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
618 d = self.createProfile(password, jid_s, jid_s)
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
619 d.addCallback(lambda dummy: self.host.memory.getProfileName(jid_s)) # checks if the profile has been successfuly created
1725
c1be6363bfab core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents: 1713
diff changeset
620 d.addCallback(self.host.asyncConnect, password, 0)
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
621
1916
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
622
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
623 def connected(result):
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
624 self.sendEmails(None, profile=jid_s)
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
625 return result
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
626
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
627 def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong!
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
628 log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage())
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
629 self.host.memory.asyncDeleteProfile(jid_s)
1696
9a7a27c44611 plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
Goffi <goffi@goffi.org>
parents: 1691
diff changeset
630 raise failure
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
631
1907
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
632 # FIXME: we don't catch the case where the JID host is not an XMPP server, and the user
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
633 # has to wait until the DBUS timeout ; as a consequence, emails are sent to the admins
0b748ad46ede plugin misc account: separate profile creation and sending emails, so we can wait and send the emails at the right time (when we know that no error occured)
souliane <souliane@mailoo.org>
parents: 1901
diff changeset
634 # and the profile is not deleted. When the host exists, removeProfile is well called.
1916
72837638f076 plugin misc_account: fixes two bugs introduced by revision 1907 (0b748ad46ede):
souliane <souliane@mailoo.org>
parents: 1907
diff changeset
635 d.addCallbacks(connected, removeProfile)
1653
200efadcab76 plugin misc_account: add method asyncConnectWithXMPPCredentials
souliane <souliane@mailoo.org>
parents: 1433
diff changeset
636 return d