summaryrefslogtreecommitdiff
path: root/service/pixelated/account_recovery.py
diff options
context:
space:
mode:
Diffstat (limited to 'service/pixelated/account_recovery.py')
-rw-r--r--service/pixelated/account_recovery.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/service/pixelated/account_recovery.py b/service/pixelated/account_recovery.py
index 723d4048..f84aea1a 100644
--- a/service/pixelated/account_recovery.py
+++ b/service/pixelated/account_recovery.py
@@ -15,25 +15,26 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import pkg_resources
+import binascii
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.logger import Logger
from twisted.mail import smtp
-from email.mime.text import MIMEText
-
-from pixelated.resources.account_recovery_resource import AccountRecoveryResource
+from email import message_from_string
+from email.utils import formatdate
log = Logger()
class AccountRecovery(object):
- def __init__(self, session, soledad, smtp_config, backup_email, domain):
+ def __init__(self, session, soledad, smtp_config, backup_email, domain, language='en-US'):
self._bonafide_session = session
self._soledad = soledad
self._smtp_config = smtp_config
self._backup_email = backup_email
self._domain = domain
+ self._language = language
@inlineCallbacks
def update_recovery_code(self):
@@ -56,10 +57,7 @@ class AccountRecovery(object):
log.info('Sending mail containing the user\'s recovery code')
sender = 'team@{}'.format(self._domain)
- msg = MIMEText(self._get_recovery_mail(code))
- msg['Subject'] = 'Recovery Code'
- msg['From'] = sender
- msg['To'] = backup_email
+ msg = self._get_recovery_mail(code, sender, backup_email)
try:
send_mail_result = yield smtp.sendmail(
@@ -72,15 +70,15 @@ class AccountRecovery(object):
log.error('Failed trying to send the email with the recovery code')
raise e
- def _get_recovery_mail(self, code, language='en-US'):
+ def _get_recovery_mail(self, code, sender, backup_email):
recovery_mail = pkg_resources.resource_filename(
'pixelated.assets',
- 'recovery.mail.%s' % (language))
-
- account_recovery_url = '{}/{}'.format(self._domain, AccountRecoveryResource.BASE_URL)
+ 'recovery.mail.%s' % (self._language))
with open(recovery_mail) as mail_template_file:
- return mail_template_file.read().format(
+ return message_from_string(mail_template_file.read().format(
domain=self._domain,
- recovery_code=code,
- account_recovery_url=account_recovery_url)
+ recovery_code=binascii.hexlify(code),
+ backup_email=backup_email,
+ sender=sender,
+ date=formatdate(localtime=True)))