Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Add the change-name route #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bguillaumat
Copy link

@bguillaumat bguillaumat commented Jan 21, 2021

logic/auth.js Outdated

changeNameStatus.percent = 100;
} catch (error) {
if (error.response.status === constants.STATUS_CODES.UNAUTHORIZED) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (error.response.status === constants.STATUS_CODES.UNAUTHORIZED) {
if (error.response.status === constants.STATUS_CODES.FORBIDDEN) {

Copy link
Author

Choose a reason for hiding this comment

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

I've seen the same code as you on the previous function and the thing I don't understand is why use the flag forbidden and respond unauthorised = true?
I've done this by "logic" on my reflexion but I can put it back as you mentioned if it's normal

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah you're right.

https://stackoverflow.com/a/6937030

I think we don't need an unauthorised here, because the only error we can get is an fs error (read or write), contrary to the other function which need auth.

Maybe just return Internal server error if something goes wrong?

const newName = req.body.newName;

try {
validator.isString(newName);
Copy link
Contributor

@louneskmt louneskmt Jan 21, 2021

Choose a reason for hiding this comment

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

Maybe we can add other validators, like no special characters?

function isAlphanumeric(string) {

or
function isAlphanumericAndSpaces(string) {

Copy link
Author

Choose a reason for hiding this comment

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

Oh yeah right didn't looked them alpha+space seems a good idea!

Copy link
Contributor

Choose a reason for hiding this comment

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

Then this should also be added later in the file, otherwise a name that works for signup won't work if changed to it.

validator.isString(req.body.name);

Copy link
Member

Choose a reason for hiding this comment

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

If validator.isString(); is all we validate at signup then that's all we should do for name changes too.

Unless there's a specific bug where special characters are causing issues, but that's outside the scope of this PR and should be resolved in a separate PR.

Copy link
Author

Choose a reason for hiding this comment

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

Okok, noted I will update that

logic/auth.js Outdated
Comment on lines 53 to 63
changeNameStatus.percent = 1; // eslint-disable-line no-magic-numbers

changeNameStatus.percent = 40; // eslint-disable-line no-magic-numbers

try {
// get user data
const user = await diskLogic.readUserFile();

// update user name
user.name = name;
Copy link
Contributor

Choose a reason for hiding this comment

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

It won't change a lot of things as it's almost instant, but it seems more logical to me to have the second step (40%) after the file read instead of just after the first step (1%).

Suggested change
changeNameStatus.percent = 1; // eslint-disable-line no-magic-numbers
changeNameStatus.percent = 40; // eslint-disable-line no-magic-numbers
try {
// get user data
const user = await diskLogic.readUserFile();
// update user name
user.name = name;
changeNameStatus.percent = 1; // eslint-disable-line no-magic-numbers
try {
// get user data
const user = await diskLogic.readUserFile();
changeNameStatus.percent = 40; // eslint-disable-line no-magic-numbers
// update user name
user.name = name;

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I guess it's near to instant. In fact just before the try it set 40% for both cases, with your change if it fails we do 1 to 100.
What do you think?

I've used the percentage as the change-password function but since it's not set to an UI animation we can eventually do 1 to 100.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe 1-30-60-100 🧐

It's not really important haha

@AaronDewes
Copy link
Contributor

@bguillaumat Can you rebase this PR?

Verify that name is alphanum+space & remove condition in catch

Remove alphanum+space verification

Update percentage
@bguillaumat
Copy link
Author

@bguillaumat Can you rebase this PR?

Done

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.

None yet

4 participants