changed so shortChannelId is part of user creds

This commit is contained in:
bill bittner 2017-09-28 16:37:20 -07:00
parent bf17f5a6ec
commit a0d1cb4f5c
4 changed files with 19 additions and 23 deletions

View file

@ -46,20 +46,23 @@ passport.serializeUser((user, done) => {
done(null, user.id); done(null, user.id);
}); });
passport.deserializeUser((id, done) => { // this populates req.user passport.deserializeUser((id, done) => { // this populates req.user
let userInfo = {};
db.User.findOne({ where: { id } }) db.User.findOne({ where: { id } })
.then(user => { .then(user => {
user.getChannel().then(channel => { userInfo['id'] = user.id;
let userInfo = {}; userInfo['userName'] = user.userName;
userInfo['id'] = user.id; return user.getChannel();
userInfo['userName'] = user.userName; })
userInfo['channelName'] = channel.channelName; .then(channel => {
userInfo['channelClaimId'] = channel.channelClaimId; userInfo['channelName'] = channel.channelName;
done(null, userInfo); userInfo['channelClaimId'] = channel.channelClaimId;
}); return db.getShortChannelIdFromLongChannelId(channel.channelClaimId, channel.channelName);
// done(null, user); })
.then(shortChannelId => {
userInfo['shortChannelId'] = shortChannelId;
done(null, userInfo);
return null; return null;
}) })
.then()
.catch(error => { .catch(error => {
logger.error('sequelize error', error); logger.error('sequelize error', error);
done(error, null); done(error, null);
@ -88,6 +91,7 @@ app.use((req, res, next) => {
userName : req.user.userName, userName : req.user.userName,
channelName : req.user.channelName, channelName : req.user.channelName,
channelClaimId: req.user.channelClaimId, channelClaimId: req.user.channelClaimId,
shortChannelId: req.user.shortChannelId,
}; };
} }
next(); next();

View file

@ -1,3 +1,5 @@
<script src="/assets/js/generalFunctions.js"></script>
<div class="row"> <div class="row">
<div class="column column--2"></div> <div class="column column--2"></div>
<div class="column column--8"> <div class="column column--8">
@ -10,7 +12,6 @@
<script src="/socket.io/socket.io.js"></script> <script src="/socket.io/socket.io.js"></script>
<script src="/siofu/client.js"></script> <script src="/siofu/client.js"></script>
<script src="/assets/js/generalFunctions.js"></script>
<script src="/assets/js/validationFunctions.js"></script> <script src="/assets/js/validationFunctions.js"></script>
<script src="/assets/js/publishFileFunctions.js"></script> <script src="/assets/js/publishFileFunctions.js"></script>
<script typ="text/javascript"> <script typ="text/javascript">

View file

@ -59,15 +59,7 @@
} else { } else {
console.log('selected option:', selectedOption); console.log('selected option:', selectedOption);
// retrieve short url from db // retrieve short url from db
getRequest(`/api/shortChannelId/{{{user.channelClaimId}}}/{{{user.channelName}}}`) urlChannel.innerText = `{{user.channelName}}:{{user.shortChannelId}}/`;
.then(result => {
console.log('result', result)
// update url text
urlChannel.innerText = `{{user.channelName}}:${result}/`;
})
.catch(error => {
console.log('error retrieving short channel id', error);
})
} }
} }
} }

View file

@ -5,10 +5,9 @@
<div class="column column--9"> <div class="column column--9">
<div id="input-error-claim-name" class="info-message info-message--failure" hidden="true"></div> <div id="input-error-claim-name" class="info-message info-message--failure" hidden="true"></div>
<div class="input-text--primary"> <div class="input-text--primary">
<span class="url-text">Spee.ch/</span><span id="url-channel" class="url-text">{{#if user.channelName}}{{user.channelName}}/{{/if}}</span><input type="text" id="claim-name-input" class="input-text" placeholder="your-url-here" oninput="checkClaimName(event.target.value)"> <span class="url-text">Spee.ch/</span><span id="url-channel" class="url-text">{{#if user}}{{user.channelName}}:{{user.shortChannelId}}/{{/if}}</span><input type="text" id="claim-name-input" class="input-text" placeholder="your-url-here" oninput="checkClaimName(event.target.value)">
<span id="input-success-claim-name" class="info-message info-message--success"></span> <span id="input-success-claim-name" class="info-message info-message--success"></span>
</div> </div>
</div> </div>
</div> </div>