-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const Clarifai = require ('clarifai'); | ||
|
||
const app = new Clarifai.App({ | ||
apiKey: '6d96bc98d0814d10837c8456301b5c1a' | ||
}); | ||
|
||
const handleApiCall = (req, res) =>{ | ||
app.models.predict(Clarifai.FACE_DETECT_MODEL, req.body.input) | ||
.then(data => { | ||
res.json(data); | ||
}) | ||
.catch(err => res.status(400).json('unable to work with api')) | ||
} | ||
|
||
const handleImage = (req, res, db) => { | ||
const { id } = req.body; | ||
db('users').where('id', '=', id) | ||
.increment('entries', 1) | ||
.returning('entries') | ||
.then(entries => { | ||
res.json(entries[0]); | ||
}) | ||
.catch(err => res.status(400).json('unable to get entries')) | ||
} | ||
|
||
module.exports = { | ||
handleImage : handleImage, | ||
handleApiCall : handleApiCall | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const handleProfile = (req, res) => { | ||
const { id } = req.params; | ||
db.select('*').from('users').where({id}) | ||
.then(user => { | ||
if(user.length){ | ||
res.json(user[0]) | ||
} else { | ||
res.status(400).json('Not found') | ||
} | ||
}) | ||
.catch(err => res.status(400).json('error getting user data')) | ||
// if (!found) { | ||
// res.status(400).json('not found'); | ||
// } | ||
} | ||
|
||
module.exports = { | ||
handleProfile: handleProfile | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const handleRegister = (req, res, db, bcrypt) => { | ||
const { email, name, password } = req.body; | ||
if(!email || !name || !password){ | ||
return res.status(400).json('incorrect submission form'); | ||
} | ||
const hash = bcrypt.hashSync(password); | ||
db.transaction(trx => { | ||
trx.insert({ | ||
hash: hash, | ||
email: email | ||
}) | ||
.into('login') | ||
.returning('email') | ||
.then(loginEmail => { | ||
return trx('users') | ||
.returning('*') | ||
.insert({ | ||
email: loginEmail[0], | ||
name: name, | ||
joined: new Date() | ||
}) | ||
.then(user => { | ||
res.json(user[0]); | ||
}) | ||
}) | ||
.then(trx.commit) | ||
.catch(trx.rollback) | ||
}) | ||
.catch(err => res.status(400).json('unable to register')) | ||
} | ||
|
||
module.exports = { | ||
handleRegister: handleRegister | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const handleSignin = (req, res, db, bcrypt) => { | ||
const { email, password } = req.body; | ||
if(!email || !password){ | ||
return res.status(400).json('incorrect submission form'); | ||
} | ||
db.select('email', 'hash').from('login') | ||
.where('email', '=', email) | ||
.then(data => { | ||
const isValid = bcrypt.compareSync(password, data[0].hash); | ||
if(isValid) { | ||
return db.select('*').from('users') | ||
.where('email', '=', email) | ||
.then(user => { | ||
res.json(user[0]); | ||
}) | ||
.catch(err => res.status(400).json('unable to get user')) | ||
} else { | ||
res.status(400).json('wrong credentials') | ||
} | ||
}) | ||
.catch(err => res.status(400).json('wrong credentials')) | ||
} | ||
|
||
module.exports = { | ||
handleSignin : handleSignin | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.