From 84c525dcc09e13de7e1459da1c504667fa2b4ec0 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 25 Sep 2017 22:49:27 -0700 Subject: [PATCH] fixed view for Channel and User tables --- helpers/lbryApi.js | 8 ++++---- models/user.js | 2 +- passport/local-login.js | 2 -- passport/local-signup.js | 15 +++++---------- speech.js | 13 +++++++++++-- views/partials/channelCreation.handlebars | 2 +- views/partials/channelLogin.handlebars | 2 +- views/partials/publishChannel.handlebars | 2 +- views/partials/topBar.handlebars | 2 +- 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/helpers/lbryApi.js b/helpers/lbryApi.js index 2b9c1fba..df101b55 100644 --- a/helpers/lbryApi.js +++ b/helpers/lbryApi.js @@ -122,7 +122,7 @@ module.exports = { }); }); }, - createChannel (name, claimAddress) { + createChannel (name) { return new Promise((resolve, reject) => { axios .post('http://localhost:5279/lbryapi', { @@ -135,9 +135,9 @@ module.exports = { .then(response => { handleResponse(response, resolve, reject); }) - .catch(error => { - reject(error); - }); + .catch(error => { + reject(error); + }); }); }, }; diff --git a/models/user.js b/models/user.js index 56f71002..bce93d91 100644 --- a/models/user.js +++ b/models/user.js @@ -17,7 +17,7 @@ module.exports = (sequelize, { STRING }) => { ); User.associate = db => { - User.hasOne(db.Certificate); + User.hasOne(db.Channel); }; User.prototype.validPassword = (givenpassword, thispassword) => { diff --git a/passport/local-login.js b/passport/local-login.js index bc03eda3..5ccb822c 100644 --- a/passport/local-login.js +++ b/passport/local-login.js @@ -24,8 +24,6 @@ module.exports = new PassportLocalStrategy( } logger.debug('user found:', user.dataValues); return user.getChannel().then(channel => { - user['channelName'] = channel.channelClaimId; - user['channelClaimId'] = channel.channelClaimId; return done(null, user); }); }) diff --git a/passport/local-signup.js b/passport/local-signup.js index 0158f715..23273180 100644 --- a/passport/local-signup.js +++ b/passport/local-signup.js @@ -2,7 +2,6 @@ const db = require('../models'); const PassportLocalStrategy = require('passport-local').Strategy; const lbryApi = require('../helpers/lbryApi.js'); const logger = require('winston'); -const config = require('config'); module.exports = new PassportLocalStrategy( { @@ -12,13 +11,12 @@ 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'); - const address = config.get('WalletConfig.LbryClaimAddress'); + logger.debug(`new channel signup request: ${username} ${password}`); let user; // server-side validaton of inputs (username, password) // create the channel and retrieve the metadata - return lbryApi.createChannel(username, address) + return lbryApi.createChannel(`@${username}`) .then(tx => { // create user record const userData = { @@ -35,7 +33,7 @@ module.exports = new PassportLocalStrategy( // create certificate record const certificateData = { claimId: tx.claim_id, - name : username, + name : `@${username}`, // address, }; logger.debug('certificateData >', certificateData); @@ -43,9 +41,7 @@ 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; // save outside scope of this function - user['channelName'] = newChannel.channelClaimId; - user['channelClaimId'] = newChannel.channelClaimId; + user = newUser; logger.debug('user and certificate successfully created'); logger.debug('user result >', newUser.dataValues); logger.debug('user result >', newChannel.dataValues); @@ -54,11 +50,10 @@ module.exports = new PassportLocalStrategy( return Promise.all([newCertificate.setChannel(newChannel), newChannel.setUser(newUser)]); }).then(() => { logger.debug('user and certificate successfully associated'); - logger.debug('user ===', user.dataValues); return done(null, user); }) .catch(error => { - logger.debug(error); + logger.error('signup error', error); return done(error); }); } diff --git a/speech.js b/speech.js index 24667437..500f2132 100644 --- a/speech.js +++ b/speech.js @@ -45,10 +45,18 @@ app.use(passport.session()); passport.serializeUser((user, done) => { done(null, user.id); }); -passport.deserializeUser((id, done) => { +passport.deserializeUser((id, done) => { // this populates req.user db.User.findOne({ where: { id } }) .then(user => { - done(null, user); + user.getChannel().then(channel => { + let userInfo = {}; + userInfo['id'] = user.id; + userInfo['userName'] = user.userName; + userInfo['channelName'] = channel.channelName; + userInfo['channelClaimId'] = channel.channelClaimId; + done(null, userInfo); + }); + // done(null, user); return null; }) .then() @@ -74,6 +82,7 @@ app.set('view engine', 'handlebars'); // middleware to pass user info back to client (for handlebars access), if user is logged in app.use((req, res, next) => { if (req.user) { + logger.verbose(req.user); res.locals.user = { id : req.user.id, userName : req.user.userName, diff --git a/views/partials/channelCreation.handlebars b/views/partials/channelCreation.handlebars index e0f3c692..1f538a7f 100644 --- a/views/partials/channelCreation.handlebars +++ b/views/partials/channelCreation.handlebars @@ -19,7 +19,7 @@