Changeset 7221 for main/waeup.sirp/trunk


Ignore:
Timestamp:
27 Nov 2011, 06:50:43 (13 years ago)
Author:
Henrik Bettermann
Message:

Now we have a configuration object and can provide ContactAdminForm? with proper credentials for a smtp server.

Add Email address to IAccount objects so that 'From' fields in emails, sent by users, can be automatically filled.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/authentication.py

    r7197 r7221  
    8484
    8585    def __init__(self, name, password, title=None, description=None,
    86                  roles = []):
     86                 email=None, roles = []):
    8787        self.name = name
    8888        if title is None:
     
    9292        self.title = title
    9393        self.description = description
     94        self.email = email
    9495        self.setPassword(password)
    9596        #self.setSiteRolesForPrincipal(roles)
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7214 r7221  
    313313        name = data['name']
    314314        title = data['title']
     315        email = data['email']
    315316        description = data['description']
    316317        #password = data['password']
     
    326327                return
    327328        try:
    328             self.context.addUser(name, password, title=title,
     329            self.context.addUser(name, password, title=title, email=email,
    329330                                 description=description, roles=roles)
    330331        except KeyError:
     
    506507        msg['From'] = '%s <%s>' % (fullname,email)
    507508
    508         # These parameters should be part of the portal configuration.
    509         msg['To'] = 'contact@waeup.org'
    510         msg['Subject'] = 'WAeUP Contact'
    511         #server = smtplib.SMTP('smtp_server')
    512         # Also connection details (username, passwords, host, port,
    513         # etc.) should be settable somewhere.
    514         # server.login('user_name','secret_password')
    515         server = smtplib.SMTP('localhost')
    516         server.sendmail(email,'contact@waeup.org',msg.as_string())
     509        config = grok.getSite()['configuration']
     510        msg['To'] = config.email_admin
     511        msg['Subject'] = config.email_subject
     512        server = smtplib.SMTP(config.smtp_server)
     513        if config.smtp_requires_login:
     514            server.login(config.smtp_username,config.smtp_password)
     515        server.sendmail(email,config.email_admin,msg.as_string())
    517516
    518517        server.quit()
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r7197 r7221  
    1717##
    1818import os
     19import re
    1920from datetime import datetime
    2021from hurry.file.interfaces import IFileRetrieval
     
    7172    )
    7273
     74# Define a valiation method for email addresses
     75class NotAnEmailAddress(schema.ValidationError):
     76    __doc__ = u"Invalid email address"
     77
     78check_email = re.compile(
     79    r"[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match
     80
     81def validate_email(value):
     82    if not check_email(value):
     83        raise NotAnEmailAddress(value)
     84    return True
     85
    7386class FatalCSVError(Exception):
    7487    """Some row could not be processed.
     
    196209        description = u'Login name of user',
    197210        required = True,)
     211
    198212    title = schema.TextLine(
    199213        title = u'Name',
    200214        description = u'Real name of user',
    201215        required = False,)
     216
    202217    description = schema.Text(
    203218        title = u'Description/Notice',
    204219        required = False,)
     220
     221    email = schema.ASCIILine(
     222        title = u'Email',
     223        default = None,
     224        required = False,
     225        constraint=validate_email,
     226        )
     227
    205228    roles = schema.List(
    206229        title = u'Portal roles',
     
    287310        default = [],
    288311        )
     312
     313    email_admin = schema.ASCIILine(
     314        title = u'Email',
     315        default = 'contact@waeup.org',
     316        required = False,
     317        constraint=validate_email,
     318        )
     319
     320    email_subject = schema.TextLine(
     321        title = u'Subject of Email to Administrator',
     322        default = u'SIRP Contact',
     323        required = False,
     324        )
     325
     326    smtp_server = schema.TextLine(
     327        title = u'Adress of SMTP Server',
     328        default = u'localhost',
     329        required = False,
     330        )
     331
     332    smtp_requires_login = schema.Bool(
     333        title = u'Server requires login',
     334        default = False,
     335        )
     336
     337    smtp_username = schema.TextLine(
     338        title = u'Username for SMTP Account',
     339        default = None,
     340        required = False,
     341        )
     342
     343    smtp_password = schema.Password(
     344        title = u'Password for SMTP Account',
     345        default = None,
     346        required = False,
     347        )
     348
    289349
    290350class ISessionConfiguration(IWAeUPObject):
  • main/waeup.sirp/trunk/src/waeup/sirp/students/authentication.py

    r7190 r7221  
    5252
    5353    @property
     54    def email(self):
     55        return self.context.email
     56
     57    @property
    5458    def description(self):
    5559        return self.title
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7214 r7221  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
    18 import re
    1918from datetime import datetime
    2019from zope.interface import Attribute, invariant, Interface
    2120from zope.interface.exceptions import Invalid
    2221from zope import schema
    23 from waeup.sirp.interfaces import IWAeUPObject, academic_sessions_vocab
     22from waeup.sirp.interfaces import (
     23    IWAeUPObject, academic_sessions_vocab, validate_email)
    2424from waeup.sirp.schema import TextLineChoice
    2525from waeup.sirp.university.vocabularies import CourseSource, study_modes
     
    3030from waeup.sirp.payments.interfaces import IPaymentsContainer, IOnlinePayment
    3131
    32 # Define a valiation method for email addresses
    33 class NotAnEmailAddress(schema.ValidationError):
    34     __doc__ = u"Invalid email address"
    35 
    36 check_email = re.compile(
    37     r"[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match
    38 def validate_email(value):
    39     if not check_email(value):
    40         raise NotAnEmailAddress(value)
    41     return True
    42 
    4332class IStudentsUtils(Interface):
    4433    """A collection of methods which are subject to customization.
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_authentication.py

    r7193 r7221  
    6363    fullname = 'Test User'
    6464    password = None
     65    email = None
    6566
    6667
  • main/waeup.sirp/trunk/src/waeup/sirp/userscontainer.py

    r7197 r7221  
    3131    grok.require('waeup.manageUsers')
    3232
    33     def addUser(self, name, password, title=None, description=None, roles=[]):
     33    def addUser(self, name, password, title=None,
     34                description=None, email=None, roles=[]):
    3435        """Add a new Account instance, created from parameters.
    3536        """
     
    3839        #if description is None:
    3940        #    description = title
    40         self[name] = Account(name, password, title, description, roles)
     41        self[name] = Account(name, password, title, description, email, roles)
    4142
    4243    def addAccount(self, account):
Note: See TracChangeset for help on using the changeset viewer.