Skip to content

Commit

Permalink
Handle activation link when signed in to another account
Browse files Browse the repository at this point in the history
  • Loading branch information
seanh committed Feb 3, 2016
1 parent c448513 commit 972c51a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
17 changes: 17 additions & 0 deletions h/accounts/test/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,23 @@ def test_activate_redirects_if_user_already_logged_in():
"Your account has been activated and you're now signed in")


@activate_fixtures
def test_activate_redirects_if_user_already_logged_in_to_different_account():
request = DummyRequest(
matchdict={'id': '123', 'code': 'abc456'},
authenticated_user=mock.Mock(
id=124, # Different user id.
spec=['id']))
request.session.flash = mock_flash_function()

result = RegisterController(request).activate()

assert isinstance(result, httpexceptions.HTTPFound)
assert request.session.flash.call_count == 1
assert request.session.flash.call_args[0][0].startswith(
"You're already signed in to a different account")


@activate_fixtures
def test_activate_looks_up_activation_by_code(activation_model, user_model):
request = DummyRequest(matchdict={'id': '123', 'code': 'abc456'},
Expand Down
13 changes: 10 additions & 3 deletions h/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,15 @@ def activate(self):
self.request.session.flash(jinja2.Markup(_(
"Your account has been activated and you're now signed "
"in!")), 'success')
return httpexceptions.HTTPFound(
location=self.request.route_url('index'))
else:
self.request.session.flash(jinja2.Markup(_(
"You're already signed in to a different account. "
'<a href="{url}">Sign out</a> then try opening the '
'activation link again.').format(
url=self.request.route_url('logout'))),
'error')
return httpexceptions.HTTPFound(
location=self.request.route_url('index'))

activation = Activation.get_by_code(code)
if activation is None:
Expand All @@ -399,7 +406,7 @@ def activate(self):
'If so, try <a href="{url}">signing in</a> using the username '
'and password that you provided.').format(
url=self.request.route_url('login'))),
'success')
'error')
return httpexceptions.HTTPFound(
location=self.request.route_url('index'))

Expand Down

0 comments on commit 972c51a

Please sign in to comment.