From 580c63a1fbe8b2ce13d07098a89a496067959804 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 4 Oct 2017 14:03:19 -0700 Subject: [PATCH] fixed bug letting re-publish to existing channel --- passport/local-signup.js | 2 +- public/assets/css/general.css | 46 ++++++++ public/assets/js/publishFileFunctions.js | 20 +++- public/assets/js/validationFunctions.js | 22 ++-- views/partials/channelCreationForm.handlebars | 6 +- views/partials/publishForm-Channel.handlebars | 108 ++++++++++++------ views/partials/publishForm-Url.handlebars | 7 +- 7 files changed, 157 insertions(+), 54 deletions(-) diff --git a/passport/local-signup.js b/passport/local-signup.js index 23273180..18a854f3 100644 --- a/passport/local-signup.js +++ b/passport/local-signup.js @@ -11,7 +11,7 @@ module.exports = new PassportLocalStrategy( passReqToCallback: true, // we want to be able to read the post body message parameters in the callback }, (req, username, password, done) => { - logger.debug(`new channel signup request: ${username} ${password}`); + logger.debug(`new channel signup request. user: ${username} pass: ${password} .`); let user; // server-side validaton of inputs (username, password) diff --git a/public/assets/css/general.css b/public/assets/css/general.css index c9b0d994..a73e12c7 100644 --- a/public/assets/css/general.css +++ b/public/assets/css/general.css @@ -24,10 +24,56 @@ p { padding:0px; } +.url-text--primary { + color: black; +} + +.url-text--secondary { + color: lightgrey; +} + .pull-quote { font-size: 3rem; } +/* TOOL TIPS */ +/* Tooltip container */ +.tooltip { + position: relative; + display: inline-block; + border-bottom: 1px dotted black; /* If you want dots under the hoverable text */ +} +/* Tooltip text */ +.tooltip > .tooltip-text { + visibility: hidden; + width: 15em; + background-color: dodgerblue; + color: #fff; + text-align: center; + padding: 0.5em; + /* Position the tooltip text */ + position: absolute; + z-index: 1; + bottom: 110%; + left: 50%; + margin-left: -8em; /* Use half of the width (120/2 = 60), to center the tooltip */ +} +/* Show the tooltip text when you mouse over the tooltip container */ +.tooltip:hover > .tooltip-text { + visibility: visible; +} + +.tooltip > .tooltip-text::after { + content: " "; + position: absolute; + top: 100%; /* At the bottom of the tooltip */ + left: 50%; + margin-left: -5px; + border-width: 5px; + border-style: solid; + border-color: dodgerblue transparent transparent transparent; +} + /* LINKS */ a, a:visited { diff --git a/public/assets/js/publishFileFunctions.js b/public/assets/js/publishFileFunctions.js index 1a45b76f..0fe2dc0a 100644 --- a/public/assets/js/publishFileFunctions.js +++ b/public/assets/js/publishFileFunctions.js @@ -50,14 +50,28 @@ function previewAndStageFile(selectedFile){ // Validate the publish submission and then trigger publishing. function publishStagedFile(event) { + // prevent default so this script can handle submission + event.preventDefault(); + // declare variables const claimName = document.getElementById('claim-name-input').value; - const channelName = document.getElementById('channel-name-select').value; + let channelName = document.getElementById('channel-name-select').value; const fileSelectionError = document.getElementById('input-error-file-selection'); const claimNameError = document.getElementById('input-error-claim-name'); const channelSelectError = document.getElementById('input-error-channel-select'); const publishSubmitError = document.getElementById('input-error-publish-submit'); - // prevent default so this script can handle submission - event.preventDefault(); + let anonymousOrInChannel; + // replace channelName with 'anonymous' if needed + const radios = document.getElementsByName('anonymous-or-channel'); + for (let i = 0; i < radios.length; i++) { + if (radios[i].checked) { + // do whatever you want with the checked radio + anonymousOrInChannel = radios[i].value; + // only one radio can be logically checked, don't check the rest + break; + } + } + if (anonymousOrInChannel === 'anonymous') {channelName = 'anonymous'}; + console.log('channel name:', channelName); // validate, submit, and handle response validateFilePublishSubmission(stagedFiles, claimName, channelName) .then(() => { diff --git a/public/assets/js/validationFunctions.js b/public/assets/js/validationFunctions.js index d18c91a4..39c4021b 100644 --- a/public/assets/js/validationFunctions.js +++ b/public/assets/js/validationFunctions.js @@ -131,7 +131,7 @@ function checkAvailability(name, successDisplayElement, errorDisplayElement, val function checkClaimName(name){ const successDisplayElement = document.getElementById('input-success-claim-name'); const errorDisplayElement = document.getElementById('input-error-claim-name'); - checkAvailability(name, successDisplayElement, errorDisplayElement, validateClaimName, isNameAvailable, 'Sorry, that url ending has been taken by another user', '/api/isClaimAvailable/'); + checkAvailability(name, successDisplayElement, errorDisplayElement, validateClaimName, isNameAvailable, 'Sorry, that url ending has been taken', '/api/isClaimAvailable/'); } function checkChannelName(name){ @@ -162,7 +162,7 @@ function validateFilePublishSubmission(stagedFiles, claimName, channelName){ } // 3. validate that a channel was chosen if (channelName === 'new' || channelName === 'login') { - reject(new ChannelNameError("Please select a valid channel")); + reject(new ChannelNameError("Please log in to a channel")); return; }; // 4. validate the claim name @@ -172,7 +172,7 @@ function validateFilePublishSubmission(stagedFiles, claimName, channelName){ reject(error); return; } - // if all validation passes, check availability of the name + // if all validation passes, check availability of the name (note: do we need to re-validate channel name vs. credentials as well?) return isNameAvailable(claimName, '/api/isClaimAvailable/') .then(result => { if (result) { @@ -188,7 +188,8 @@ function validateFilePublishSubmission(stagedFiles, claimName, channelName){ } // validation function which checks all aspects of a new channel submission -function validateNewChannelSubmission(channelName, password){ +function validateNewChannelSubmission(userName, password){ + const channelName = `@${userName}`; return new Promise(function (resolve, reject) { // 1. validate name try { @@ -204,12 +205,17 @@ function validateNewChannelSubmission(channelName, password){ } // 3. if all validation passes, check availability of the name isNameAvailable(channelName, '/api/isChannelAvailable/') // validate the availability - .then(() => { - console.log('channel is available'); - resolve(); + .then(result => { + if (result) { + console.log('channel is available'); + resolve(); + } else { + console.log('channel is not avaliable'); + reject(new ChannelNameError('that channel name has already been taken')); + } }) .catch( error => { - console.log('error: channel is not avaliable'); + console.log('error evaluating channel name availability', error); reject(error); }); }); diff --git a/views/partials/channelCreationForm.handlebars b/views/partials/channelCreationForm.handlebars index afce9838..a3b65c61 100644 --- a/views/partials/channelCreationForm.handlebars +++ b/views/partials/channelCreationForm.handlebars @@ -39,7 +39,7 @@ \ No newline at end of file diff --git a/views/partials/publishForm-Url.handlebars b/views/partials/publishForm-Url.handlebars index afe8ec3e..a5fecf19 100644 --- a/views/partials/publishForm-Url.handlebars +++ b/views/partials/publishForm-Url.handlebars @@ -5,8 +5,11 @@
- Spee.ch/{{#if user}}{{user.channelName}}:{{user.shortChannelId}}/{{/if}} - + {{#if user}} + Spee.ch/{{user.channelName}}:{{user.shortChannelId}}/ + {{else}} + Spee.ch/xyz/ + {{/if}}