-
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
6237c4b
commit a03c1b2
Showing
5,412 changed files
with
541,809 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE = |
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,5 @@ | ||
const config={ | ||
Useremail:'[email protected]', | ||
UserPassword:'fdkmgjcesrzgwjmcz', | ||
} | ||
export default config; |
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,49 @@ | ||
import Blog from "../model/blog"; | ||
|
||
export const getAllBlogs = async (req, res, next) => { | ||
let blogs; | ||
try { | ||
blogs = await Blog.find(); | ||
// .populate("user"); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
if (!blogs) { | ||
return res.status(404).json({ message: "No blog found" }); | ||
} | ||
return res.status(200).json({ blogs }); | ||
}; | ||
|
||
export const addblog = async (req, res, next) => { | ||
const { title, description, Image, user } = req.body; | ||
const blog = new Blog({ | ||
title, | ||
description, | ||
Image, | ||
user, | ||
}); | ||
try { | ||
await blog.save(); | ||
return res.status(200).json({ blog }); | ||
} catch (err) { | ||
return res.status(500).json({ message: "error" }); | ||
} | ||
}; | ||
|
||
export const updateblog = async (req, res, next) => { | ||
const { title, description } = req.body; | ||
const blogId = req.params.id; | ||
let blog; | ||
try { | ||
blog = await Blog.findByIdAndUpdate(blogId, { | ||
title, | ||
description, | ||
}); | ||
} catch (err) { | ||
return console.log(err); | ||
} | ||
if (!blog) { | ||
return res.status(500).json({ message: "unable to update the blog" }); | ||
} | ||
return res.status(200).json({ blog }); | ||
}; |
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,32 @@ | ||
import Query from "../model/query"; | ||
|
||
export const getAllQuerys = async (req, res, next) => { | ||
let querys; | ||
try { | ||
querys = await Query.find(); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
if (!querys) { | ||
return res.status(404).json({ message: "No contact found" }); | ||
} | ||
return res.status(200).json({ querys }); | ||
}; | ||
|
||
export const addQuery = async (req, res, next) => { | ||
const { name, email, phone, company, heading, message } = req.body; | ||
const query = new Query({ | ||
name, | ||
email, | ||
phone, | ||
company, | ||
heading, | ||
message, | ||
}); | ||
try { | ||
await query.save(); | ||
return res.status(201).json({ query }); | ||
} catch (err) { | ||
return res.status(500).json({ message: "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,176 @@ | ||
import User from "../model/user"; | ||
import config from "../config/config"; | ||
import bcrypt from "bcryptjs"; //using bcryptjs for hashing password | ||
import jwt from "jsonwebtoken"; | ||
import { SECRET_KEY } from "./utils/constants.js"; | ||
import randomstring from "randomstring"; | ||
import nodemailer from "nodemailer"; | ||
|
||
|
||
const sendresetmail = async (email, token, name) => { | ||
try { | ||
const transporter = nodemailer.createTransport({ | ||
service: "Gmail", | ||
auth: { | ||
user: config.Useremail, | ||
pass: config.UserPassword, | ||
}, | ||
}); | ||
|
||
const mailOptions = { | ||
from: config.Useremail, | ||
to: email, | ||
subject: "to reset password", | ||
html: | ||
"<p>Hi " + | ||
name + | ||
', click on the link and <a href="http://localhost:4000/api/user/resetpassword?token=' + | ||
token + | ||
'" > reset your paswword </a></p>', | ||
}; | ||
transporter.sendMail(mailOptions, function (error, info) { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
console.log("mail has been sent", info.response); | ||
} | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
export const getAllUser = async (req, res, next) => { | ||
//getting all user from database | ||
try { | ||
const users = await User.find(); | ||
return res.status(200).json({ users }); | ||
} catch (err) { | ||
console.log(err); | ||
return res | ||
.status(500) | ||
.json({ message: "Failed to get users from database." }); | ||
} | ||
}; | ||
|
||
//SIGNUP | ||
|
||
export const signup = async (req, res, next) => { | ||
const { firstname, lastname, email, password } = req.body; | ||
|
||
try { | ||
const existingUser = await User.findOne({ email: email }); | ||
if (existingUser) { | ||
return res.status(400).json({ message: "user already exist" }); | ||
} | ||
|
||
const hashedPassword = bcrypt.hashSync(password, 10); | ||
const user = new User({ | ||
firstname, | ||
lastname, | ||
email, | ||
password: hashedPassword, | ||
}); | ||
const token = jwt.sign({ email: user.email, id: user._id }, SECRET_KEY); | ||
|
||
await user.save(); //saving new user | ||
|
||
return res.status(201).json({ user, token }); /////////// | ||
} catch (err) { | ||
console.log(err); | ||
return res | ||
.status(500) | ||
.json({ message: "Failed to create user. Please try again later." }); | ||
} | ||
}; | ||
|
||
//LOGIN | ||
|
||
export const login = async (req, res, next) => { | ||
const { email, password } = req.body; | ||
|
||
let existingUser; | ||
try { | ||
existingUser = await User.findOne({ email }); | ||
} catch (err) { | ||
console.log(err); | ||
return res | ||
.status(500) | ||
.json({ message: "Failed to login. Please try again later." }); | ||
} | ||
if (!existingUser) { | ||
return res.status(404).json({ message: "couldnot find user by email" }); | ||
} | ||
|
||
const isPasswordCorrect = bcrypt.compareSync(password, existingUser.password); | ||
|
||
var token = jwt.sign( | ||
{ email: existingUser.email, id: existingUser._id }, | ||
SECRET_KEY, | ||
{ | ||
expiresIn: "24h", | ||
} | ||
); | ||
|
||
if (!isPasswordCorrect) { | ||
return res.status(400).json({ message: "incorrect password" }); | ||
} else { | ||
return res | ||
.status(200) | ||
.json({ message: "login", user: existingUser, token }); | ||
} | ||
}; | ||
|
||
export const forgotpassword = async (req, res) => { | ||
try { | ||
const email = req.body.email; | ||
const userdata = await User.findOne({ email: email }); | ||
|
||
if (userdata) { | ||
const token = randomstring.generate(); | ||
|
||
const filter = { email: email }; | ||
const update = { token }; | ||
|
||
await User.findOneAndUpdate(filter, update, { new: true }); | ||
|
||
await sendresetmail(email, token, userdata.firstname); | ||
|
||
res.status(200).send({ | ||
success: true, | ||
msg: "check your inbox and reset your password", | ||
}); | ||
} else { | ||
res.status(200).send({ success: true, msg: "user doesn't exist" }); | ||
} | ||
} catch (error) { | ||
res.status(400).send({ success: false, msg: error.message }); | ||
} | ||
}; | ||
|
||
export const resetpassword = async (req, res) => { | ||
try { | ||
const token = req.query.token; | ||
|
||
const tokenData = await User.findOne({ token: token }); | ||
if (tokenData) { | ||
const password = req.body.password; | ||
|
||
const newpassword = bcrypt.hashSync(password, 10); | ||
|
||
const user = await User.findOneAndUpdate( | ||
{ _id: tokenData._id }, | ||
{ $set: { password: newpassword, token: "" } }, | ||
{ new: true } | ||
); | ||
|
||
res | ||
.status(200) | ||
.send({ success: true, msg: "password updated", data: user }); | ||
} else { | ||
res.status(200).send({ success: false, msg: "this link has expired" }); | ||
} | ||
} catch (error) { | ||
res.status(400).send({ success: false, msg: error.message }); | ||
} | ||
}; |
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 @@ | ||
export const SECRET_KEY = "code1234" |
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,25 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const blogSchema = new Schema({ | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
|
||
description: { | ||
type: String, | ||
required: true, | ||
}, | ||
Image: { | ||
type: String, | ||
|
||
}, | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User', | ||
} | ||
}); | ||
|
||
export default mongoose.model("Blog", blogSchema); |
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,33 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const querySchema = new Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
}, | ||
phone: { | ||
type: Number, | ||
required: true, | ||
}, | ||
company: { | ||
type: String, | ||
required: true, | ||
}, | ||
heading: { | ||
type: String, | ||
required: true, | ||
}, | ||
message: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
|
||
export default mongoose.model("Query" , querySchema); | ||
|
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,41 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const userSchema = new Schema({ | ||
firstname: { | ||
type: String, | ||
required: true, | ||
}, | ||
lastname: { | ||
type: String, | ||
required: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
unique: true, | ||
}, | ||
password: { | ||
type: String, | ||
required: true, | ||
minlength: 4, | ||
}, | ||
|
||
token: { | ||
type: String, | ||
}, | ||
}); | ||
|
||
// userSchema.methods.generateAuthToken = function () { | ||
// const token = jwt.sign( | ||
// { _id: this._id, name: this.name, isAdmin: this.isAdmin }, | ||
// process.env.JWTPRIVATEKEY, | ||
// { | ||
// expiresIn: "24h", | ||
// } | ||
// ); | ||
// return token; | ||
// }; | ||
|
||
export default mongoose.model("User", userSchema); //create modal for us like collection |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.