sms-tps 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend-project/.env +4 -0
- package/backend-project/Config/db.js +17 -0
- package/backend-project/Controller/UserController.js +69 -0
- package/backend-project/Middleware/authUser.js +28 -0
- package/backend-project/Models/UserModel.js +11 -0
- package/backend-project/Router/UserRouter.js +9 -0
- package/backend-project/package-lock.json +1550 -0
- package/backend-project/package.json +22 -0
- package/backend-project/server.js +36 -0
- package/frontend-project/README.md +16 -0
- package/frontend-project/eslint.config.js +21 -0
- package/frontend-project/index.html +13 -0
- package/frontend-project/package-lock.json +3086 -0
- package/frontend-project/package.json +34 -0
- package/frontend-project/public/favicon.svg +1 -0
- package/frontend-project/public/icons.svg +24 -0
- package/frontend-project/src/App.css +0 -0
- package/frontend-project/src/App.jsx +0 -0
- package/frontend-project/src/Context/UserContext.jsx +56 -0
- package/frontend-project/src/Layout/Pannel.jsx +221 -0
- package/frontend-project/src/Page/Login.jsx +102 -0
- package/frontend-project/src/Page/NotFound.jsx +7 -0
- package/frontend-project/src/Page/Register.jsx +103 -0
- package/frontend-project/src/assets/hero.png +0 -0
- package/frontend-project/src/assets/react.svg +1 -0
- package/frontend-project/src/assets/vite.svg +1 -0
- package/frontend-project/src/index.css +0 -0
- package/frontend-project/src/main.jsx +0 -0
- package/frontend-project/vite.config.js +7 -0
- package/package.json +12 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
// Database Connection Function
|
|
4
|
+
|
|
5
|
+
const db_conn = async () => {
|
|
6
|
+
try {
|
|
7
|
+
const db = process.env.MONGO_URL;
|
|
8
|
+
const conn = await mongoose.connect(db);
|
|
9
|
+
console.log(
|
|
10
|
+
`${conn.connection.name} Database Connected Running Success On http://${conn.connection.host}:${conn.connection.port}`,
|
|
11
|
+
);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.log(error.message);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default db_conn;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import User from "../Models/UserModel.js";
|
|
2
|
+
import jwt from "jsonwebtoken";
|
|
3
|
+
import bcrypt from "bcryptjs";
|
|
4
|
+
|
|
5
|
+
export const Register = async (req, res) => {
|
|
6
|
+
try {
|
|
7
|
+
const { name, email, password } = req.body;
|
|
8
|
+
const emailExist = await User.findOne({ email });
|
|
9
|
+
if (emailExist) {
|
|
10
|
+
return res.json({ success: false, message: "Email Already Exist" });
|
|
11
|
+
}
|
|
12
|
+
const hashPass = await bcrypt.hash(password, 10);
|
|
13
|
+
const person = await User.create({
|
|
14
|
+
name,
|
|
15
|
+
email,
|
|
16
|
+
password: hashPass,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const token = jwt.sign({ id: person._id }, process.env.JWT_SECRET, {
|
|
20
|
+
expiresIn: "7d",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return res.json({
|
|
24
|
+
success: true,
|
|
25
|
+
message: "Account Created Successfull",
|
|
26
|
+
token,
|
|
27
|
+
person,
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
res.json({ success: false, message: error.message });
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const Login = async (req, res) => {
|
|
35
|
+
try {
|
|
36
|
+
const { email, password } = req.body;
|
|
37
|
+
const emailExist = await User.findOne({ email });
|
|
38
|
+
if (!emailExist) {
|
|
39
|
+
return res.json({ success: false, message: "Email Not Exist" });
|
|
40
|
+
}
|
|
41
|
+
const isMatch = await bcrypt.compare(password, emailExist.password);
|
|
42
|
+
|
|
43
|
+
if (!isMatch) {
|
|
44
|
+
return res.json({ success: false, message: "invalid Password" });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const token = jwt.sign({ id: emailExist._id }, process.env.JWT_SECRET, {
|
|
48
|
+
expiresIn: "7d",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return res.json({
|
|
52
|
+
success: true,
|
|
53
|
+
message: "Login Successfull",
|
|
54
|
+
token,
|
|
55
|
+
user: emailExist,
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
res.json({ success: false, message: error.message });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const verify = async (req, res) => {
|
|
63
|
+
try {
|
|
64
|
+
const user = req.user;
|
|
65
|
+
return res.json({ success: true, user });
|
|
66
|
+
} catch (error) {
|
|
67
|
+
res.json({ success: false, message: error.message });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
import User from "../Models/UserModel.js";
|
|
3
|
+
|
|
4
|
+
export const verifyUser = async (req, res, next) => {
|
|
5
|
+
try {
|
|
6
|
+
const token = req.headers.authorization.split(" ")[1];
|
|
7
|
+
if (!token) {
|
|
8
|
+
return res.json({ success: false, message: "Token Not Provided" });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const secret = process.env.JWT_SECRET;
|
|
12
|
+
const decoded = jwt.verify(token, secret);
|
|
13
|
+
if (!decoded) {
|
|
14
|
+
return res.json({ success: false, message: "Token Not Valid" });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const user = await User.findById({ _id: decoded.id }).select("-password");
|
|
18
|
+
|
|
19
|
+
if (!user) {
|
|
20
|
+
return res.json({ success: false, message: "User Not Found" });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
req.user = user;
|
|
24
|
+
next();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
res.json({ success: false, message: error.message });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const UserSchema = mongoose.Schema({
|
|
4
|
+
name: { type: String, required: true },
|
|
5
|
+
email: { type: String, required: true, unique: true },
|
|
6
|
+
password: { type: String, required: true },
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const User = mongoose.model("user", UserSchema);
|
|
10
|
+
|
|
11
|
+
export default User;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { Login, Register, verify } from "../Controller/UserController.js";
|
|
3
|
+
import { verifyUser } from "../Middleware/authUser.js";
|
|
4
|
+
|
|
5
|
+
export const userRouter = express.Router();
|
|
6
|
+
|
|
7
|
+
userRouter.post("/register", Register);
|
|
8
|
+
userRouter.post("/login", Login);
|
|
9
|
+
userRouter.get("/verify", verifyUser, verify);
|