diff --git a/passport/local-signup.js b/passport/local-signup.js
index 18a854f3..d72a95f6 100644
--- a/passport/local-signup.js
+++ b/passport/local-signup.js
@@ -12,7 +12,7 @@ module.exports = new PassportLocalStrategy(
},
(req, username, password, done) => {
logger.debug(`new channel signup request. user: ${username} pass: ${password} .`);
- let user;
+ let userInfo = {};
// server-side validaton of inputs (username, password)
// 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)]);
})
.then(([newUser, newChannel, newCertificate]) => {
- user = newUser;
logger.debug('user and certificate successfully created');
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);
// associate the instances
return Promise.all([newCertificate.setChannel(newChannel), newChannel.setUser(newUser)]);
- }).then(() => {
+ })
+ .then(() => {
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 => {
logger.error('signup error', error);
diff --git a/public/assets/js/createChannelFunctions.js b/public/assets/js/createChannelFunctions.js
new file mode 100644
index 00000000..94933506
--- /dev/null
+++ b/public/assets/js/createChannelFunctions.js
@@ -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);
+ }
+ })
+}
\ No newline at end of file
diff --git a/public/assets/js/loginFunctions.js b/public/assets/js/loginFunctions.js
index 6405221b..ff66056c 100644
--- a/public/assets/js/loginFunctions.js
+++ b/public/assets/js/loginFunctions.js
@@ -52,7 +52,6 @@ function loginToChannel (event) {
// update session cookie with new channel name and id's
.then(result => {
setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId); // replace the current cookies
- return result;
})
// update channel selection
.then(() => {
diff --git a/routes/auth-routes.js b/routes/auth-routes.js
index 1f9f6cff..8350c0e0 100644
--- a/routes/auth-routes.js
+++ b/routes/auth-routes.js
@@ -5,7 +5,12 @@ module.exports = (app) => {
// route for sign up
app.post('/signup', passport.authenticate('local-signup'), (req, res) => {
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
app.post('/login', passport.authenticate('local-login'), (req, res) => {
diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars
index 87f470c1..300e480b 100644
--- a/views/layouts/main.handlebars
+++ b/views/layouts/main.handlebars
@@ -25,6 +25,7 @@
+
{{{ body }}}