~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
= Registering email addresses =

Users can have any number of email addresses registered in their Launchpad
accounts, although we'll always communicate with them using their preferred
one. In order to register a new email address users must follow a link sent
by us to the address they want to add and confirm the registration.

Sample Person will now add a couple email addresses to his account.

    >>> from lp.services.mail import stub

    >>> browser = setupBrowser(auth='Basic test@canonical.com:test')
    >>> browser.open('http://launchpad.dev/~name12')
    >>> browser.getLink(url='+editemails').click()
    >>> browser.url
    'http://launchpad.dev/~name12/+editemails'

    >>> browser.getControl('Add a new address').value = 'test2@canonical.com'
    >>> browser.getControl('Add', index=1).click()

    >>> browser.url
    'http://launchpad.dev/%7Ename12/+editemails'
    >>> for msg in get_feedback_messages(browser.contents):
    ...     print msg
    A confirmation message has been sent to...

    >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
    >>> assert not stub.test_emails

Trying to add the same email again (while it's unconfirmed) will only cause
a new email to be sent with a new link. The links in the old and new email are
still accessible and will confirm the new address if/when the user follows
them.

    >>> browser.getControl('Add a new address').value = 'test2@canonical.com'
    >>> browser.getControl('Add', index=1).click()

    >>> browser.url
    'http://launchpad.dev/%7Ename12/+editemails'
    >>> for msg in get_feedback_messages(browser.contents):
    ...     print msg
    A confirmation message has been sent to...

    # Extract the link (from the email we just sent) the user will have to
    # use to finish the registration process.
    >>> from canonical.launchpad.ftests.logintoken import (
    ...     get_token_url_from_email)
    >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
    >>> token_url = get_token_url_from_email(raw_msg)
    >>> token_url
    'http://launchpad.dev/token/...'
    >>> to_addrs
    ['test2@canonical.com']
    >>> assert not stub.test_emails

Follow the token link, to confirm the new email address.

    >>> browser.open(token_url)
    >>> browser.url
    'http://launchpad.dev/token/.../+validateemail'
    >>> browser.getControl('Continue').click()

    >>> browser.url
    'http://launchpad.dev/~name12'
    >>> for msg in get_feedback_messages(browser.contents):
    ...     print msg
    Email address successfully confirmed.

Now that the address is confirmed he sees it in the list of his confirmed
addresses.

    >>> from canonical.launchpad.testing.pages import strip_label

    >>> browser.getLink(url='+editemails').click()
    >>> confirmed = browser.getControl(name="field.VALIDATED_SELECTED")
    >>> [strip_label(option) for option in confirmed.displayOptions]
    ['test@canonical.com', 'test2@canonical.com', 'testing@canonical.com']

If he tries to add it again, he'll get an error message explaining
that it's already registered.

    >>> browser.getControl('Add a new address').value = 'test2@canonical.com'
    >>> browser.getControl('Add', index=1).click()
    >>> browser.url
    'http://launchpad.dev/%7Ename12/+editemails'
    >>> for msg in get_feedback_messages(browser.contents):
    ...     print msg
    There is 1 error.
    The email address 'test2@canonical.com' is already registered as your
    email address...


== Adding a second email address ==

    >>> browser.getControl('Add a new address').value = 'sample@ubuntu.com'
    >>> browser.getControl('Add', index=1).click()

    >>> browser.url
    'http://launchpad.dev/%7Ename12/+editemails'
    >>> for tag in find_tags_by_class(browser.contents, 'message'):
    ...     print tag.renderContents()
    A confirmation message has been sent to...

    # Extract the link (from the email we just sent) the user will have to
    # use to finish the registration process.
    >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
    >>> token_url = get_token_url_from_email(raw_msg)
    >>> token_url
    'http://launchpad.dev/token/...'
    >>> to_addrs
    ['sample@ubuntu.com']
    >>> assert not stub.test_emails

Follow the token link, to confirm the new email address.

    >>> browser.open(token_url)
    >>> browser.url
    'http://launchpad.dev/token/.../+validateemail'
    >>> browser.getControl('Continue').click()

    >>> browser.url
    'http://launchpad.dev/~name12'

    >>> for tag in find_tags_by_class(browser.contents, 'informational'):
    ...     print tag.renderContents()
    Email address successfully confirmed.


== Trying to register an already registered email address ==

Email addresses can not be registered more than once in Launchpad, so if
a given email address is registered by Joe, then Sample Person won't be
able to register it for himself.  When that happens we tell the user the
email is already registered and explain he may want to merge the other
account if that's a duplicate.

    >>> login(ANONYMOUS)
    >>> person = factory.makePerson(email='joe@ubuntu.com')
    >>> person_with_hidden_emails = factory.makePerson(
    ...     email='joe2@ubuntu.com', hide_email_addresses=True)
    >>> logout()
    >>> browser.open('http://launchpad.dev/~name12/+editemails')
    >>> browser.getControl('Add a new address').value = 'joe@ubuntu.com'
    >>> browser.getControl('Add', index=1).click()
    >>> print "\n".join(get_feedback_messages(browser.contents))
    There is 1 error.
    The email address 'joe@ubuntu.com' is already registered...
    If you think that is a duplicated account, you can merge it...

    >>> browser.open('http://launchpad.dev/~name12/+editemails')
    >>> browser.getControl('Add a new address').value = 'joe2@ubuntu.com'
    >>> browser.getControl('Add', index=1).click()
    >>> print "\n".join(get_feedback_messages(browser.contents))
    There is 1 error.
    The email address 'joe2@ubuntu.com' is already registered...
    If you think that is a duplicated account, you can merge it...

If someone tries to add an already registered email address for a team,
a similar error will be shown.

    >>> browser.open(
    ...     'http://launchpad.dev/~landscape-developers/+contactaddress')
    >>> browser.getControl('Another e-mail address').selected = True
    >>> browser.getControl(
    ...     name='field.contact_address').value = 'joe2@ubuntu.com'
    >>> browser.getControl('Change').click()
    >>> print "\n".join(get_feedback_messages(browser.contents))
    There is 1 error.
    joe2@ubuntu.com is already registered in Launchpad...