Skip to content

Commit

Permalink
Merge pull request #4016 from minrk/edituser-validate
Browse files Browse the repository at this point in the history
admin: avoid redundant client-side username validation in edit-user
  • Loading branch information
consideRatio committed Aug 16, 2022
2 parents bb52351 + 8a1110f commit 71e86f3
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions jsx/src/components/EditUser/EditUser.jsx
Expand Up @@ -125,38 +125,12 @@ const EditUser = (props) => {
if (updatedUsername == "" && admin == has_admin) {
noChangeEvent();
return;
} else if (updatedUsername != "") {
if (
updatedUsername.length > 2 &&
/[!@#$%^&*(),.?":{}|<>]/g.test(updatedUsername) == false
) {
editUser(
username,
updatedUsername != "" ? updatedUsername : username,
admin
)
.then((data) => {
data.status < 300
? updateUsers(0, limit)
.then((data) => dispatchPageChange(data, 0))
.then(() => history.push("/"))
.catch(() =>
setErrorAlert(
`Could not update users list.`
)
)
: setErrorAlert(`Failed to edit user.`);
})
.catch(() => {
setErrorAlert(`Failed to edit user.`);
});
} else {
setErrorAlert(
`Failed to edit user. Make sure the username does not contain special characters.`
);
}
} else {
editUser(username, username, admin)
editUser(
username,
updatedUsername != "" ? updatedUsername : username,
admin
)
.then((data) => {
data.status < 300
? updateUsers(0, limit)
Expand Down

0 comments on commit 71e86f3

Please sign in to comment.