Skip to content

Commit 04103e7

Browse files
committed
my commit
1 parent 7f462f8 commit 04103e7

File tree

10 files changed

+314
-76
lines changed

10 files changed

+314
-76
lines changed

Diff for: .env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
password: '2739247921'
1+
password: 'qu136578a'

Diff for: .gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.env
2+
.env.development.local
3+
.env.test.local
4+
.env.production.local
5+
.env.local
6+
node_modules/
7+
dist
8+
.DS_Store

Diff for: controllers/image.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const Clarifai = require('clarifai');
2+
3+
const handleImage = (req, res, db) => {
4+
const { id } = req.body;
5+
db('users').where('id', '=', id)
6+
.increment('entries', 1)
7+
.returning('entries')
8+
.then(entries => {
9+
res.json(entries[0]);
10+
})
11+
.catch(err => res.status(400).json('unable to get entries'))
12+
}
13+
14+
module.exports = {
15+
handleImage
16+
}

Diff for: controllers/profile.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const handleProfileGet = (req, res, db) => {
2+
const { id } = req.params;
3+
db.select('*').from('users').where({id})
4+
.then(user => {
5+
if(user.length) {
6+
res.json(user[0])
7+
} else {
8+
res.status(400).json('Not found')
9+
}
10+
})
11+
.catch(err => res.status(400).json('error getting user'))
12+
}
13+
14+
module.exports = {
15+
handleProfileGet
16+
}

Diff for: controllers/register.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const handleRegister = (req, res, db, bcrypt) => {
2+
const { email, name, password } = req.body;
3+
if(!email || !name || !password) {
4+
return res.status(400).json('incorrect form submission');
5+
}
6+
const hash = bcrypt.hashSync(password);
7+
db.transaction(trx => {
8+
trx.insert({
9+
hash: hash,
10+
email: email
11+
})
12+
.into('login')
13+
.returning('email')
14+
.then(loginEmail => {
15+
return trx('users')
16+
.returning('*')
17+
.insert({
18+
email: loginEmail[0].email,
19+
name: name,
20+
joined: new Date()
21+
})
22+
.then(user => {
23+
res.json(user[0]);
24+
})
25+
})
26+
.then(trx.commit)
27+
.catch(trx.rollback)
28+
})
29+
.catch(err => res.status(400).json('unable to register'))
30+
}
31+
32+
module.exports = {
33+
handleRegister: handleRegister
34+
};

Diff for: controllers/signin.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const handleSignin = (req, res, db, bcrypt) => {
2+
const { email, password } = req.body;
3+
if(!email || !password) {
4+
return res.status(400).json('incorrect form submission');
5+
}
6+
db.select('email', 'hash').from('login')
7+
.where('email', '=', email)
8+
.then(data => {
9+
//console.log(data);
10+
const isValid = bcrypt.compareSync(password, data[0].hash);
11+
if(isValid) {
12+
return db.select('*').from('users')
13+
.where('email', '=', email)
14+
.then(user => {
15+
//console.log(user);
16+
res.json(user[0])
17+
})
18+
.catch(err => res.status(400).json('uable to get user'))
19+
} else {
20+
res.status(400).json('wrong credentials')
21+
}
22+
})
23+
.catch(err => res.status(400).json('wrong credentials'))
24+
}
25+
26+
module.exports = {
27+
handleSignin: handleSignin
28+
}

Diff for: node_modules/.package-lock.json

+99
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)