Skip to content

Commit

Permalink
Merge pull request #13 from cis3296s24/DevlinSession
Browse files Browse the repository at this point in the history
Session number created
  • Loading branch information
nina-perone authored Apr 3, 2024
2 parents 75e5387 + 7805322 commit 2c10c5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
26 changes: 21 additions & 5 deletions receiptifyv1/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ var generateRandomString = function (length) {
}
return text;
};
var generateSessionID = function () {
var text = '';
var possible =
'0123456789';

for (var i = 0; i < 6; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};

var stateKey = 'spotify_auth_state';

Expand All @@ -88,7 +98,6 @@ app.use((req, res, next) => {
app.get('/login', function (req, res) {
var state = generateRandomString(16);
res.cookie(stateKey, state);

// your application requests authorization
// user-read-private & user-read-email used to get current user info
// user-top-read used to get top track info
Expand All @@ -112,6 +121,11 @@ app.get('/session', function (req, res){
console.log("Connection Attempting to Join Session: " + sessionID)
res.sendFile(__dirname + '/public/session.html', {sessionID: sessionID});
});

//app.get('/login', function (req, res) {
// console.log("it be working");
//});

// how do i find all users currently in the session right now
// instead of making it live, add as we go, but show status of the user.
// when a logging in track spotify user id (user authentication)
Expand Down Expand Up @@ -187,15 +201,17 @@ app.get('/lastfm', function (req, res) {
app.get('/callback', function (req, res) {
// your application requests refresh and access tokens
// after checking the state parameter
sessionIDString = 'sessionID'
console.log(`/callback sessionID: ${req.cookies[sessionIDString]}`);
sessionID = generateSessionID();
sessionIDString = 'sessionID'
if (req.cookies[sessionIDString] != null){
sessionID = req.cookies[sessionIDString];
}
console.log(`/callback sessionID: ` + sessionID);
var code = req.query.code || null;
var state = req.query.state || null;
var storedState = req.cookies ? req.cookies[stateKey] : null;



if (state === null || state !== storedState) {
res.redirect(
'/#' +
Expand Down
2 changes: 1 addition & 1 deletion receiptifyv1/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<div class="header-section">
<div class="row">
<div class="col-12">
<h1>Receiptify - Arianna, Nina, Martin</h1>
<h1>Receiptify - Arianna, Nina, Martin, Devlin</h1>
<h2>Top Track Generator</h2>
</div>
<div class="row flex-center btns">
Expand Down
2 changes: 1 addition & 1 deletion receiptifyv1/views/home.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div id="login">
<h1>Receiptify</h1>
<h2>Top Track Generator</h2>
<a href="/login" class="login-btn">Log in with Spotify</a>
<a href="/login" class="login-btn">Create a session</a>
<a href="/applemusic" class="login-btn apple" id="apple-music-authorize">Log in with Apple Music</a>
<a href="/lastfm" class="login-btn lastfm">Last.fm</a>
<p class="info">
Expand Down

0 comments on commit 2c10c5e

Please sign in to comment.