forked from zero-to-mastery/book-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug with site manifest not finding an image. Refactored SignUpF…
…orm (React) fields.
- Loading branch information
1 parent
936ebf9
commit d2cf3ba
Showing
9 changed files
with
184 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,68 @@ | ||
const { | ||
User, | ||
validateRegister, | ||
validateLogin, | ||
} = require('../models/User.model'); | ||
const bcrypt = require('bcryptjs'); | ||
const { User, validateRegister, validateLogin } = require("../models/User.model"); | ||
const bcrypt = require("bcryptjs"); | ||
|
||
const collectErrorMessage = (error) => ({ [error.details[0].context.key]: error.details[0].message }) | ||
const collectErrorMessage = (error) => ({ [error.details[0].context.key]: error.details[0].message }); | ||
|
||
export default { | ||
signUp: async (req, res) => { | ||
const { error } = validateRegister(req.body); | ||
if (error) return res.status(400).send({ | ||
type: error.name, details: collectErrorMessage(error) | ||
}); | ||
signUp: async (req, res) => { | ||
const { error } = validateRegister(req.body); | ||
if (error) | ||
return res.status(400).send({ | ||
type: error.name, | ||
details: collectErrorMessage(error), | ||
}); | ||
|
||
const { email, password, name } = req.body; | ||
const { email, password, name } = req.body; | ||
|
||
let user = await User.findOne({ email }); // Verify if user already exist. | ||
if (user) { | ||
return res.status(400).json({ | ||
message: 'User already registered.', | ||
}); | ||
} | ||
let user = await User.findOne({ email }); // Verify if user already exist. | ||
if (user) { | ||
return res.status(400).json({ | ||
message: "User already registered.", | ||
}); | ||
} | ||
|
||
user = new User({ | ||
name, | ||
email, | ||
password, | ||
}); | ||
user = new User({ | ||
name, | ||
email, | ||
password, | ||
}); | ||
|
||
try { | ||
const salt = await bcrypt.genSalt(10); | ||
user.password = await bcrypt.hash(password, salt); | ||
await user.save(); | ||
try { | ||
const salt = await bcrypt.genSalt(10); | ||
user.password = await bcrypt.hash(password, salt); | ||
await user.save(); | ||
|
||
const token = user.generateAuthToken(); | ||
const token = user.generateAuthToken(); | ||
|
||
res.header('x-auth-token', token).status(201).send({ | ||
message: 'User successfully registered', | ||
user: user._id, | ||
}); | ||
} catch (err) { | ||
res.status(400).json(err); | ||
} | ||
}, | ||
res.header("x-auth-token", token).status(201).send({ | ||
message: "User successfully registered", | ||
user: user._id, | ||
}); | ||
} catch (err) { | ||
res.status(400).json(err); | ||
} | ||
}, | ||
|
||
login: async (req, res) => { | ||
// const { error } = validateLogin(req.body); | ||
// if (error) return res.status(400).send(error.details[0].message); | ||
console.log(req.body); | ||
login: async (req, res) => { | ||
// const { error } = validateLogin(req.body); | ||
// if (error) return res.status(400).send(error.details[0].message); | ||
console.log(req.body); | ||
|
||
const { email, password } = req.body; | ||
const user = await User.findOne({ email }); | ||
const { email, password } = req.body; | ||
const user = await User.findOne({ email }); | ||
|
||
if (!user) return res.status(400).send('Invalid email or password'); | ||
if (!user) return res.status(400).send("Invalid email or password"); | ||
|
||
const validPass = await bcrypt.compare(password, user.password); | ||
if (!validPass) { | ||
return res.status(400).send('Invalid email or password.'); | ||
} | ||
const validPass = await bcrypt.compare(password, user.password); | ||
if (!validPass) { | ||
return res.status(400).send("Invalid email or password."); | ||
} | ||
|
||
const token = user.generateAuthToken(); | ||
const token = user.generateAuthToken(); | ||
|
||
res.header('x-auth-token', token).status(200).send({ | ||
message: 'Successfully logged in!', | ||
token, | ||
}); | ||
}, | ||
res.header("x-auth-token", token).status(200).send({ | ||
message: "Successfully logged in!", | ||
token, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
{ | ||
"name": "", | ||
"short_name": "", | ||
"icons": [ | ||
{ | ||
"src": "/android-chrome-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/android-chrome-384x384.png", | ||
"sizes": "384x384", | ||
"type": "image/png" | ||
} | ||
], | ||
"theme_color": "#ffffff", | ||
"background_color": "#ffffff", | ||
"display": "standalone" | ||
"name": "", | ||
"short_name": "", | ||
"icons": [ | ||
{ | ||
"src": "android-chrome-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "android-chrome-384x384.png", | ||
"sizes": "384x384", | ||
"type": "image/png" | ||
} | ||
], | ||
"start_url": "../", | ||
"theme_color": "#ffffff", | ||
"background_color": "#ffffff", | ||
"display": "standalone" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const formFields = [ | ||
{ | ||
id: "name", | ||
name: "name", | ||
type: "text", | ||
label: "Name", | ||
isRequired: true, | ||
}, | ||
{ | ||
id: "email", | ||
name: "email", | ||
type: "email", | ||
label: "Email", | ||
isRequired: true, | ||
}, | ||
{ | ||
id: "password", | ||
name: "password", | ||
type: "password", | ||
label: "Password", | ||
isRequired: true, | ||
}, | ||
{ | ||
id: "confirmPassword", | ||
name: "confirmPassword", | ||
type: "password", | ||
label: "Confirm Password", | ||
isRequired: true, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.