Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Passwords can now be changed (#687)#694

Merged
dannycoates merged 1 commit intomozilla:masterfrom
himanish-star:feature-change-password
Jan 18, 2018
Merged

Passwords can now be changed (#687)#694
dannycoates merged 1 commit intomozilla:masterfrom
himanish-star:feature-change-password

Conversation

@himanish-star
Copy link
Copy Markdown
Contributor

@himanish-star himanish-star commented Jan 3, 2018

fixes: #687

@ehuggett , Thanks for the help I have added the ability to change password.

However I still face one error and that is as follows

The password does get reset but it fails once with status 401 and then proceeds as per the existing code below. It doesn't affect in any way(as you can see in the gif below that all works well) but still I would like to get rid of this error. Could you suggest how ? At the mean time I am also having a look into this matter

try {
  await sendPassword(file, authKey, rawAuth);
} catch (e) {
  if (e.message === '401' && file.nonce !== e.nonce) {
    await sendPassword(file, authKey, rawAuth);
  } else {
    throw e;
  }
}

simplescreenrecorder-2018-01-03_17 14 13

@himanish-star
Copy link
Copy Markdown
Contributor Author

himanish-star commented Jan 3, 2018

If no password has been set then existingPassword is undefined, this error prevents the password from being set the first time.

Nope this doesn't happen I believe. @ehuggett , you can also see the gif and over there too the password was being set the first time and no error shows. Errors show up only when we try to reset the password. The reset procedure fails once with status 401 and then proceeds with status 200

@ehuggett
Copy link
Copy Markdown
Contributor

ehuggett commented Jan 4, 2018

Nope this doesn't happen I believe. @ehuggett , you can also see the gif(...)

I get the error when using Firefox Developer Edition 58.0b13 (64-bit) & Firefox ESR 52.5.2 (64-bit)
, Your PR does seem to work in chromium version 63.0.3239.84.

note: the 'reset' button is not well formatted in Firefox either

The reset procedure fails once with status 401 and then proceeds with status 200

I see that now. sendPassword was only updating the stored nonce if the request failed, my changes to have it always update the file nonce seem clean enough so I've opened a PR to have you include them in your branch himanish-star#1 (which should cause it to be included here, so you should test it yourself before merging it).

@himanish-star
Copy link
Copy Markdown
Contributor Author

@ehuggett , thanks for the help. This issue has really helped me get a deeper understanding of the mozilla/send code base. So I need to correct the logic of existingPassword, got to format the reset Button and got to merge your branch onto mine. Ok I'm working on it. I'll make these changes later on , as I now got to go to college. If there are any other changes you want me to incorporate please do tell me.

@shikhar-scs
Copy link
Copy Markdown
Contributor

shikhar-scs commented Jan 4, 2018

Also @ehuggett would you mind reviewing these PRs #695 #686 #681 #679.
I have asked @dannycoates too but he seems to be unavailable since a long time.

@dannycoates
Copy link
Copy Markdown
Contributor

@shikhar-scs @himanish-star I appreciate your enthusiasm, but please chill 😉

I will be able to review your PRs soon. I'm the only current maintainer who can merge them.

@himanish-star
Copy link
Copy Markdown
Contributor Author

@dannycoates, sorry for the inconvenience 😅

@shikhar-scs
Copy link
Copy Markdown
Contributor

@dannycoates, yeah Sorry for the inconvenience .

@himanish-star himanish-star force-pushed the feature-change-password branch 2 times, most recently from 9b26f2e to 6173e76 Compare January 5, 2018 00:28
@himanish-star
Copy link
Copy Markdown
Contributor Author

@ehuggett , Now you can have a look at the changes . I have fixed all the bugs and have made the requested changes and I have also merged your branch into my branch

@himanish-star
Copy link
Copy Markdown
Contributor Author

@dannycoates , shall I resolve the conflicts ?

@dannycoates
Copy link
Copy Markdown
Contributor

@himanish-star yes, you can resolve conflicts, but it will probably be a little while longer before this feature gets reviewed / merged.

@himanish-star
Copy link
Copy Markdown
Contributor Author

@dannycoates , ok I will do this in a later part of the day

@himanish-star himanish-star force-pushed the feature-change-password branch from 1daaf82 to abc930c Compare January 14, 2018 14:52
@himanish-star
Copy link
Copy Markdown
Contributor Author

himanish-star commented Jan 14, 2018

@dannycoates , I have fixed the conflicts and things are back to normal.

Here is a GIF with the changes

ezgif com-video-to-gif

Copy link
Copy Markdown
Contributor

@dannycoates dannycoates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good @himanish-star! Thanks for your patience. We might want to make a few little tweaks before pushing to production, but this is almost ready to merge.

await sendPassword(file, oldAuthKey, rawAuth);
} else {
await sendPassword(file, authKey, rawAuth);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit on style... I'd prefer something like:

const aKey = existingPassword ? oldAuthKey : authKey;
await sendPassword(file, aKey, rawAuth);


function toggleResetInput(event) {
const form = event.target.parentElement.querySelector('form');
if (form.style.visibility === 'hidden' || form.style.visibility === '')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another style nit: no ifs without brackets

const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
const nonce = xhr.getResponseHeader('WWW-Authenticate').split(' ')[1];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are cases where this header is not set (status == 404 for example), so would throw an exception here

function resetPassword(event) {
event.preventDefault();
const existingPassword = document.querySelector('.passwordOriginal')
.innerText;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is regarding indentation . Shall I do this

const existingPassword = document.querySelector('.passwordOriginal')
       .innerText;

or this

 const existingPassword = document.querySelector('.passwordOriginal').innerText;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general try to keep it on one line, but our auto-formatter prettier might change it.

if (xhr.status === 200) {
return resolve(xhr.response);
}
if (xhr.status === 401) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to revert this removed code back. If in case the status=401 then the below code would help to reset the file.nonce

if (xhr.status === 401) {
 const nonce = xhr.getResponseHeader('WWW-Authenticate').split(' ')[1];
 file.nonce = nonce;
}

@himanish-star himanish-star force-pushed the feature-change-password branch from abc930c to ef28050 Compare January 17, 2018 01:16
password: '<pre></pre>'
})}</div>`
})}
<button id="resetButton">Reset</button>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this earlier... The "Reset" text here needs to be localized. We need to add a string to public/locales/en-US/send.ftl and use state.translate like the other strings here. I also think "Change" is a better word than "Reset" in this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes , I know that it has to be localised. But I thought I would have to do it in a number of different languages . Thus I had left it alone. I'll make the changes soon.

placeholder="${state.translate('unlockInputPlaceholder')}">
<input type="submit"
id="unlock-reset-btn"
class="btn btn-hidden"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work if you set onclick=${toggleResetInput} here instead of with the querySelector below? If so it's the preferred style. (also same with others)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know that this is the preferred style, but I had tried to do it this way but it hadn't worked. I'll try again and if it doesn't work , I'll ask you for help 😃

Copy link
Copy Markdown
Contributor Author

@himanish-star himanish-star Jan 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope , using onclick=${toggleResetInput} doesn't work 😞. Can you try the same thing out once @dannycoates and I have also made the changes requested

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking @himanish-star. I see the reason it doesn't work... using the function form "html()" processes the string differently than the template string form "html``". We need to use the function form here so that the password text gets escaped properly. It's not a big deal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use the function form here so that the password text gets escaped properly. It's not a big deal.

So you mean we can still write onclick=${toggleResetInput}. Ok, I'll try searching more over the net of how to do this. Meanwhile if you can suggest me of how this is done, then I will surely rectify my mistake

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no, I was just commenting on why we needed to use html() instead of html``

Your code is fine :)

@dannycoates
Copy link
Copy Markdown
Contributor

Nice work @himanish-star! 💯

@dannycoates dannycoates merged commit 9688dde into mozilla:master Jan 18, 2018
@himanish-star
Copy link
Copy Markdown
Contributor Author

@dannycoates , Thank for merging. Can I take up issue #324 ? 😃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: An ability to change password

4 participants