-
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.
- Loading branch information
1 parent
3f21fb0
commit 0cfd0b9
Showing
4 changed files
with
96 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
const User = require('../Models/Users/user.js'); | ||
|
||
exports.signup = async (req, res) => { | ||
try { | ||
const { username, email, mobile, password } = req.body; | ||
const newUser = new User({ username, email, mobile, password }); | ||
const savedUser = await newUser.save(); | ||
res.json(savedUser); | ||
} catch (error) { | ||
console.error('Error during signup:', error); | ||
res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}; | ||
|
||
exports.login = async (req, res) => { | ||
try{ | ||
const {username, email, mobile, password} = req.body; | ||
|
||
if(!(username || email || mobile)){ | ||
return res.status(400).json({ error: 'Please provide username, email, or mobile for login' }); | ||
} | ||
const user = await User.findOne({ $or: [{ username }, { email }, { mobile }] }); | ||
|
||
if (!user) { | ||
return res.status(401).json({ error: 'Invalid credentials' }); | ||
} | ||
const isPasswordMatch = await user.comparePassword(password); | ||
|
||
if (isPasswordMatch) { | ||
res.json({ message: 'Login successful', user }); | ||
} else { | ||
res.status(401).json({ error: 'Invalid credentials' }); | ||
} | ||
} catch (error) { | ||
console.error('Error during login:', error); | ||
res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}; |
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,46 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const productSchema = new mongoose.Schema({ | ||
productID: String, | ||
productName: String, | ||
productImage: [ | ||
{ | ||
image:[String], | ||
image_URL: [String], | ||
image_ALT: [String], | ||
}, | ||
{ | ||
image:[String], | ||
image_URL: [String], | ||
image_ALT: [String], | ||
}, | ||
{ | ||
image:[String], | ||
image_URL: [String], | ||
image_ALT: [String], | ||
}, | ||
{ | ||
image:[String], | ||
image_URL: [String], | ||
image_ALT: [String], | ||
}, | ||
{ | ||
image:[String], | ||
image_URL: [String], | ||
image_ALT: [String], | ||
}, | ||
], | ||
productPrice: String, | ||
productAvailability: Boolean, | ||
productAvailableSizes: [String], | ||
productDescription: String, | ||
productMaker: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Maker', | ||
required: true, | ||
}, | ||
}); | ||
|
||
const Product = mongoose.model('Product', productSchema); | ||
|
||
module.exports = Product; |
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,10 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const productMaker = new mongoose.Schema({ | ||
makerName: String, | ||
makerLocation: String, | ||
}); | ||
|
||
const Maker = mongoose.model('Maker', productMaker); | ||
|
||
module.exports = Maker; |
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