Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(desktop): keep desktop context after password change
Browse files Browse the repository at this point in the history
Fixes #812
  • Loading branch information
zaach committed Jun 24, 2014
1 parent 2be3831 commit df187b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/scripts/lib/fxa-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function (FxaClient, $, p, Session, AuthErrors, Constants) {
changePassword: function (originalEmail, oldPassword, newPassword) {
var email = trim(originalEmail);
var self = this;
var sessionTokenContext = Session.sessionTokenContext;
return this._getClientAsync()
.then(function (client) {
return client.passwordChange(email, oldPassword, newPassword);
Expand All @@ -352,6 +353,11 @@ function (FxaClient, $, p, Session, AuthErrors, Constants) {
// Clear old info on password change.
Session.clear();
return self.signIn(email, newPassword);
}).then(function (result) {
// Restore the sessionTokenContext because it indicates if we're
// in a Sync flow or not.
Session.set('sessionTokenContext', sessionTokenContext);
return result;
});
},

Expand Down
17 changes: 15 additions & 2 deletions app/tests/spec/views/change_password.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ define([
'lib/auth-errors',
'views/change_password',
'../../mocks/router',
'../../lib/helpers'
'../../lib/helpers',
'lib/session'
],
function (chai, _, $, AuthErrors, View, RouterMock, TestHelpers) {
function (chai, _, $, AuthErrors, View, RouterMock, TestHelpers, Session) {
var assert = chai.assert;
var wrapAssertion = TestHelpers.wrapAssertion;

Expand Down Expand Up @@ -150,6 +151,18 @@ function (chai, _, $, AuthErrors, View, RouterMock, TestHelpers) {
});
});

it('changes from old to new password, keeps sessionTokenContext', function () {
$('#old_password').val('password');
$('#new_password').val('new_password');

Session.set('sessionTokenContext', 'foo');

return view.submit()
.then(function () {
assert.equal(Session.sessionTokenContext, 'foo');
});
});

it('shows the unverified user message if the user is unverified', function () {
email = 'testuser.' + Math.random() + '@testuser.com';

Expand Down
19 changes: 16 additions & 3 deletions app/tests/spec/views/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ define([
'underscore',
'jquery',
'views/settings',
'../../mocks/router'
'../../mocks/router',
'lib/session',
'lib/constants'
],
function (chai, _, $, View, RouterMock) {
function (chai, _, $, View, RouterMock, Session, Constants) {
var assert = chai.assert;

describe('views/settings', function () {
Expand Down Expand Up @@ -45,7 +47,7 @@ function (chai, _, $, View, RouterMock) {
beforeEach(function () {
email = 'testuser.' + Math.random() + '@testuser.com';

return view.fxaClient.signUp(email, 'password')
return view.fxaClient.signUp(email, 'password', { preVerified: true })
.then(function() {
return view.render();
})
Expand All @@ -66,6 +68,17 @@ function (chai, _, $, View, RouterMock) {
});
});
});

describe('desktop context', function () {
it('does not show sign out link', function () {
Session.set('sessionTokenContext', Constants.FX_DESKTOP_CONTEXT);

return view.render()
.then(function () {
assert.equal(view.$('#signout').length, 0);
});
});
});
});
});
});
Expand Down

0 comments on commit df187b8

Please sign in to comment.