source: mauRepo/dj_security/trunk/dj_security/__init__.py @ 8791

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/dj_security/trunk/dj_security/__init__.py@8791
Revision 8791, 1.7 KB checked in by mnagni, 6 years ago (diff)

Incomplete - # 22737: [CEDA Site Python Port] Resource Registration - Make Agreement Docs PDFs
 http://team.ceda.ac.uk/trac/ceda/ticket/22737
Incomplete - # 22802: [CEDA Site Python Port] Login - no message is displayed when the user enters the wrong password
 http://team.ceda.ac.uk/trac/ceda/ticket/22802

Implements the "Reset Password" functionality

  • Property svn:mime-type set to text/plain
Line 
1__version__ = '0.0.3'
2
3from django.core.mail.message import EmailMultiAlternatives
4import smtplib
5import logging
6from django.conf import settings
7
8
9# Get an instance of a logger
10LOGGER = logging.getLogger(__name__)
11
12def cookie_domain():
13    return getattr(settings, 'COOKIE_DOMAIN', None)
14
15def reset_password():
16    return getattr(settings, 'CC_RESET_PASSWORD', [])
17
18def _redirect_field_name():
19    return getattr(settings, 'REDIRECT_FIELD_NAME', 'r')
20
21def _token_field_name():
22    return getattr(settings, 'TOKEN_FIELD_NAME', 't')
23
24def auth_tkt_name():
25    return getattr(settings, 'AUTH_TKT_NAME', 'auth_tkt')
26
27def shared_secret():
28    return getattr(settings, 'SECURITY_SHAREDSECRET', 'sharedsecret')
29
30def ds_send_mail(mail_subject, msg, mail_from, to_email,
31                 log_msgs = [], attachments = None, send_html=True, cc=None):
32    '''
33    **attachment** is a list of triples (filename, content, mimetype)
34    '''
35    try:       
36        email = EmailMultiAlternatives(mail_subject,
37                                       msg,
38                                       mail_from,
39                                       to_email,
40                                       cc=cc)
41        if attachments:
42            for att in attachments:
43                email.attach(att[0], att[1], att[2])
44       
45        if send_html:       
46            html_msg = "<html><head></head><body>" + msg + "</body></html>"
47            email.attach_alternative(html_msg, "text/html")
48                           
49               
50        email.message().as_string()
51        email.send()       
52    except smtplib.SMTPException:
53        for lmsg in log_msgs:
54            LOGGER.error("Error sending email %s" % lmsg)
55    for lmsg in log_msgs:
56        LOGGER.info(lmsg)
Note: See TracBrowser for help on using the repository browser.