Commit 25284bd5 authored by Barry Warsaw's avatar Barry Warsaw

IRegistrar.register() now requires a mailing list argument. This fixes the

problem where the confirmation message doesn't know where to come from.
parent 8938d653
......@@ -56,7 +56,7 @@ class Registrar:
def __init__(self, context):
self._context = context
def register(self, address, real_name=None, mlist=None):
def register(self, mlist, address, real_name=None):
"""See `IUserRegistrar`."""
# First, do validation on the email address. If the address is
# invalid, it will raise an exception, otherwise it just returns.
......@@ -66,8 +66,7 @@ class Registrar:
type=PendableRegistration.PEND_KEY,
address=address,
real_name=real_name)
if mlist is not None:
pendable['list_name'] = mlist.fqdn_listname
pendable['list_name'] = mlist.fqdn_listname
token = getUtility(IPendings).add(pendable)
# Set up some local variables for translation interpolation.
domain = IDomain(self._context)
......@@ -83,7 +82,7 @@ class Registrar:
# Send a verification email to the address.
text = _(resource_string('mailman.templates.en', 'verify.txt'))
msg = UserNotification(address, confirm_address, subject, text)
msg.send(mlist=mlist)
msg.send(mlist)
return token
def confirm(self, token):
......
......@@ -75,7 +75,7 @@ example:
'$self.name: No valid address found to subscribe')
return ContinueProcessing.no
registrar = IRegistrar(mlist.domain)
registrar.register(address, real_name, mlist)
registrar.register(mlist, address, real_name)
person = formataddr((real_name, address))
print >> results, _('Confirmation email sent to $person')
return ContinueProcessing.yes
......
......@@ -46,32 +46,37 @@ Here is a helper function to extract tokens from confirmation messages.
Invalid email addresses
=======================
The only piece of information you need to register is the email address.
Addresses are registered within the context of a mailing list, mostly so that
confirmation emails can come from some place. You also need the email
address.
>>> mlist = create_list('[email protected]')
Some amount of sanity checks are performed on the email address, although
honestly, not as much as probably should be done. Still, some patently bad
addresses are rejected outright.
>>> registrar.register('')
>>> registrar.register(mlist, '')
Traceback (most recent call last):
...
InvalidEmailAddress: u''
>>> registrar.register('some [email protected]')
>>> registrar.register(mlist, 'some [email protected]')
Traceback (most recent call last):
...
InvalidEmailAddress: u'some [email protected]'
>>> registrar.register('<script>@example.com')
>>> registrar.register(mlist, '<script>@example.com')
Traceback (most recent call last):
...
InvalidEmailAddress: u'<script>@example.com'
>>> registrar.register('\[email protected]')
>>> registrar.register(mlist, '\[email protected]')
Traceback (most recent call last):
...
InvalidEmailAddress: u'\[email protected]'
>>> registrar.register('noatsign')
>>> registrar.register(mlist, 'noatsign')
Traceback (most recent call last):
...
InvalidEmailAddress: u'noatsign'
>>> registrar.register('[email protected]')
>>> registrar.register(mlist, '[email protected]')
Traceback (most recent call last):
...
InvalidEmailAddress: u'[email protected]'
......@@ -85,7 +90,7 @@ is complete. No IUser or IAddress is created at registration time, but a
record is added to the pending database, and the token for that record is
returned.
>>> token = registrar.register('[email protected]', 'Anne Person')
>>> token = registrar.register(mlist, '[email protected]', 'Anne Person')
>>> check_token(token)
ok
......@@ -105,10 +110,11 @@ But this address is waiting for confirmation.
>>> from zope.component import getUtility
>>> pendingdb = getUtility(IPendings)
>>> sorted(pendingdb.confirm(token, expunge=False).items())
[(u'address', u'[email protected]'),
(u'real_name', u'Anne Person'),
(u'type', u'registration')]
>>> dump_msgdata(pendingdb.confirm(token, expunge=False))
address : [email protected]
list_name: [email protected]
real_name: Anne Person
type : registration
Verification by email
......@@ -157,6 +163,7 @@ message is sent to the user in order to verify the registered address.
<BLANKLINE>
>>> dump_msgdata(qdata)
_parsemsg : False
listname : [email protected]
nodecorate : True
recipients : [u'[email protected]']
reduced_list_headers: True
......@@ -209,7 +216,7 @@ Non-standard registrations
If you try to confirm a registration token twice, of course only the first one
will work. The second one is ignored.
>>> token = registrar.register('[email protected]')
>>> token = registrar.register(mlist, '[email protected]')
>>> check_token(token)
ok
>>> filebase = switchboard.files[0]
......@@ -229,7 +236,8 @@ confirmation step is completed.
>>> user_manager.create_address('[email protected]')
<Address: [email protected] [not verified] at ...>
>>> token = registrar.register('[email protected]', 'Claire Person')
>>> token = registrar.register(
... mlist, '[email protected]', 'Claire Person')
>>> print user_manager.get_user('[email protected]')
None
>>> filebase = switchboard.files[0]
......@@ -245,7 +253,7 @@ confirmation step is completed.
Even if the address being registered has already been verified, the
registration sends a confirmation.
>>> token = registrar.register('[email protected]')
>>> token = registrar.register(mlist, '[email protected]')
>>> token is not None
True
......@@ -256,7 +264,7 @@ Discarding
A confirmation token can also be discarded, say if the user changes his or her
mind about registering. When discarded, no IAddress or IUser is created.
>>> token = registrar.register('[email protected]', 'Elly Person')
>>> token = registrar.register(mlist, '[email protected]', 'Elly Person')
>>> check_token(token)
ok
>>> registrar.discard(token)
......@@ -287,7 +295,7 @@ can be used.
[<Address: Dave Person <[email protected]> [verified] at ...>]
>>> dperson.register('[email protected]', 'David Person')
<Address: David Person <[email protected]> [not verified] at ...>
>>> token = registrar.register('[email protected]')
>>> token = registrar.register(mlist, '[email protected]')
>>> filebase = switchboard.files[0]
>>> qmsg, qdata = switchboard.dequeue(filebase)
>>> switchboard.finish(filebase)
......@@ -335,9 +343,8 @@ Registration and subscription
Fred registers with Mailman at the same time that he subscribes to a mailing
list.
>>> mlist = create_list('[email protected]')
>>> token = registrar.register(
... '[email protected]', 'Fred Person', mlist)
... mlist, '[email protected]', 'Fred Person')
Before confirmation, Fred is not a member of the mailing list.
......
......@@ -42,7 +42,7 @@ class IRegistrar(Interface):
syntax checking, or confirmation, while this interface does.
"""
def register(address, real_name=None, mlist=None):
def register(mlist, address, real_name=None):
"""Register the email address, requesting verification.
No IAddress or IUser is created during this step, but after successful
......@@ -53,9 +53,14 @@ class IRegistrar(Interface):
In all cases, the email address is sanity checked for validity first.
:param address: The textual email address to register.
:param mlist: The mailing list that is the focus of this registration.
:type mlist: `IMailingList`
:param address: The email address to register.
:type address: str
:param real_name: The optional real name of the user.
:type real_name: str
:return: The confirmation token string.
:rtype: str
:raises InvalidEmailAddress: if the address is not allowed.
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment