Mercurial > libervia-backend
annotate src/plugins/plugin_misc_account.py @ 644:53de6954e94e
plugin misc_account: fix for sending a failure message
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 08 Sep 2013 14:59:14 +0200 |
parents | 49587e170f53 |
children | 712e3782af12 |
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 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for parrot mode (experimental) |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 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 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from logging import debug, info, warning, error |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core import exceptions |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 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
|
23 from os.path import join, dirname |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 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
|
25 from twisted.python.failure import Failure |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
26 from email.mime.text import MIMEText |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
27 from twisted.mail.smtp import sendmail |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
30 "name": "Account Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
31 "import_name": "MISC-ACCOUNT", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
32 "type": "MISC", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
33 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
34 "dependencies": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
35 "main": "MiscAccount", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
36 "handler": "no", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
37 "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
|
38 } |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 #You need do adapt the following consts to your server |
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
|
41 _REG_EMAIL_FROM = "NOREPLY@example.net" |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 _REG_EMAIL_SERVER = "localhost" |
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
|
43 _REG_ADMIN_EMAIL = "admin@example.net" |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 _NEW_ACCOUNT_SERVER = "localhost" |
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
|
45 _NEW_ACCOUNT_DOMAIN = "example.net" |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 _NEW_ACCOUNT_RESOURCE = "libervia" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
47 _PROSODY_PATH = None # prosody path (where prosodyctl will be executed from), or None to automaticaly find it |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 _PROSODYCTL = "prosodyctl" |
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 RESERVED = ['libervia'] |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
52 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 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
|
54 """ Try to register an account with prosody """ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
55 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
56 def __init__(self, password, deferred=None): |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 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
|
58 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
|
59 self.data = '' |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
60 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 def connectionMade(self): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
62 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
|
63 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
|
64 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 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
|
66 self.data += data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
67 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 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
|
69 self.data += data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
70 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 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
|
72 if (reason.value.exitCode == 0): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 info(_('Prosody registration success')) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 self.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
|
75 else: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 error(_(u"Can't register Prosody account (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data}) |
644
53de6954e94e
plugin misc_account: fix for sending a failure message
souliane <souliane@mailoo.org>
parents:
641
diff
changeset
|
77 self.deferred.errback(Failure(u"INTERNAL")) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
80 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
|
81 """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
|
82 #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
|
83 # 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
|
84 _prosody_path = _PROSODY_PATH or '' |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 def __init__(self, host): |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 info(_(u"Plugin Account initialization")) |
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.host = host |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
89 host.bridge.addMethod("registerSatAccount", ".plugin", in_sign='sss', out_sign='', method=self._registerAccount, async=True) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 if not self._prosody_path: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 paths = which(_PROSODYCTL) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 if not paths: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
93 error(_("Can't find %s") % (_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
|
94 else: |
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._prosody_path = dirname(paths[0]) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
96 info(_('Prosody path found: %s') % (self._prosody_path, )) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 def _registerAccount(self, email, password, profile): |
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 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 #Password Generation |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 #_charset = [chr(i) for i in range(0x21,0x7F)] #XXX: this charset seems to have some issues with openfire |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 _charset = [chr(i) for i in range(0x30,0x3A) + range(0x41,0x5B) + range (0x61,0x7B)] |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 import random |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 random.seed() |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 password = ''.join([random.choice(_charset) for i in range(15)]) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 """ |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 if not email or not password or not profile: |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 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
|
110 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 if profile.lower() in RESERVED: |
644
53de6954e94e
plugin misc_account: fix for sending a failure message
souliane <souliane@mailoo.org>
parents:
641
diff
changeset
|
112 return defer.fail(Failure(u'CONFLICT')) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 d = self.host.memory.asyncCreateProfile(profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 d.addCallback(self._profileRegistered, email, password, profile) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 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
|
117 |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 def _profileRegistered(self, result, email, password, profile): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
119 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 #FIXME: values must be in a config file instead of hardcoded |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
121 self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
122 "Connection", profile_key=profile) |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
123 self.host.memory.setParam("Server", _NEW_ACCOUNT_SERVER, |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
124 "Connection", profile_key=profile) |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
125 self.host.memory.setParam("Password", password, |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
126 "Connection", profile_key=profile) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 #and the account |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
128 |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 #XXX: we use "prosodyctl adduser" because "register" doesn't check conflict |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 # and just change the password if the account already exists |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 d = defer.Deferred() |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 prosody_reg = ProsodyRegisterProtocol(password, d) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
133 prosody_exe = join(self._prosody_path, _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
|
134 reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, 'adduser', "%s@%s" % (profile, _NEW_ACCOUNT_DOMAIN)], path=self._prosody_path) |
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 |
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
|
136 d.addCallback(self._accountCreated, profile, email, password) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 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
|
138 |
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
|
139 def _accountCreated(self, result, login, email, password): |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
140 #time to send the email |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
141 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
142 _email_host = _REG_EMAIL_SERVER |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
143 _email_from = _REG_EMAIL_FROM |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
144 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
145 def email_ok(ignore): |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
146 print ("Account creation email sent to %s" % email) |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
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
|
148 def email_ko(ignore): |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
149 #TODO: return error code to user |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
150 error("Failed to send email to %s" % email) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
151 |
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
|
152 body = (u"""Welcome to Libervia, a Salut à Toi project part |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
153 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
154 /!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\ |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 |
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
|
156 Here are your connection informations: |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
157 --- |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
158 login: %(login)s |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
159 password: %(password)s |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
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
|
161 Your Jabber ID (JID) is: %(jid)s |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
162 --- |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
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
|
164 SàT website: http://sat.goffi.org |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
165 follow SàT news: http://www.goffi.org |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
166 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
167 Any feedback welcome |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
168 |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
169 Cheers |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
170 Goffi""" % {'login': login, 'password': password, 'jid': "%s@%s" % (login, _NEW_ACCOUNT_DOMAIN)}).encode('utf-8') |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
171 msg = MIMEText(body, 'plain', 'UTF-8') |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
172 msg['Subject'] = 'Libervia account created' |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
173 msg['From'] = _email_from |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
174 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
|
175 |
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
|
176 d = sendmail(_email_host, _email_from, email, msg.as_string()) |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
177 d.addCallbacks(email_ok, email_ko) |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
178 #email to the administrator |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
180 body = (u"""New account created: %(login)s [%(email)s]""" % {'login': login, 'email': email}).encode('utf-8') |
571
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
181 msg = MIMEText(body, 'plain', 'UTF-8') |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
182 msg['Subject'] = 'Libervia new account created' |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
183 msg['From'] = _email_from |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
184 msg['To'] = _REG_ADMIN_EMAIL |
569
06faf5bffbc0
plugin account: first draft of automatic SàT/Prosody account creation (basis coming from Libervia)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 |
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
|
186 d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string()) |
1cb24325485c
plugin account: errReceived fix + emails are now sent on new account + generic example server constants
Goffi <goffi@goffi.org>
parents:
569
diff
changeset
|
187 d.addCallbacks(email_ok, email_ko) |