removed cookies from front end
This commit is contained in:
parent
c2bb1d600f
commit
8228e5bd12
12 changed files with 22 additions and 122 deletions
|
@ -31,7 +31,6 @@ function publishNewChannel (event) {
|
||||||
return sendAuthRequest(userName, password, '/signup') // post the request
|
return sendAuthRequest(userName, password, '/signup') // post the request
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId);
|
|
||||||
showChannelCreateDoneDisplay();
|
showChannelCreateDoneDisplay();
|
||||||
window.location = '/';
|
window.location = '/';
|
||||||
})
|
})
|
||||||
|
|
|
@ -96,51 +96,6 @@ function createProgressBar(element, size){
|
||||||
setInterval(updateOneBar, 300);
|
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 <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 "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkCookie() {
|
|
||||||
const channelName = getCookie("channel_name");
|
|
||||||
if (channelName != "") {
|
|
||||||
console.log(`cookie found for ${channelName}`);
|
|
||||||
} else {
|
|
||||||
console.log('no channel_name cookie found');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearCookie(name) {
|
|
||||||
document.cookie = `${name}=; expires=Thu, 01-Jan-1970 00:00:01 GMT;`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUserCookies(channelName, shortChannelId, channelClaimId) {
|
|
||||||
setCookie('CHANNEL_NAME', channelName)
|
|
||||||
setCookie('CHANNEL_SHORT_ID', shortChannelId);
|
|
||||||
setCookie('CHANNEL_LONG_ID', channelClaimId);
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearUserCookies() {
|
|
||||||
clearCookie('CHANNEL_NAME')
|
|
||||||
clearCookie('CHANNEL_SHORT_ID');
|
|
||||||
clearCookie('CHANNEL_LONG_ID');
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyToClipboard(event){
|
function copyToClipboard(event){
|
||||||
var elementToCopy = event.target.dataset.elementtocopy;
|
var elementToCopy = event.target.dataset.elementtocopy;
|
||||||
var element = document.getElementById(elementToCopy);
|
var element = document.getElementById(elementToCopy);
|
||||||
|
|
|
@ -8,8 +8,6 @@ function loginToChannel (event) {
|
||||||
return sendAuthRequest(userName, password, '/login')
|
return sendAuthRequest(userName, password, '/login')
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId);
|
|
||||||
// if user is on the home page, update the needed elements without reloading
|
|
||||||
window.location = '/';
|
window.location = '/';
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -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}`;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ProgressBar from 'components/ProgressBar';
|
import ProgressBar from 'components/ProgressBar';
|
||||||
import { makeGetRequest, makePostRequest } from 'utils/xhr';
|
import { makeGetRequest, makePostRequest } from 'utils/xhr';
|
||||||
import { setUserCookies } from 'utils/cookies';
|
|
||||||
|
|
||||||
class ChannelCreateForm extends React.Component {
|
class ChannelCreateForm extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
|
@ -44,7 +43,7 @@ class ChannelCreateForm extends React.Component {
|
||||||
}
|
}
|
||||||
updateIsChannelAvailable (channel) {
|
updateIsChannelAvailable (channel) {
|
||||||
const that = this;
|
const that = this;
|
||||||
const channelWithAtSymbol = `@${channel}`
|
const channelWithAtSymbol = `@${channel}`;
|
||||||
makeGetRequest(`/api/channel-is-available/${channelWithAtSymbol}`)
|
makeGetRequest(`/api/channel-is-available/${channelWithAtSymbol}`)
|
||||||
.then(isAvailable => {
|
.then(isAvailable => {
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
|
@ -111,7 +110,6 @@ class ChannelCreateForm extends React.Component {
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
that.setState({status: null});
|
that.setState({status: null});
|
||||||
setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId);
|
|
||||||
that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { makePostRequest } from 'utils/xhr';
|
import { makePostRequest } from 'utils/xhr';
|
||||||
import { setUserCookies } from 'utils/cookies';
|
|
||||||
|
|
||||||
class ChannelLoginForm extends React.Component {
|
class ChannelLoginForm extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
|
@ -25,7 +24,6 @@ class ChannelLoginForm extends React.Component {
|
||||||
const that = this;
|
const that = this;
|
||||||
makePostRequest(url, params)
|
makePostRequest(url, params)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId);
|
|
||||||
that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { clearUserCookies } from 'utils/cookies';
|
|
||||||
import { authenticateUser } from 'utils/auth';
|
import { authenticateUser } from 'utils/auth';
|
||||||
import Logo from 'components/Logo';
|
import Logo from 'components/Logo';
|
||||||
import NavBarChannelDropdown from 'components/NavBarChannelDropdown';
|
import NavBarChannelDropdown from 'components/NavBarChannelDropdown';
|
||||||
|
|
|
@ -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'),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -17,7 +17,6 @@
|
||||||
</head>
|
</head>
|
||||||
<body id="channel-body">
|
<body id="channel-body">
|
||||||
<script src="/assets/js/generalFunctions.js"></script>
|
<script src="/assets/js/generalFunctions.js"></script>
|
||||||
<script src="/assets/js/navBarFunctions.js"></script>
|
|
||||||
{{{ body }}}
|
{{{ body }}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
<script src="/assets/js/authFunctions.js"></script>
|
<script src="/assets/js/authFunctions.js"></script>
|
||||||
<script src="/assets/js/loginFunctions.js"></script>
|
<script src="/assets/js/loginFunctions.js"></script>
|
||||||
<script src="/assets/js/createChannelFunctions.js"></script>
|
<script src="/assets/js/createChannelFunctions.js"></script>
|
||||||
<script src="/assets/js/navBarFunctions.js"></script>
|
|
||||||
{{{ body }}}
|
{{{ body }}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
</head>
|
</head>
|
||||||
<body id="show-body">
|
<body id="show-body">
|
||||||
<script src="/assets/js/generalFunctions.js"></script>
|
<script src="/assets/js/generalFunctions.js"></script>
|
||||||
<script src="/assets/js/navBarFunctions.js"></script>
|
|
||||||
<script src="/assets/js/assetConstructor.js"></script>
|
<script src="/assets/js/assetConstructor.js"></script>
|
||||||
{{{ body }}}
|
{{{ body }}}
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -27,12 +27,15 @@
|
||||||
<a class="nav-bar-link link--nav" href="/">Publish</a>
|
<a class="nav-bar-link link--nav" href="/">Publish</a>
|
||||||
<!--<a class="nav-bar-link link--nav" href="/popular">Popular</a>-->
|
<!--<a class="nav-bar-link link--nav" href="/popular">Popular</a>-->
|
||||||
<a class="nav-bar-link link--nav" href="/about">About</a>
|
<a class="nav-bar-link link--nav" href="/about">About</a>
|
||||||
<select type="text" id="nav-bar-channel-select" class="select select--arrow link--nav" onchange="toggleNavBarSelection(event.target.selectedOptions[0].value)" {{#unless user}}style="display:none"{{/unless}}>
|
{{#if user }}
|
||||||
<option id="nav-bar-channel-select-channel-option">@{{user.userName}}</option>
|
<select type="text" id="nav-bar-channel-select" class="select select--arrow link--nav" onchange="toggleNavBarSelection(event)">
|
||||||
<option value="VIEW">View</option>
|
<option id="nav-bar-channel-select-channel-option" >{{user.channelName}}</option>
|
||||||
<option value="LOGOUT">Logout</option>
|
<option value="VIEW" data-channelUrl="/{{user.channelName}}:{{user.channelClaimId}}">View</option>
|
||||||
</select>
|
<option value="LOGOUT">Logout</option>
|
||||||
<a id="nav-bar-login-link" class="nav-bar-link link--nav" href="/login" {{#if user}}style="display:none"{{/if}}>Channel</a>
|
</select>
|
||||||
|
{{else}}
|
||||||
|
<a id="nav-bar-login-link" class="nav-bar-link link--nav" href="/login">Channel</a>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -48,4 +51,16 @@
|
||||||
link.setAttribute('class', 'select select--arrow link--nav-active');
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue