Skip to content
Permalink
Browse files
Upload with list of track details
  • Loading branch information
nellurib committed Jul 28, 2020
1 parent faa379f commit ef3571f08f77994b94963441d7164c0e060a0c3a
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 651 deletions.
@@ -0,0 +1,45 @@
[
{
"Singer_Name": "John",

"Track":"BlackOut"
},
{
"Singer_Name": "Justin-Bieber",
"Description":"It was launched in 2002. At that Justin bieber age was 12 years.",
"Track":"Baby"
},
{
"Singer_Name": "ChainSmoker",
"Track":"Loser"
},
{
"Singer_Name": "JohnCena",

"Track":"You-can-see-me"
},
{
"Singer_Name": "Akon",

"Track":"Chammak-Challo"
},
{
"Singer_Name": "A.R-Rehman",
"Track":"Oscar"
},
{
"Singer_Name": "Pritam",

"Track":"Black"
},
{
"Singer_Name": "AlanWalker",

"Track":"Fade"
},
{
"Singer_Name": "EDSheeran",
"Track":"We-dont-talk-anymore"
}

]
@@ -0,0 +1,35 @@

const bcrypt = require('bcrypt-promise')
const sqlite = require('sqlite-async')

const saltRounds = 10

module.exports = class List {

constructor(dbName = ':memory:') {
return (async() => {
this.db = await sqlite.open(dbName)
/*we need this table to store the user track
const sql = 'CREATE TABLE IF NOT EXISTS uploadTrack\
(id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, pass TEXT, email TEXT);'
await this.db.run(sql)*/
return this
console.log("Track open")
})()
}

/**
* checks to see if a set of login credentials are valid
* @param {String} username the username to check
* @param {String} password the password to check
* @returns {Boolean} returns true if credentials are valid
*/
async getAll() {


}

async tearDown() {
await this.db.close()
}
}
@@ -10,15 +10,15 @@ module.exports = class User {
return (async() => {
this.db = await sqlite.open(dbName)
// we need this table to store the user accounts
const sql = 'CREATE TABLE IF NOT EXISTS users\
const sql = 'CREATE TABLE IF NOT EXISTS artist\
(id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, pass TEXT, email TEXT);'
await this.db.run(sql)
return this
})()
}

/**
* registers a new user
* registers a new artist
* @param {String} user the chosen username
* @param {String} pass the chosen password
* @returns {Boolean} returns true if the new user has been added
@@ -27,14 +27,14 @@ module.exports = class User {
Array.from(arguments).forEach( val => {
if(val.length === 0) throw new Error('missing field')
})
let sql = `SELECT COUNT(id) as records FROM users WHERE user="${user}";`
let sql = `SELECT COUNT(id) as records FROM artist WHERE user="${user}";`
const data = await this.db.get(sql)
if(data.records !== 0) throw new Error(`username "${user}" already in use`)
sql = `SELECT COUNT(id) as records FROM users WHERE email="${email}";`
sql = `SELECT COUNT(id) as records FROM artist WHERE email="${email}";`
const emails = await this.db.get(sql)
if(emails.records !== 0) throw new Error(`email address "${email}" is already in use`)
pass = await bcrypt.hash(pass, saltRounds)
sql = `INSERT INTO users(user, pass, email) VALUES("${user}", "${pass}", "${email}")`
sql = `INSERT INTO artist(user, pass, email) VALUES("${user}", "${pass}", "${email}")`
await this.db.run(sql)
return true
}
@@ -46,10 +46,10 @@ module.exports = class User {
* @returns {Boolean} returns true if credentials are valid
*/
async login(username, password) {
let sql = `SELECT count(id) AS count FROM users WHERE user="${username}";`
let sql = `SELECT count(id) AS count FROM artist WHERE user="${username}";`
const records = await this.db.get(sql)
if(!records.count) throw new Error(`username "${username}" not found`)
sql = `SELECT pass FROM users WHERE user = "${username}";`
sql = `SELECT pass FROM artist WHERE user = "${username}";`
const record = await this.db.get(sql)
const valid = await bcrypt.compare(password, record.pass)
if(valid === false) throw new Error(`invalid password for account "${username}"`)

0 comments on commit ef3571f

Please sign in to comment.