fixed channel updates when new channel created from publish

This commit is contained in:
bill bittner 2017-10-10 17:46:26 -07:00
parent c79e033766
commit c65082e610
6 changed files with 72 additions and 50 deletions

View file

@ -12,7 +12,7 @@ module.exports = new PassportLocalStrategy(
}, },
(req, username, password, done) => { (req, username, password, done) => {
logger.debug(`new channel signup request. user: ${username} pass: ${password} .`); logger.debug(`new channel signup request. user: ${username} pass: ${password} .`);
let user; let userInfo = {};
// server-side validaton of inputs (username, password) // server-side validaton of inputs (username, password)
// create the channel and retrieve the metadata // create the channel and retrieve the metadata
@ -41,16 +41,24 @@ module.exports = new PassportLocalStrategy(
return Promise.all([db.User.create(userData), db.Channel.create(channelData), db.Certificate.create(certificateData)]); return Promise.all([db.User.create(userData), db.Channel.create(channelData), db.Certificate.create(certificateData)]);
}) })
.then(([newUser, newChannel, newCertificate]) => { .then(([newUser, newChannel, newCertificate]) => {
user = newUser;
logger.debug('user and certificate successfully created'); logger.debug('user and certificate successfully created');
logger.debug('user result >', newUser.dataValues); logger.debug('user result >', newUser.dataValues);
logger.debug('user result >', newChannel.dataValues); userInfo['id'] = newUser.id;
userInfo['userName'] = newUser.userName;
logger.debug('channel result >', newChannel.dataValues);
userInfo['channelName'] = newChannel.channelName;
userInfo['channelClaimId'] = newChannel.channelClaimId;
logger.debug('certificate result >', newCertificate.dataValues); logger.debug('certificate result >', newCertificate.dataValues);
// associate the instances // associate the instances
return Promise.all([newCertificate.setChannel(newChannel), newChannel.setUser(newUser)]); return Promise.all([newCertificate.setChannel(newChannel), newChannel.setUser(newUser)]);
}).then(() => { })
.then(() => {
logger.debug('user and certificate successfully associated'); logger.debug('user and certificate successfully associated');
return done(null, user); return db.getShortChannelIdFromLongChannelId(userInfo.channelClaimId, userInfo.channelName);
})
.then(shortChannelId => {
userInfo['shortChannelId'] = shortChannelId;
return done(null, userInfo);
}) })
.catch(error => { .catch(error => {
logger.error('signup error', error); logger.error('signup error', error);

View file

@ -0,0 +1,51 @@
function showChannelCreateInProgressDisplay () {
const publishChannelForm = document.getElementById('publish-channel-form');
publishChannelForm.hidden = true;
const inProgress = document.getElementById('channel-publish-in-progress');
inProgress.hidden = false;
createProgressBar(document.getElementById('create-channel-progress-bar'), 12);
}
function showChannelCreateDoneDisplay() {
const inProgress = document.getElementById('channel-publish-in-progress');
inProgress.hidden=true;
const done = document.getElementById('channel-publish-done');
done.hidden = false;
}
function publishNewChannel (event) {
const userName = document.getElementById('new-channel-name').value;
const password = document.getElementById('new-channel-password').value;
// prevent default so this script can handle submission
event.preventDefault();
// validate submission
validateNewChannelSubmission(userName, password)
.then(() => {
console.log('new channel creation is in progress');
showChannelCreateInProgressDisplay();
return sendAuthRequest(userName, password, '/signup') // post the request
})
.then(result => {
console.log('new channel successfully created', result);
showChannelCreateDoneDisplay();
// refresh window logged in as the channel
setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId); // set cookies
})
.then(() => {
// remove old channel and replace with new one & select it
replaceChannelOptionInPublishChannelSelect();
// remove old channel and replace with new one & select it
replaceChannelOptionInNavBarChannelSelect();
})
.catch(error => {
if (error.name === 'ChannelNameError'){
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
showError(channelNameErrorDisplayElement, error.message);
} else if (error.name === 'ChannelPasswordError'){
const passwordErrorDisplayElement = document.getElementById('input-error-channel-password');
showError(passwordErrorDisplayElement, error.message);
} else {
console.log('signup failure:', error);
}
})
}

View file

@ -52,7 +52,6 @@ function loginToChannel (event) {
// update session cookie with new channel name and id's // update session cookie with new channel name and id's
.then(result => { .then(result => {
setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId); // replace the current cookies setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId); // replace the current cookies
return result;
}) })
// update channel selection // update channel selection
.then(() => { .then(() => {

View file

@ -5,7 +5,12 @@ module.exports = (app) => {
// route for sign up // route for sign up
app.post('/signup', passport.authenticate('local-signup'), (req, res) => { app.post('/signup', passport.authenticate('local-signup'), (req, res) => {
logger.debug('successful signup'); logger.debug('successful signup');
res.status(200).json(true); res.status(200).json({
success : true,
channelName : req.user.channelName,
channelClaimId: req.user.channelClaimId,
shortChannelId: req.user.shortChannelId,
});
}); });
// route for log in // route for log in
app.post('/login', passport.authenticate('local-login'), (req, res) => { app.post('/login', passport.authenticate('local-login'), (req, res) => {

View file

@ -25,6 +25,7 @@
<script src="/assets/js/publishFileFunctions.js"></script> <script src="/assets/js/publishFileFunctions.js"></script>
<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/navBarFunctions.js"></script> <script src="/assets/js/navBarFunctions.js"></script>
{{{ body }}} {{{ body }}}
</body> </body>

View file

@ -1,4 +1,3 @@
<form id="publish-channel-form"> <form id="publish-channel-form">
<div class="row row--wide row--short"> <div class="row row--wide row--short">
<div class="column column--3 column--sml-10"> <div class="column column--3 column--sml-10">
@ -35,44 +34,3 @@
<div id="channel-publish-done" hidden="true"> <div id="channel-publish-done" hidden="true">
<p>Your channel has been successfully created!</p> <p>Your channel has been successfully created!</p>
</div> </div>
<script type="text/javascript">
function publishNewChannel (event) {
const userName = document.getElementById('new-channel-name').value;
const password = document.getElementById('new-channel-password').value;
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
const passwordErrorDisplayElement = document.getElementById('input-error-channel-password');
const chanelCreateForm = document.getElementById('publish-channel-form');
const inProgress = document.getElementById('channel-publish-in-progress');
const done = document.getElementById('channel-publish-done');
// prevent default so this script can handle submission
event.preventDefault();
// validate submission
validateNewChannelSubmission(userName, password)
.then(() => {
console.log('in progress');
chanelCreateForm.hidden = true;
inProgress.hidden = false;
createProgressBar(document.getElementById('create-channel-progress-bar'), 12);
return sendAuthRequest(userName, password, '/signup') // post the request
})
.then(() => {
console.log('success');
inProgress.hidden=true;
done.hidden = false;
// refresh window logged in as the channel
window.location.href = '/';
})
.catch(error => {
if (error.name === 'ChannelNameError'){
showError(channelNameErrorDisplayElement, error.message);
} else if (error.name === 'ChannelPasswordError'){
showError(passwordErrorDisplayElement, error.message);
} else {
console.log('failure:', error);
}
})
}
</script>