Client side name validation #99

Merged
bones7242 merged 4 commits from client-side-name-validation into master 2017-07-23 02:23:41 +02:00
bones7242 commented 2017-07-23 01:41:17 +02:00 (Migrated from github.com)
  • Revised some of the client side publish functions to make the flow more clear. Added comments where appropriate
  • Added validation of the file name to check for special characters
  • Added an event listener to the name input box to change spaces to dashes when they are entered
  • Changed the function that auto-fills the name input box so that it replaces spaces with dashes
- Revised some of the client side publish functions to make the flow more clear. Added comments where appropriate - Added validation of the file name to check for special characters - Added an event listener to the name input box to change spaces to dashes when they are entered - Changed the function that auto-fills the name input box so that it replaces spaces with dashes
bones7242 (Migrated from github.com) reviewed 2017-07-23 01:44:43 +02:00
@ -45,2 +34,4 @@
function validateClaimName (name) {
var deferred = new Promise(function(resolve, reject) {
// validate the characters in the 'name' field
if (name.length < 1) {
bones7242 (Migrated from github.com) commented 2017-07-23 01:44:43 +02:00

@98farhan94 This function is used to validate the file on the client side before it is submitted. I added a check to make sure there are no special characters in the file name. Unfortunately, the file.name in the file object is read only so we can't simply replace the spaces. For now we will just prompt the user to fix their file name.

@98farhan94 This function is used to validate the file on the client side before it is submitted. I added a check to make sure there are no special characters in the file name. Unfortunately, the file.name in the file object is read only so we can't simply replace the spaces. For now we will just prompt the user to fix their file name.
bones7242 (Migrated from github.com) reviewed 2017-07-23 01:46:03 +02:00
@ -58,3 +57,4 @@
reject( new NameError("That name has already been claimed by spee.ch. Please choose a different name."));
}
} else {
reject("request to check claim name failed with status:" + this.status);
bones7242 (Migrated from github.com) commented 2017-07-23 01:46:03 +02:00

@98farhan94 note that there are two functions in this file. One to validate the file itself, and one to validate the claim name that the user chooses. The file name can have spaces in it, but the claim name cannot.

@98farhan94 note that there are two functions in this file. One to validate the file itself, and one to validate the claim name that the user chooses. The file name can have spaces in it, but the claim name cannot.
bones7242 (Migrated from github.com) reviewed 2017-07-23 01:46:54 +02:00
@ -103,0 +130,4 @@
function publishSelectedImage(event) {
event.preventDefault();
var name = document.getElementById('publish-name').value;
validateSubmission(stagedFiles, name)
bones7242 (Migrated from github.com) commented 2017-07-23 01:46:54 +02:00

@98farhan94 this function is run when the submit button is clicked to submit the file for publishing.

@98farhan94 this function is run when the submit button is clicked to submit the file for publishing.
bones7242 (Migrated from github.com) reviewed 2017-07-23 01:48:11 +02:00
bones7242 (Migrated from github.com) commented 2017-07-23 01:48:11 +02:00

@98farhan94 this is where the claim-name input box is filled based off of the file name. I added a check here to replace spaces with dashes as you suggested (line 123)

@98farhan94 this is where the claim-name input box is filled based off of the file name. I added a check here to replace spaces with dashes as you suggested (line 123)
bones7242 (Migrated from github.com) reviewed 2017-07-23 01:49:25 +02:00
@ -17,0 +62,4 @@
//event listener to filter claim name inputs
document.getElementById('publish-name').addEventListener('input', function() {
var name = this.value;
this.value = name.replace(/\s+/g, '-');
bones7242 (Migrated from github.com) commented 2017-07-23 01:49:25 +02:00

@98farhan94 I added an event listener to the claim name input box so that if a space is entered it will be changed to a dash. I suppose we could also use this filter to disallow all the other extraneous characters from being inputted.

@98farhan94 I added an event listener to the claim name input box so that if a space is entered it will be changed to a dash. I suppose we could also use this filter to disallow all the other extraneous characters from being inputted.
chickenpie347 (Migrated from github.com) reviewed 2017-07-23 01:56:50 +02:00
chickenpie347 (Migrated from github.com) commented 2017-07-23 01:56:50 +02:00

Thanks - and also for all the comments, they are really helpful!

Thanks - and also for all the comments, they are really helpful!
kauffj (Migrated from github.com) reviewed 2017-07-26 00:49:23 +02:00
@ -47,0 +37,4 @@
if (name.length < 1) {
reject(new NameError("You must enter a name for your claim"));
return;
}
kauffj (Migrated from github.com) commented 2017-07-26 00:49:23 +02:00

Can this just be fixed/stripped rather than erroring?

Can this just be fixed/stripped rather than erroring?
kauffj (Migrated from github.com) reviewed 2017-07-26 00:51:50 +02:00
@ -65,41 +65,87 @@ function validateClaimName (name) {
});
return deferred;
}
// validation function which checks all aspects of the publish submission
kauffj (Migrated from github.com) commented 2017-07-26 00:51:50 +02:00

Might want to consider adopting a validator pattern/standard. Look at validator patterns in a popular JS web framework, for example.

Might want to consider adopting a validator pattern/standard. Look at validator patterns in a popular JS web framework, for example.
bones7242 (Migrated from github.com) reviewed 2017-07-28 06:45:48 +02:00
@ -47,0 +37,4 @@
if (name.length < 1) {
reject(new NameError("You must enter a name for your claim"));
return;
}
bones7242 (Migrated from github.com) commented 2017-07-28 06:45:48 +02:00

Yes, but not easily at the moment. 1. I can't strip or fix it client side because the file name is read only on the file object. I did some snooping on google and stack overflow and it seemed like it was more or less immutable. 2. The solution I imagine is then to rename the file when it is saved on the server. Unfortunately, the socket.io uploader library I am using doesn't have a built in option to rename the file. So, I think to fix would be to rename the file on the server side with the node filesystem tools. I will make an issue to add this.

Yes, but not easily at the moment. 1. I can't strip or fix it client side because the file name is read only on the file object. I did some snooping on google and stack overflow and it seemed like it was more or less immutable. 2. The solution I imagine is then to rename the file when it is saved on the server. Unfortunately, the socket.io uploader library I am using doesn't have a built in option to rename the file. So, I think to fix would be to rename the file on the server side with the node filesystem tools. I will make an issue to add this.
bones7242 (Migrated from github.com) reviewed 2017-07-28 06:46:56 +02:00
@ -65,41 +65,87 @@ function validateClaimName (name) {
});
return deferred;
}
// validation function which checks all aspects of the publish submission
bones7242 (Migrated from github.com) commented 2017-07-28 06:46:56 +02:00

I did a little bit of research on this. There are some validator libraries out there, or at least we can make a more standard pattern that fits our unique needs. Will make an issue.

I did a little bit of research on this. There are some validator libraries out there, or at least we can make a more standard pattern that fits our unique needs. Will make an issue.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: LBRYCommunity/spee.ch#99
No description provided.