backenddeepali 1.0.0 → 1.0.1
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/Controllers/deleteprofile.js +26 -0
- package/Controllers/editprofile.js +65 -0
- package/Controllers/getprofile.js +34 -0
- package/Routes/user.routes.js +24 -1
- package/images/Screenshot from 2022-07-04 14-20-05.png +0 -0
- package/package.json +1 -1
- package/Controllers/showprofile.js +0 -0
- package/Controllers/user.controller.js +0 -417
@@ -0,0 +1,26 @@
|
|
1
|
+
const Profile = require("../Models/UserProfile");
|
2
|
+
const mongoose = require("mongoose")
|
3
|
+
|
4
|
+
const deleteprofile = async (req, res) => {
|
5
|
+
const { user_id } = req.body;
|
6
|
+
try {
|
7
|
+
if (user_id) {
|
8
|
+
const profiledelete = await Profile.deleteOne({
|
9
|
+
_id: mongoose.Types.ObjectId(`${user_id}`),
|
10
|
+
});
|
11
|
+
if (profiledelete.deletedCount == 1) {
|
12
|
+
return res.send("profile deleted");
|
13
|
+
} else {
|
14
|
+
return res.send("Fail to delete profile ");
|
15
|
+
}
|
16
|
+
}
|
17
|
+
return res.send("Please select a profile ");
|
18
|
+
} catch (err) {
|
19
|
+
res.json({
|
20
|
+
msg: `Failed to delete profile because ${err.message}`,
|
21
|
+
});
|
22
|
+
console.log(err);
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
module.exports = { deleteprofile };
|
@@ -0,0 +1,65 @@
|
|
1
|
+
const Profile = require("../Models/UserProfile");
|
2
|
+
const domain = "http://localhost:4000/images/";
|
3
|
+
|
4
|
+
const editprofile = async (req, res) => {
|
5
|
+
const { firstname, lastname, age, gender, state, address, email } = req.body;
|
6
|
+
try {
|
7
|
+
var filenames = "";
|
8
|
+
if (req.file) {
|
9
|
+
filenames = domain + req.file.filename;
|
10
|
+
}
|
11
|
+
if (firstname && age) {
|
12
|
+
// console.log(re.user._id);
|
13
|
+
const editprofile = await Profile.findOne({ userId: req.user._id });
|
14
|
+
editprofile.Firstname = firstname ? firstname : editprofile.Firstname;
|
15
|
+
editprofile.Lastname = lastname ? lastname : editprofile.Lastname;
|
16
|
+
editprofile.Age = age ? age : editprofile.Age;
|
17
|
+
editprofile.Gender = gender ? gender : editprofile.Gender;
|
18
|
+
editprofile.State = state ? state : editprofile.State;
|
19
|
+
editprofile.Address = address ? address : editprofile.Address;
|
20
|
+
editprofile.EmailId = email ? email : editprofile.EmailId;
|
21
|
+
editprofile.Image = filenames != "" ? filenames : editprofile.Image;
|
22
|
+
|
23
|
+
await editprofile.save();
|
24
|
+
res.send({
|
25
|
+
message: "Profile updated successfully",
|
26
|
+
status: "true",
|
27
|
+
sessionExist: "1",
|
28
|
+
response: {
|
29
|
+
data: {
|
30
|
+
Firstname: editprofile.Firstname,
|
31
|
+
Lastname: editprofile.Lastname,
|
32
|
+
userId: editprofile.userId,
|
33
|
+
Image: filenames,
|
34
|
+
Age: editprofile.Age,
|
35
|
+
Gender: editprofile.Gender,
|
36
|
+
State: editprofile.State,
|
37
|
+
Address: editprofile.Address,
|
38
|
+
EmailId: editprofile.EmailId,
|
39
|
+
},
|
40
|
+
},
|
41
|
+
});
|
42
|
+
} else {
|
43
|
+
res.send({
|
44
|
+
message: "Please enter player name and age",
|
45
|
+
status: "false",
|
46
|
+
sessionExist: "1",
|
47
|
+
response: {
|
48
|
+
data: null,
|
49
|
+
},
|
50
|
+
});
|
51
|
+
}
|
52
|
+
} catch (err) {
|
53
|
+
res.send({
|
54
|
+
message: "server not responding",
|
55
|
+
status: "false",
|
56
|
+
sessionExist: "0",
|
57
|
+
response: {
|
58
|
+
data: null,
|
59
|
+
},
|
60
|
+
});
|
61
|
+
console.log(err);
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
module.exports = { editprofile };
|
@@ -0,0 +1,34 @@
|
|
1
|
+
const Profile = require("../Models/UserProfile");
|
2
|
+
|
3
|
+
const getprofile = async (req, res) => {
|
4
|
+
try {
|
5
|
+
Profile.findOne({ userId: req.user._id }, (err, data) => {
|
6
|
+
if (err) throw err;
|
7
|
+
// console.log(data);
|
8
|
+
console.log("data", data);
|
9
|
+
|
10
|
+
res.send({
|
11
|
+
message: "Account details",
|
12
|
+
status: "true",
|
13
|
+
sessionExist: "1",
|
14
|
+
response: {
|
15
|
+
data: data,
|
16
|
+
},
|
17
|
+
});
|
18
|
+
// res.send(data);
|
19
|
+
console.log(data);
|
20
|
+
});
|
21
|
+
} catch (err) {
|
22
|
+
// console.log("error", err);
|
23
|
+
res.send({
|
24
|
+
message: `account show api fail because ${err.message} `,
|
25
|
+
status: "false",
|
26
|
+
sessionExist: "0",
|
27
|
+
response: {
|
28
|
+
data: null,
|
29
|
+
},
|
30
|
+
});
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
module.exports = { getprofile };
|
package/Routes/user.routes.js
CHANGED
@@ -8,7 +8,10 @@ const forgotpasswordcontroller = require("../Controllers/forgotpassword");
|
|
8
8
|
const sendotpcontroller = require("../Controllers/sendotp");
|
9
9
|
const resetpasscontroller = require("../Controllers/resetpassword");
|
10
10
|
const changepasscontroller = require("../Controllers/changepassword");
|
11
|
-
const createprofilecontroller = require("../Controllers/createprofile")
|
11
|
+
const createprofilecontroller = require("../Controllers/createprofile");
|
12
|
+
const getprofilecontroller = require("../Controllers/getprofile");
|
13
|
+
const editprofilecontroller = require("../Controllers/editprofile");
|
14
|
+
const deleteprofilecontroller = require("../Controllers/deleteprofile");
|
12
15
|
|
13
16
|
const Authorization = require("../Middleware/Authorization");
|
14
17
|
const { uploadimage } = require("../helper/imagehelper");
|
@@ -56,4 +59,24 @@ router.post(
|
|
56
59
|
createprofilecontroller.createprofile
|
57
60
|
);
|
58
61
|
|
62
|
+
router.post(
|
63
|
+
"/getprofile",
|
64
|
+
Authorization,
|
65
|
+
requireAuth,
|
66
|
+
getprofilecontroller.getprofile
|
67
|
+
);
|
68
|
+
|
69
|
+
router.put(
|
70
|
+
"/editprofile",
|
71
|
+
uploadimage.single("file"),
|
72
|
+
requireAuth,
|
73
|
+
editprofilecontroller.editprofile
|
74
|
+
);
|
75
|
+
|
76
|
+
router.post(
|
77
|
+
"/deleteprofile",
|
78
|
+
requireAuth,
|
79
|
+
deleteprofilecontroller.deleteprofile
|
80
|
+
);
|
81
|
+
|
59
82
|
module.exports = router;
|
Binary file
|
package/package.json
CHANGED
File without changes
|
@@ -1,417 +0,0 @@
|
|
1
|
-
|
2
|
-
const dotenev = require("dotenv");
|
3
|
-
const bcrypt = require("bcryptjs");
|
4
|
-
const jwt = require("jsonwebtoken");
|
5
|
-
const User = require("../Models/UserSchema");
|
6
|
-
const { transporter } = require("../helper/mailer")
|
7
|
-
const mongoose = require("mongoose");
|
8
|
-
dotenev.config();
|
9
|
-
|
10
|
-
|
11
|
-
// User signup API
|
12
|
-
const userRegister = async (req, res) => {
|
13
|
-
const { name, contact, email, password, cpassword } = req.body;
|
14
|
-
try {
|
15
|
-
if (name && contact && email && password && cpassword) {
|
16
|
-
const userfound = await User.findOne({
|
17
|
-
EmailId: email,
|
18
|
-
});
|
19
|
-
if (userfound) {
|
20
|
-
res.send({
|
21
|
-
message: "Email Already registered",
|
22
|
-
status: "false",
|
23
|
-
sessionExist: "0",
|
24
|
-
response: {
|
25
|
-
data: null,
|
26
|
-
},
|
27
|
-
});
|
28
|
-
} else {
|
29
|
-
if (password == cpassword) {
|
30
|
-
const code = Math.floor(1000 + Math.random() * 9000);
|
31
|
-
const user = new User({
|
32
|
-
Fullname: name,
|
33
|
-
EmailId: email,
|
34
|
-
Contact: contact,
|
35
|
-
Password: password,
|
36
|
-
Token: code,
|
37
|
-
});
|
38
|
-
await user.save();
|
39
|
-
res.send({
|
40
|
-
message: "You are signup successfully",
|
41
|
-
status: "true",
|
42
|
-
sessionExist: "1",
|
43
|
-
response: {
|
44
|
-
data: {
|
45
|
-
id: user._id,
|
46
|
-
full_name: user.Fullname,
|
47
|
-
email: user.EmailId,
|
48
|
-
mobile: user.Contact,
|
49
|
-
token: user.Token,
|
50
|
-
},
|
51
|
-
},
|
52
|
-
});
|
53
|
-
} else {
|
54
|
-
res.send({
|
55
|
-
message: "Password mismatch",
|
56
|
-
status: "false",
|
57
|
-
sessionExist: "0",
|
58
|
-
response: {
|
59
|
-
data: null,
|
60
|
-
},
|
61
|
-
});
|
62
|
-
}
|
63
|
-
}
|
64
|
-
} else {
|
65
|
-
res.send({
|
66
|
-
message: "Please fill complete details",
|
67
|
-
status: "false",
|
68
|
-
sessionExist: "0",
|
69
|
-
response: {
|
70
|
-
data: null,
|
71
|
-
},
|
72
|
-
});
|
73
|
-
}
|
74
|
-
} catch (err) {
|
75
|
-
console.log("errror", err);
|
76
|
-
|
77
|
-
res.send({
|
78
|
-
message: "Failed to register",
|
79
|
-
status: "false",
|
80
|
-
sessionExist: "0",
|
81
|
-
response: {
|
82
|
-
data: null,
|
83
|
-
},
|
84
|
-
});
|
85
|
-
}
|
86
|
-
};
|
87
|
-
|
88
|
-
//User login API
|
89
|
-
const userLogin = async (req, res) => {
|
90
|
-
const { email, password } = req.body;
|
91
|
-
// console.log(req.body);
|
92
|
-
try {
|
93
|
-
const found = await User.findOne({
|
94
|
-
EmailId: email,
|
95
|
-
});
|
96
|
-
if (email && password) {
|
97
|
-
if (!found) {
|
98
|
-
res.send({
|
99
|
-
message: "Invalid Credentials",
|
100
|
-
status: "false",
|
101
|
-
sessionExist: "0",
|
102
|
-
response: {
|
103
|
-
data:null
|
104
|
-
},
|
105
|
-
});
|
106
|
-
} else {
|
107
|
-
const matchPassword = await bcrypt.compare(password, found.Password);
|
108
|
-
const token = jwt.sign(
|
109
|
-
{
|
110
|
-
email: found.EmailId,
|
111
|
-
},
|
112
|
-
"NODEJS"
|
113
|
-
);
|
114
|
-
matchPassword
|
115
|
-
? ((found.JWTToken = token),
|
116
|
-
await found.save(),
|
117
|
-
res.send({
|
118
|
-
message: "You are successfully logged in",
|
119
|
-
status: "true",
|
120
|
-
sessionExist: "1",
|
121
|
-
response: {
|
122
|
-
data: {
|
123
|
-
id: found._id,
|
124
|
-
full_name: found.Fullname,
|
125
|
-
email: found.EmailId,
|
126
|
-
mobile: found.Contact,
|
127
|
-
token: found.JWTToken,
|
128
|
-
|
129
|
-
},
|
130
|
-
},
|
131
|
-
}))
|
132
|
-
: res.send({
|
133
|
-
message: "Invalid Credentials",
|
134
|
-
status: "false",
|
135
|
-
sessionExist: "0",
|
136
|
-
response: {
|
137
|
-
data: {
|
138
|
-
id: null,
|
139
|
-
full_name: null,
|
140
|
-
email: null,
|
141
|
-
mobile: null,
|
142
|
-
token: null,
|
143
|
-
|
144
|
-
},
|
145
|
-
},
|
146
|
-
});
|
147
|
-
}
|
148
|
-
} else {
|
149
|
-
res.send({
|
150
|
-
message: "Please Enter Credentials",
|
151
|
-
status: "false",
|
152
|
-
sessionExist: "0",
|
153
|
-
response: {
|
154
|
-
data:null
|
155
|
-
},
|
156
|
-
});
|
157
|
-
}
|
158
|
-
} catch (err) {
|
159
|
-
// console.log("Failed to login", err);
|
160
|
-
res.send({
|
161
|
-
message: "Login Api fail",
|
162
|
-
status: "false",
|
163
|
-
sessionExist: "0",
|
164
|
-
response: {
|
165
|
-
data: {
|
166
|
-
id: null,
|
167
|
-
full_name: null,
|
168
|
-
email: null,
|
169
|
-
mobile: null,
|
170
|
-
token: null,
|
171
|
-
isblock: null,
|
172
|
-
isExist: null,
|
173
|
-
},
|
174
|
-
},
|
175
|
-
});
|
176
|
-
}
|
177
|
-
};
|
178
|
-
|
179
|
-
//forgot password API
|
180
|
-
const userForgotpassword = async (req, res) => {
|
181
|
-
const { email } = req.body;
|
182
|
-
try {
|
183
|
-
if (email) {
|
184
|
-
const userfound = await User.findOne({
|
185
|
-
EmailId: email,
|
186
|
-
});
|
187
|
-
// console.log(userfound);
|
188
|
-
if (userfound) {
|
189
|
-
const code = Math.floor(1000 + Math.random() * 9000);
|
190
|
-
userfound.Token = code;
|
191
|
-
await userfound.save();
|
192
|
-
transporter.sendMail({
|
193
|
-
to: email,
|
194
|
-
subject: "Reset Password Verification code",
|
195
|
-
html: `<h4>Use this ${code} 4 digit code to reset your account Password </h4>`,
|
196
|
-
});
|
197
|
-
|
198
|
-
res.send({
|
199
|
-
message: "4-digit code has been sent via email to your email address",
|
200
|
-
status: "true",
|
201
|
-
sessionExist: "0",
|
202
|
-
response: {
|
203
|
-
data: null
|
204
|
-
},
|
205
|
-
});
|
206
|
-
} else {
|
207
|
-
res.send({
|
208
|
-
message:
|
209
|
-
"4-digit code has been sent via email to your email address ",
|
210
|
-
status: "true",
|
211
|
-
sessionExist: "0",
|
212
|
-
response: {
|
213
|
-
data: null
|
214
|
-
},
|
215
|
-
});
|
216
|
-
}
|
217
|
-
} else {
|
218
|
-
res.send({
|
219
|
-
message: "Please Enter Emailid",
|
220
|
-
status: "false",
|
221
|
-
sessionExist: "0",
|
222
|
-
response: {
|
223
|
-
data: null
|
224
|
-
},
|
225
|
-
});
|
226
|
-
}
|
227
|
-
} catch (err) {
|
228
|
-
// console.log("Failed to get email ", err);
|
229
|
-
res.send({
|
230
|
-
message: "forgot password api fail",
|
231
|
-
status: "false",
|
232
|
-
sessionExist: "0",
|
233
|
-
response: {
|
234
|
-
data: null
|
235
|
-
},
|
236
|
-
});
|
237
|
-
}
|
238
|
-
};
|
239
|
-
|
240
|
-
//otp send to email
|
241
|
-
const sendOTP = async (req, res) => {
|
242
|
-
const { email, otp } = req.body;
|
243
|
-
|
244
|
-
try {
|
245
|
-
const userfound = await User.findOne({
|
246
|
-
EmailId: email,
|
247
|
-
});
|
248
|
-
// console.log(userfound, otp);
|
249
|
-
if ((userfound && otp == userfound.Token) || otp == 1234) {
|
250
|
-
res.send({
|
251
|
-
message: "Correct OTP",
|
252
|
-
status: "true",
|
253
|
-
sessionExist: "0",
|
254
|
-
response: {
|
255
|
-
data: null
|
256
|
-
},
|
257
|
-
});
|
258
|
-
} else {
|
259
|
-
res.send({
|
260
|
-
message: "Invalid otp",
|
261
|
-
status: "false",
|
262
|
-
sessionExist: "0",
|
263
|
-
response: {
|
264
|
-
data: null
|
265
|
-
},
|
266
|
-
});
|
267
|
-
}
|
268
|
-
} catch (err) {
|
269
|
-
// console.log("failed to get otp", err);
|
270
|
-
|
271
|
-
res.send({
|
272
|
-
message: "forgototp api fail",
|
273
|
-
status: "false",
|
274
|
-
sessionExist: "0",
|
275
|
-
response: {
|
276
|
-
data:null
|
277
|
-
},
|
278
|
-
});
|
279
|
-
}
|
280
|
-
};
|
281
|
-
|
282
|
-
//reset password
|
283
|
-
const resetpass = async (req, res) => {
|
284
|
-
const { email, password, cpassword } = req.body;
|
285
|
-
try {
|
286
|
-
if (email && password && cpassword) {
|
287
|
-
const userfound = await User.findOne({
|
288
|
-
EmailId: email,
|
289
|
-
});
|
290
|
-
if (userfound) {
|
291
|
-
if (password == cpassword) {
|
292
|
-
userfound.Password = password;
|
293
|
-
await userfound.save();
|
294
|
-
res.send({
|
295
|
-
message: "Password changed Successfully",
|
296
|
-
status: "true",
|
297
|
-
sessionExist: "0",
|
298
|
-
response: {
|
299
|
-
data: null
|
300
|
-
},
|
301
|
-
});
|
302
|
-
} else {
|
303
|
-
res.send({
|
304
|
-
message: "Password mismatch",
|
305
|
-
status: "false",
|
306
|
-
sessionExist: "0",
|
307
|
-
response: {
|
308
|
-
data: null
|
309
|
-
},
|
310
|
-
});
|
311
|
-
}
|
312
|
-
} else {
|
313
|
-
res.send({
|
314
|
-
message: "User not found",
|
315
|
-
status: "false",
|
316
|
-
sessionExist: "0",
|
317
|
-
response: {
|
318
|
-
data: null
|
319
|
-
},
|
320
|
-
});
|
321
|
-
}
|
322
|
-
} else {
|
323
|
-
res.send({
|
324
|
-
message: "Please Fill complete details",
|
325
|
-
status: "false",
|
326
|
-
sessionExist: "0",
|
327
|
-
response: {
|
328
|
-
data:null
|
329
|
-
},
|
330
|
-
});
|
331
|
-
}
|
332
|
-
} catch (err) {
|
333
|
-
res.send({
|
334
|
-
message: "Server error reset password fail",
|
335
|
-
status: "false",
|
336
|
-
sessionExist: "0",
|
337
|
-
response: {
|
338
|
-
data: null
|
339
|
-
},
|
340
|
-
});
|
341
|
-
}
|
342
|
-
};
|
343
|
-
//change password api
|
344
|
-
const changepassword = async (req, res) => {
|
345
|
-
const { oldpassword, newpassword, cnewpassword } = req.body;
|
346
|
-
try {
|
347
|
-
if (oldpassword && newpassword && cnewpassword) {
|
348
|
-
const isMatch = await bcrypt.compare(oldpassword, req.user.Password);
|
349
|
-
if (isMatch) {
|
350
|
-
if (newpassword == cnewpassword) {
|
351
|
-
req.user.Password = newpassword;
|
352
|
-
await req.user.save(),
|
353
|
-
res.send({
|
354
|
-
message: "Password Updated successfully",
|
355
|
-
status: "true",
|
356
|
-
sessionExist: "1",
|
357
|
-
response: {
|
358
|
-
data: {
|
359
|
-
id: req.user._id,
|
360
|
-
full_name: req.user.Fullname,
|
361
|
-
email: req.user.EmailId,
|
362
|
-
mobile: req.user.Contact,
|
363
|
-
token: req.user.JWTToken,
|
364
|
-
|
365
|
-
},
|
366
|
-
},
|
367
|
-
});
|
368
|
-
} else {
|
369
|
-
res.send({
|
370
|
-
message: "Password mismatch",
|
371
|
-
status: "false",
|
372
|
-
sessionExist: "0",
|
373
|
-
response: {
|
374
|
-
data: null
|
375
|
-
},
|
376
|
-
});
|
377
|
-
}
|
378
|
-
} else {
|
379
|
-
res.send({
|
380
|
-
message: "You have entered current password wrong",
|
381
|
-
status: "false",
|
382
|
-
sessionExist: "0",
|
383
|
-
response: {
|
384
|
-
data: null
|
385
|
-
},
|
386
|
-
});
|
387
|
-
}
|
388
|
-
} else {
|
389
|
-
res.send({
|
390
|
-
message: "Please Enter in all required fields",
|
391
|
-
status: "false",
|
392
|
-
sessionExist: "0",
|
393
|
-
response: {
|
394
|
-
data:null
|
395
|
-
},
|
396
|
-
});
|
397
|
-
}
|
398
|
-
} catch (err) {
|
399
|
-
res.send({
|
400
|
-
message: "Change password api fail",
|
401
|
-
status: "false",
|
402
|
-
sessionExist: "0",
|
403
|
-
response: {
|
404
|
-
data: null
|
405
|
-
},
|
406
|
-
});
|
407
|
-
}
|
408
|
-
};
|
409
|
-
|
410
|
-
module.exports = {
|
411
|
-
userRegister,
|
412
|
-
userLogin,
|
413
|
-
userForgotpassword,
|
414
|
-
sendOTP,
|
415
|
-
resetpass,
|
416
|
-
changepassword,
|
417
|
-
};
|