Skip to content

Commit 9b1025e

Browse files
committed
google signup
1 parent ff28273 commit 9b1025e

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

authantication/google.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1-
const db = require("../database/database");
2-
const { response } = require("express");
1+
const googleregister = (req,res,db,bcrypt) =>{
2+
const {name,email,username} = req.body;
3+
const hash = bcrypt.hashSync(email);
4+
db('users')
5+
.returning('*')
6+
.insert({
7+
name: name,
8+
email: email,
9+
joined: new Date(),
10+
username: username,
11+
hash: hash
12+
}).then(result => {
13+
db.select('id', 'email', 'name','enteries').from('users').where('email', '=', email)
14+
.then(user=>{
15+
res.json({
16+
status: 'sucess',
17+
username: user[0].name,
18+
enteries: user[0].enteries,
19+
id: user[0].id,
20+
});
21+
}).catch(err=> res.status(400).json('no such user'));
22+
})
23+
.catch(err => res.status(400).json('error'));
24+
}
325

4-
const googleauthchecker = (req,res,db,bcrypt) => {
26+
const googleauthchecker = (req,res,db) => {
527
const {email} = req.body;
628
db.select('id', 'email', 'enteries', 'name').from('users').where('email', '=', email)
729
.then(user=>{
@@ -11,9 +33,11 @@ const googleauthchecker = (req,res,db,bcrypt) => {
1133
enteries: user[0].enteries,
1234
id: user[0].id,
1335
});
14-
}).catch(err => res.status(400).json('error'));
36+
})
37+
.catch(err => res.status(400).json('error'));
1538
}
1639

1740
module.exports = {
18-
googleauthchecker
41+
googleauthchecker,
42+
googleregister
1943
}

authantication/login.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const loginhandler = (req, res, db, bcrypt) => {
22
const { username, password } = req.body;
3-
db.select('id', 'email', 'username', 'hash', 'enteries').from('users').where('email', '=', username).orWhere('username', '=', username)
3+
db.select('id', 'email', 'name', 'hash', 'enteries').from('users').where('email', '=', username).orWhere('username', '=', username)
44
.then(user => {
55
let pass = bcrypt.compareSync(password, user[0].hash);
66
if (pass) {
77
res.json({
88
status: 'sucess',
9-
username: user[0].username,
9+
username: user[0].name,
1010
enteries: user[0].enteries,
1111
id: user[0].id,
1212
});

authantication/signup.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ const signuphandler = (req, res, db ,bcrypt) => {
1010
username: username,
1111
hash: hash
1212
})
13-
.then(result => res.json('sucess'))
14-
.catch(err => res.status(400).json('error'))
13+
.then(result => {
14+
db.select('id', 'email', 'name','enteries').from('users').where('email', '=', email)
15+
.then(user=>{
16+
res.json({
17+
status: 'sucess',
18+
username: user[0].name,
19+
enteries: user[0].enteries,
20+
id: user[0].id,
21+
});
22+
}).catch(err=> res.status(400).json('no such user'));
23+
}).catch(err => res.status(400).json('error'));
1524
}
1625

1726
module.exports = {

package-lock.json

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

script.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ app.post('/login', (req,res) => {login.loginhandler(req,res,db,bcrypt)})
2020

2121
app.post('/register', (req,res)=>{signup.signuphandler(req,res,db,bcrypt)});
2222

23-
app.post('/frgtpass', (req,res) => {frgtpass.frgtpasshandler(req,res,db,bcrypt)});
23+
app.post('/frgtpass', (req,res) => {frgtpass.frgtpasshandler(req,res)});
24+
25+
app.put('/passreset', (req,res) => {frgtpass.resetpasshandler(req,res,db,bcrypt)});
2426

2527
app.get('/profile/:id', (req,res)=>{profile.profilehandler(req,res,db)});
2628

2729
app.post('/imageurl', (req, res) => {image.apihandler(req,res)});
2830

29-
app.put('/image',(req,res)=>{image.imgcounthandler(req,res,db)});
31+
app.put('/image', (req,res) => {image.imgcounthandler(req,res,db)});
3032

31-
app.post('/upload',(req,res)=>{image.imgfilehandler(req,res)});
33+
app.post('/upload', (req,res) => {image.imgfilehandler(req,res)});
3234

3335
app.post('/gauth', (req,res) => {google.googleauthchecker(req,res,db,bcrypt)});
3436

37+
app.post('/gregister', (req,res) => {google.googleregister(req,res,db,bcrypt)});
38+
3539
app.listen(port, () => console.log(`running on port ${port}`));

0 commit comments

Comments
 (0)