diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4eecc8ee..febfdd6d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,15 +1,15 @@ -**Deliverable Submission** - -Please describe your comfort and completeness levels before submitting. Comfort Level (1-5): - -Completeness Level (1-5): - -How many hours did you spend on this assignment? - -What part did you spend the most time on? - -Does the assignment run without errors? If the assignment has errors, what are they? - -Describe one part of the code or choose one line you would improve upon. What would you improve? - -What did you think of this deliverable? Any other comments? +**Deliverable Submission** + +Please describe your comfort and completeness levels before submitting. Comfort Level (1-5): + +Completeness Level (1-5): + +How many hours did you spend on this assignment? + +What part did you spend the most time on? + +Does the assignment run without errors? If the assignment has errors, what are they? + +Describe one part of the code or choose one line you would improve upon. What would you improve? + +What did you think of this deliverable? Any other comments? diff --git a/index.js b/index.js index c5a34e0a..4d585a34 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,11 @@ console.log("starting up!!"); const express = require('express'); const methodOverride = require('method-override'); const pg = require('pg'); +var sha256 = require('js-sha256'); // Initialise postgres client const configs = { - user: 'YOURUSERNAME', + user: 'Vignesh', host: '127.0.0.1', database: 'tunr_db', port: 5432, @@ -23,7 +24,7 @@ pool.on('error', function (err) { * Configurations and set up * =================================== */ - +const cookieParser = require('cookie-parser') // Init express app const app = express(); @@ -33,6 +34,8 @@ app.use(express.urlencoded({ extended: true })); +app.use(cookieParser()); + app.use(methodOverride('_method')); @@ -42,24 +45,339 @@ app.set('views', __dirname + '/views'); app.set('view engine', 'jsx'); app.engine('jsx', reactEngine); + + /** * =================================== - * Routes + * Create feature * =================================== */ -app.get('/', (request, response) => { - // query database for all pokemon +app.get('/new', (request, response) => { + response.render('new'); +}); + +app.post('/new', (request, response) => { + console.log("this", request.body); + + const artistAddQuery = (queryError, result) => { + if(queryError){ + console.log("Error found!"); + console.log(queryError); + }else{ + console.log(result); + response.render('new') + } + } + const queryString = "INSERT INTO artists (name,photo_url,nationality) VALUES ($1,$2,$3) RETURNING *"; + const insertValues = [request.body.artistName,request.body.photoUrl,request.body.nationality]; + + pool.query(queryString, insertValues, artistAddQuery ) - // respond with HTML page displaying all pokemon - response.render('home'); }); -app.get('/new', (request, response) => { +/** + * =================================== + * Artists index feature + * =================================== + */ + +app.get('/artists', (request, response) => { // respond with HTML page with form to create new pokemon + const artistQuery = ( error, result) => { + if ( error ){ + console.log("An Errorr!!") + }else{ + const data ={ + artistNames: result.rows + } + response.render('index', data) + //response.send(result.rows[0].name); + } + } + const queryString = "SELECT * FROM artists;" + pool.query(queryString, artistQuery ) +}); + +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/**********PART 2*************************************/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ +/*===================================================*/ + +/** + * =================================== + * Tracklist feature + * =================================== + */ + +//Display the list of songs and artists +// app.get('/playlist/new', (request, response) => { +// response.send("NEW list"); +// }); + +app.get('/playlist', (request, response) => { + console.log("this", request.body); + + const trackListQuery = (trackQueryError, result) => { + if(trackQueryError){ + console.log("Error found!"); + console.log(trackQueryError); + }else{ + const data = { + tracks: result.rows + } + response.render('tracks', data) + } + } + const queryString = "SELECT songs.title, songs.album, artists.name FROM songs INNER JOIN artists ON songs.artist_id = artists.id" + + pool.query(queryString, trackListQuery ) + +}); + +/** + * =================================== + * Playlist id feature + * =================================== + */ + +app.get('/playlist/:id', (request, response) => { + //console.log("this", request.body); + + const queryString = "SELECT songs.title, songs.album, artists.name FROM songs INNER JOIN artists ON (songs.artist_id = artists.id) WHERE artists.id = " + request.params.id ; + + const playListQuery = (playListQueryError, result) => { + if(playListQueryError){ + console.log("Error found!"); + console.log(playListQueryError); + }else{ + response.send(result.rows) + response.render('songsByArtist') + + } + } + pool.query(queryString, playListQuery ) + +}); + + +/** + * =================================== + * Create New Playlist feature + * =================================== + */ + + +app.get('/newPlaylist', (request, response) => { response.render('new'); }); +app.post('/newPlaylist', (request, response) => { + console.log("this", request.body); + + const artistAddQuery = (queryError, result) => { + if(queryError){ + console.log("Error found!"); + console.log(queryError); + }else{ + console.log(result); + } + } + const queryString = ""; + const insertValues = [request.body.artistName,request.body.photoUrl,request.body.nationality]; + + pool.query(queryString, insertValues, artistAddQuery ) + +}); + +/** + * =================================== + * Create Favorites feature + * =================================== + */ + + app.get('/newPlaylist', (request, response) => { + response.render('new'); +}); + +app.post('/newPlaylist', (request, response) => { + console.log("this", request.body); + + const artistAddQuery = (queryError, result) => { + if(queryError){ + console.log("Error found!"); + console.log(queryError); + }else{ + console.log(result); + } + } + const queryString = ""; + const insertValues = [request.body.artistName,request.body.photoUrl,request.body.nationality]; + + pool.query(queryString, insertValues, artistAddQuery ) + +}); + + + + + + + +/** + * =================================== + * Create Registration feature + * =================================== + */ + +///// create a row in the users table + +app.get('/', (request, response) => { + response.render('home'); +}); + +///// registration +// app.get('/users/new', (request, response) => { +app.get('/register', (request, response) => { + + // send response with some data (a string) + response.render('register'); +}); + +app.post('/register', (request, response) => { + console.log(request.body) + + // TODO : check to make sure that the name is unique in the db: + // SELECT * FROM users WHERE name=request.body.name + //let getUserQuery = "SELECT * FROM users WHERE name=request.body.name"; + // send response with some data (a string) + //response.send("WORKSS"); + let registerQuery = "INSERT INTO users (name, password) VALUES ($1, $2)"; + + var hashedPassword = sha256(request.body.password); + + const values = [request.body.name, hashedPassword]; + console.log(request.body.name); + console.log(hashedPassword); + + pool.query(registerQuery, values, (error, result)=>{ + if( error ){ + console.log("ERRRRRRRRRROR"); + console.log(error); + } + response.cookie('logged in', 'true'); + console.log("YAAAYYYYY"); + + }) + +}); + +app.get('/login', (request, response) => { + // send response with some data (a string) + response.render('login'); +}); + +app.post('/login', (request, response) => { + console.log(request.body) + + let getUserQuery = "SELECT * FROM users WHERE name=$1"; + + const values = [request.body.name]; + + pool.query(getUserQuery, values, (error, result)=>{ + if( error ){ + console.log("ERRRRRRRRRROR"); + console.log(error); + } + console.log("YAAAYYUUUUUUUYYYYYY"); + console.log("SELECT RESULT:") + console.log(result.rows); + + // if there is a result in the array + if( result.rows.length > 0 ){ + // we have a match with the name + // response.send("heeeyyyy");heeeyyyy + + let requestPassword = request.body.password; + + if(sha256( requestPassword) === result.rows[0].password){ + response.cookie('logged in', 'true'); + response.send("you are you!"); + }else{ + + response.status(403); + response.send("sorry!!!!!!!"); + } + + }else{ + // nothing matched + response.status(403); + response.send("sorry!"); + } + + }) + + // send response with some data (a string) +}); + + +app.get('/dashboard', (request, response) => { + + if( request.cookies['logged in'] === 'true'){ + + response.send("your dashboard"); + }else{ + + response.status(403); + response.send("not allowed"); + } +}); + +app.delete('/logout', (request, response)=>{ + response.clearCookie('logged in'); + response.send("WOW Delerte"); + +}); + + +app.get('/', (request, response) => { + + const data = { + loggedIn : false + }; + + if( request.cookies['logged in'] === 'true'){ + data.loggedIn = true; + } + + // send response with some data (a string) + response.render('home', data); +}); + + + + /** * =================================== @@ -69,13 +387,13 @@ app.get('/new', (request, response) => { const server = app.listen(3000, () => console.log('~~~ Tuning in to the waves of port 3000 ~~~')); let onClose = function(){ - + console.log("closing"); - + server.close(() => { - + console.log('Process terminated'); - + pool.end( () => console.log('Shut down db connection pool')); }) }; diff --git a/package-lock.json b/package-lock.json index c18df26d..3b443002 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,19 +4,6 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "@types/commander": { - "version": "2.12.2", - "resolved": "https://registry.npmjs.org/@types/commander/-/commander-2.12.2.tgz", - "integrity": "sha512-0QEFiR8ljcHp9bAbWxecjVRuAMr16ivPiGOw6KFQBVrVd0RQIcM3xKdRisH2EDWgVWujiYtHwhSkSUoAAGzH7Q==", - "requires": { - "commander": "*" - } - }, - "@types/semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ==" - }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -774,9 +761,9 @@ } }, "commander": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.18.0.tgz", - "integrity": "sha512-6CYPa+JP2ftfRU2qkDK+UTVeQYosOg/2GbcjIcKPHfinyOLPVGXu/ovN86RP49Re5ndJK1N0kuiidFFuepc4ZQ==" + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "concat-map": { "version": "0.0.1", @@ -802,6 +789,11 @@ "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" }, + "convert-hex": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/convert-hex/-/convert-hex-0.1.0.tgz", + "integrity": "sha1-CMBFaJIsJ3drii6BqV05M2LqC2U=" + }, "convert-source-map": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", @@ -810,11 +802,32 @@ "safe-buffer": "~5.1.1" } }, + "convert-string": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/convert-string/-/convert-string-0.1.0.tgz", + "integrity": "sha1-ec5BqbsNA7z3LNxqjzxW+7xkQQo=" + }, "cookie": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" }, + "cookie-parser": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.5.tgz", + "integrity": "sha512-f13bPUj/gG/5mDr+xLmSxxDsB9DQiTIfhJS/sqjrmfAWiAN+x2O4i/XguTL9yDZ+/IFDanJ+5x7hC4CXT9Tdzw==", + "requires": { + "cookie": "0.4.0", + "cookie-signature": "1.0.6" + }, + "dependencies": { + "cookie": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", + "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" + } + } + }, "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", @@ -852,22 +865,20 @@ } }, "editorconfig": { - "version": "0.15.0", - "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.0.tgz", - "integrity": "sha512-j7JBoj/bpNzvoTQylfRZSc85MlLNKWQiq5y6gwKhmqD2h1eZ+tH4AXbkhEJD468gjDna/XMx2YtSkCxBRX9OGg==", - "requires": { - "@types/commander": "^2.11.0", - "@types/semver": "^5.4.0", - "commander": "^2.11.0", - "lru-cache": "^4.1.1", - "semver": "^5.4.1", + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz", + "integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==", + "requires": { + "commander": "^2.19.0", + "lru-cache": "^4.1.5", + "semver": "^5.6.0", "sigmund": "^1.0.1" }, "dependencies": { "semver": { - "version": "5.5.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz", - "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==" + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" } } }, @@ -980,6 +991,24 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "globals": { "version": "9.18.0", "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", @@ -1018,6 +1047,15 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", @@ -1050,16 +1088,29 @@ } }, "js-beautify": { - "version": "1.8.6", - "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.8.6.tgz", - "integrity": "sha512-TYDZa+lg8vEC5U0OmGQEEwiZ0XFBfvZAUeNOtqflLe+woKuIqF4JzlsBx/C1KVYW5lUewZy2ODL4Obq6sH7a4Q==", - "requires": { - "config-chain": "~1.1.5", - "editorconfig": "^0.15.0", - "mkdirp": "~0.5.0", - "nopt": "~4.0.1" + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.11.0.tgz", + "integrity": "sha512-a26B+Cx7USQGSWnz9YxgJNMmML/QG2nqIaL7VVYPCXbqiKz8PN0waSNvroMtvAK6tY7g/wPdNWGEP+JTNIBr6A==", + "requires": { + "config-chain": "^1.1.12", + "editorconfig": "^0.15.3", + "glob": "^7.1.3", + "mkdirp": "~1.0.3", + "nopt": "^4.0.3" + }, + "dependencies": { + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" + } } }, + "js-sha256": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", + "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" + }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", @@ -1076,9 +1127,9 @@ "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=" }, "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, "lodash.escaperegexp": { "version": "4.1.2", @@ -1094,9 +1145,9 @@ } }, "lru-cache": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", - "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", "requires": { "pseudomap": "^1.0.2", "yallist": "^2.1.2" @@ -1165,16 +1216,16 @@ } }, "minimist": { - "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "mkdirp": { - "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", "requires": { - "minimist": "0.0.8" + "minimist": "^1.2.5" } }, "ms": { @@ -1188,9 +1239,9 @@ "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" }, "nopt": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", - "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz", + "integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==", "requires": { "abbrev": "1", "osenv": "^0.1.4" @@ -1214,6 +1265,14 @@ "ee-first": "1.1.1" } }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, "os-homedir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", @@ -1523,6 +1582,15 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" }, + "sha256": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/sha256/-/sha256-0.2.0.tgz", + "integrity": "sha1-c6C0GNqrcDW/+G6EkeNjQS/CqwU=", + "requires": { + "convert-hex": "~0.1.0", + "convert-string": "~0.1.0" + } + }, "sigmund": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", @@ -1611,6 +1679,11 @@ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", diff --git a/package.json b/package.json index 544d004b..10968617 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,14 @@ "author": "", "license": "ISC", "dependencies": { + "cookie-parser": "^1.4.5", "express": "^4.16.3", "express-react-views": "^0.10.5", + "js-sha256": "^0.9.0", "method-override": "^3.0.0", "pg": "^7.4.3", "react": "^16.5.2", - "react-dom": "^16.5.2" + "react-dom": "^16.5.2", + "sha256": "^0.2.0" } } diff --git a/seed.sql b/seed.sql new file mode 100644 index 00000000..6fe5b6fa --- /dev/null +++ b/seed.sql @@ -0,0 +1,2 @@ +INSERT INTO artists (name, photo_url, nationality) VALUES('apple',34); +INSERT INTO songs (title, album, preview_link, artwork, artist_id) VALUES('banana',4); diff --git a/tables.sql b/tables.sql new file mode 100644 index 00000000..1f0bb443 --- /dev/null +++ b/tables.sql @@ -0,0 +1,29 @@ + +CREATE TABLE IF NOT EXISTS artists ( + id SERIAL PRIMARY KEY, + name TEXT, + photo_url TEXT, + nationality TEXT +); + +CREATE TABLE IF NOT EXISTS songs ( + id SERIAL PRIMARY KEY, + title TEXT, + album TEXT, + preview_link TEXT, + artwork TEXT, + artist_id INTEGER +); + +CREATE TABLE IF NOT EXISTS users ( + id SERIAL PRIMARY KEY, + name TEXT, + password TEXT +); + +CREATE TABLE IF NOT EXISTS favorites ( + id SERIAL PRIMARY KEY, + song_id INTEGER, + user_id INTEGER, + login_id INTEGER +); diff --git a/views/favorites.jsx b/views/favorites.jsx new file mode 100644 index 00000000..891b564c --- /dev/null +++ b/views/favorites.jsx @@ -0,0 +1,32 @@ +var React = require('react'); + +class UsersNew extends React.Component { + render() { + + return ( + + +
+

register

+
+
+

+ name +

+

+ password +

+

+ + +

+
+
+
+ + + ); + } +} + +module.exports = UsersNew; diff --git a/views/home.jsx b/views/home.jsx index d880bb55..1c74bf2f 100644 --- a/views/home.jsx +++ b/views/home.jsx @@ -1,16 +1,27 @@ -var React = require("react"); +var React = require('react'); -class Home extends React.Component { +class UsersNew extends React.Component { render() { + + let userButtons = (

register

+

login

); + + if( this.props.loggedIn === true){ + userButtons = (
+ +
); + } + return ( - -

Welcome!

+

home

+ {userButtons} + ); } } -module.exports = Home; +module.exports = UsersNew; diff --git a/views/index.jsx b/views/index.jsx new file mode 100644 index 00000000..33173e88 --- /dev/null +++ b/views/index.jsx @@ -0,0 +1,28 @@ +var React = require("react"); + +class Index extends React.Component { + render() { + const artistElements = this.props.artistNames.map((artistName) => { + return
  • {artistName.name}
  • + }) + return ( + + + +
    +

    artist list

    +
    +

    +

    +

    +
    +
    + + + ); + } +} + +module.exports = Index; diff --git a/views/login.jsx b/views/login.jsx new file mode 100644 index 00000000..0d49e4f7 --- /dev/null +++ b/views/login.jsx @@ -0,0 +1,32 @@ +var React = require('react'); + +class Login extends React.Component { + render() { + + return ( + + +
    +

    Login

    +
    +
    +

    + name +

    +

    + password +

    +

    + + +

    +
    +
    +
    + + + ); + } +} + +module.exports = Login; diff --git a/views/new.jsx b/views/new.jsx index 989594d6..9101acf1 100644 --- a/views/new.jsx +++ b/views/new.jsx @@ -6,7 +6,21 @@ class New extends React.Component { -

    Form Goes Here!

    +
    +
    +

    Name: + +

    +

    Photo: + +

    +

    Nationality: + + +

    +
    +
    + ); diff --git a/views/new_playlist.jsx b/views/new_playlist.jsx new file mode 100644 index 00000000..b2ce2463 --- /dev/null +++ b/views/new_playlist.jsx @@ -0,0 +1,27 @@ +var React = require("react"); + +class NewPlaylist extends React.Component { + render() { + return ( + + + +
    +

    Name: + +

    +

    Photo: + +

    +

    Nationality: + + +

    +
    + + + ); + } +} + +module.exports = NewPlaylist; diff --git a/views/register.jsx b/views/register.jsx new file mode 100644 index 00000000..891b564c --- /dev/null +++ b/views/register.jsx @@ -0,0 +1,32 @@ +var React = require('react'); + +class UsersNew extends React.Component { + render() { + + return ( + + +
    +

    register

    +
    +
    +

    + name +

    +

    + password +

    +

    + + +

    +
    +
    +
    + + + ); + } +} + +module.exports = UsersNew; diff --git a/views/tracks.jsx b/views/tracks.jsx new file mode 100644 index 00000000..69978932 --- /dev/null +++ b/views/tracks.jsx @@ -0,0 +1,31 @@ +var React = require("react"); + +class Tracks extends React.Component { + render() { + const trackElements = this.props.tracks.map((track) => { + return + + + + + +
    {track.title} *** {track.album} *** {track.name}
    + + }) + + return ( + + + + +

    + {trackElements} + +

    + + + ); + } +} + +module.exports = Tracks;