comparison 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
comparison
equal deleted inserted replaced
643:262d9d9ad27a 644:53de6954e94e
20 from logging import debug, info, warning, error 20 from logging import debug, info, warning, error
21 from sat.core import exceptions 21 from sat.core import exceptions
22 from twisted.internet import reactor, defer, protocol 22 from twisted.internet import reactor, defer, protocol
23 from os.path import join, dirname 23 from os.path import join, dirname
24 from twisted.python.procutils import which 24 from twisted.python.procutils import which
25 from twisted.python.failure import Failure
25 from email.mime.text import MIMEText 26 from email.mime.text import MIMEText
26 from twisted.mail.smtp import sendmail 27 from twisted.mail.smtp import sendmail
27 28
28 PLUGIN_INFO = { 29 PLUGIN_INFO = {
29 "name": "Account Plugin", 30 "name": "Account Plugin",
71 if (reason.value.exitCode == 0): 72 if (reason.value.exitCode == 0):
72 info(_('Prosody registration success')) 73 info(_('Prosody registration success'))
73 self.deferred.callback(None) 74 self.deferred.callback(None)
74 else: 75 else:
75 error(_(u"Can't register Prosody account (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data}) 76 error(_(u"Can't register Prosody account (error code: %(code)d): %(message)s") % {'code': reason.value.exitCode, 'message': self.data})
76 self.deferred.errback("INTERNAL") 77 self.deferred.errback(Failure(u"INTERNAL"))
77 78
78 79
79 class MiscAccount(object): 80 class MiscAccount(object):
80 """Account plugin: create a SàT + Prosody account, used by Libervia""" 81 """Account plugin: create a SàT + Prosody account, used by Libervia"""
81 #XXX: This plugin is a Q&D one used for the demo. Something more generic (and not 82 #XXX: This plugin is a Q&D one used for the demo. Something more generic (and not
106 """ 107 """
107 if not email or not password or not profile: 108 if not email or not password or not profile:
108 raise exceptions.DataError 109 raise exceptions.DataError
109 110
110 if profile.lower() in RESERVED: 111 if profile.lower() in RESERVED:
111 return defer.fail('CONFLICT') 112 return defer.fail(Failure(u'CONFLICT'))
112 113
113 d = self.host.memory.asyncCreateProfile(profile) 114 d = self.host.memory.asyncCreateProfile(profile)
114 d.addCallback(self._profileRegistered, email, password, profile) 115 d.addCallback(self._profileRegistered, email, password, profile)
115 return d 116 return d
116 117