From 8228e5bd12b85da26fee04619588f80165a9ea4b Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 24 Jan 2018 09:27:36 -0800 Subject: [PATCH] removed cookies from front end --- public/assets/js/createChannelFunctions.js | 1 - public/assets/js/generalFunctions.js | 45 --------------------- public/assets/js/loginFunctions.js | 2 - public/assets/js/navBarFunctions.js | 15 ------- react/containers/ChannelCreateForm/view.jsx | 4 +- react/containers/ChannelLoginForm/view.jsx | 2 - react/containers/NavBar/view.jsx | 1 - react/utils/cookies.js | 44 -------------------- views/layouts/channel.handlebars | 1 - views/layouts/main.handlebars | 1 - views/layouts/show.handlebars | 1 - views/partials/navBar.handlebars | 27 ++++++++++--- 12 files changed, 22 insertions(+), 122 deletions(-) delete mode 100644 public/assets/js/navBarFunctions.js delete mode 100644 react/utils/cookies.js diff --git a/public/assets/js/createChannelFunctions.js b/public/assets/js/createChannelFunctions.js index 9c9ae9a7..19205327 100644 --- a/public/assets/js/createChannelFunctions.js +++ b/public/assets/js/createChannelFunctions.js @@ -31,7 +31,6 @@ function publishNewChannel (event) { return sendAuthRequest(userName, password, '/signup') // post the request }) .then(result => { - setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId); showChannelCreateDoneDisplay(); window.location = '/'; }) diff --git a/public/assets/js/generalFunctions.js b/public/assets/js/generalFunctions.js index c82022af..89cc239a 100644 --- a/public/assets/js/generalFunctions.js +++ b/public/assets/js/generalFunctions.js @@ -96,51 +96,6 @@ function createProgressBar(element, size){ setInterval(updateOneBar, 300); } -function setCookie(key, value) { - document.cookie = `${key}=${value}`; -} - -function getCookie(cname) { - const name = cname + "="; - const decodedCookie = decodeURIComponent(document.cookie); - const ca = decodedCookie.split(';'); - for(let i = 0; i { - setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId); - // if user is on the home page, update the needed elements without reloading window.location = '/'; }) .catch(error => { diff --git a/public/assets/js/navBarFunctions.js b/public/assets/js/navBarFunctions.js deleted file mode 100644 index 84d483ac..00000000 --- a/public/assets/js/navBarFunctions.js +++ /dev/null @@ -1,15 +0,0 @@ -function toggleNavBarSelection (value) { - const selectedOption = value; - if (selectedOption === 'LOGOUT') { - // remove session cookies - clearUserCookies(); - // send logout request to server - window.location.href = '/logout'; - } else if (selectedOption === 'VIEW') { - // get channel info - const channelName = getCookie('CHANNEL_NAME'); - const channelClaimId = getCookie('CHANNEL_LONG_ID'); - // redirect to channel page - window.location.href = `/${channelName}:${channelClaimId}`; - } -} diff --git a/react/containers/ChannelCreateForm/view.jsx b/react/containers/ChannelCreateForm/view.jsx index 44a1041b..4d26562c 100644 --- a/react/containers/ChannelCreateForm/view.jsx +++ b/react/containers/ChannelCreateForm/view.jsx @@ -1,7 +1,6 @@ import React from 'react'; import ProgressBar from 'components/ProgressBar'; import { makeGetRequest, makePostRequest } from 'utils/xhr'; -import { setUserCookies } from 'utils/cookies'; class ChannelCreateForm extends React.Component { constructor (props) { @@ -44,7 +43,7 @@ class ChannelCreateForm extends React.Component { } updateIsChannelAvailable (channel) { const that = this; - const channelWithAtSymbol = `@${channel}` + const channelWithAtSymbol = `@${channel}`; makeGetRequest(`/api/channel-is-available/${channelWithAtSymbol}`) .then(isAvailable => { if (isAvailable) { @@ -111,7 +110,6 @@ class ChannelCreateForm extends React.Component { }) .then(result => { that.setState({status: null}); - setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId); that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId); }) .catch((error) => { diff --git a/react/containers/ChannelLoginForm/view.jsx b/react/containers/ChannelLoginForm/view.jsx index a6d5e3c1..f1b6b69e 100644 --- a/react/containers/ChannelLoginForm/view.jsx +++ b/react/containers/ChannelLoginForm/view.jsx @@ -1,6 +1,5 @@ import React from 'react'; import { makePostRequest } from 'utils/xhr'; -import { setUserCookies } from 'utils/cookies'; class ChannelLoginForm extends React.Component { constructor (props) { @@ -25,7 +24,6 @@ class ChannelLoginForm extends React.Component { const that = this; makePostRequest(url, params) .then(result => { - setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId); that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId); }) .catch(error => { diff --git a/react/containers/NavBar/view.jsx b/react/containers/NavBar/view.jsx index 37457022..93be60a8 100644 --- a/react/containers/NavBar/view.jsx +++ b/react/containers/NavBar/view.jsx @@ -1,5 +1,4 @@ import React from 'react'; -import { clearUserCookies } from 'utils/cookies'; import { authenticateUser } from 'utils/auth'; import Logo from 'components/Logo'; import NavBarChannelDropdown from 'components/NavBarChannelDropdown'; diff --git a/react/utils/cookies.js b/react/utils/cookies.js deleted file mode 100644 index 135347be..00000000 --- a/react/utils/cookies.js +++ /dev/null @@ -1,44 +0,0 @@ -const CHANNEL_NAME = 'CHANNEL_NAME'; -const CHANNEL_SHORT_ID = 'CHANNEL_SHORT_ID'; -const CHANNEL_LONG_ID = 'CHANNEL_LONG_ID'; - -module.exports = { - setCookie (key, value) { - document.cookie = `${key}=${value}`; - }, - getCookie (cname) { - const name = cname + '='; - const decodedCookie = decodeURIComponent(document.cookie); - const ca = decodedCookie.split(';'); - for (let i = 0; i < ca.length; i++) { - let c = ca[i]; - while (c.charAt(0) === ' ') { - c = c.substring(1); - } - if (c.indexOf(name) === 0) { - return c.substring(name.length, c.length); - } - } - return ''; - }, - clearCookie (name) { - document.cookie = `${name}=; expires=Thu, 01-Jan-1970 00:00:01 GMT;`; - }, - setUserCookies (channelName, shortChannelId, channelClaimId) { - module.exports.setCookie('CHANNEL_NAME', channelName); - module.exports.setCookie('CHANNEL_SHORT_ID', shortChannelId); - module.exports.setCookie('CHANNEL_LONG_ID', channelClaimId); - }, - clearUserCookies () { - module.exports.clearCookie('CHANNEL_NAME'); - module.exports.clearCookie('CHANNEL_SHORT_ID'); - module.exports.clearCookie('CHANNEL_LONG_ID'); - }, - getUserCookies () { - return { - channelName : module.exports.getCookie('CHANNEL_NAME'), - channelShortId: module.exports.getCookie('CHANNEL_SHORT_ID'), - channelLongId : module.exports.getCookie('CHANNEL_LONG_ID'), - }; - }, -}; diff --git a/views/layouts/channel.handlebars b/views/layouts/channel.handlebars index 0021e325..18a41951 100644 --- a/views/layouts/channel.handlebars +++ b/views/layouts/channel.handlebars @@ -17,7 +17,6 @@ - {{{ body }}} diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index 41371bb4..9eb4cd4b 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -21,7 +21,6 @@ - {{{ body }}} diff --git a/views/layouts/show.handlebars b/views/layouts/show.handlebars index 6a47413e..8ba33271 100644 --- a/views/layouts/show.handlebars +++ b/views/layouts/show.handlebars @@ -14,7 +14,6 @@ - {{{ body }}} diff --git a/views/partials/navBar.handlebars b/views/partials/navBar.handlebars index e4d2dad6..0eba0c80 100644 --- a/views/partials/navBar.handlebars +++ b/views/partials/navBar.handlebars @@ -27,12 +27,15 @@ Publish About - - Channel + {{#if user }} + + {{else}} + Channel + {{/if}} @@ -48,4 +51,16 @@ link.setAttribute('class', 'select select--arrow link--nav-active'); } } + // function to send user to their channel if selected + function toggleNavBarSelection (event) { + console.log('toggleNavBarSelection event', event); + const selectedOption = event.target.selectedOptions[0].value; + if (selectedOption === 'LOGOUT') { + // send logout request to server + window.location.href = '/logout'; + } else if (selectedOption === 'VIEW') { + // redirect to channel page + window.location.href = event.target.selectedOptions[0].dataset.channelUrl; + } + }