-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisitor_update_by_admin.js
103 lines (92 loc) · 3.2 KB
/
visitor_update_by_admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// require('server');
const mongoose =require("mongoose");
const passport = require('passport');
const passportLocalMongoose = require('passport-local-mongoose');
var QRCode = require('qrcode')
module.exports = function(app){
const User= mongoose.model("User");
app.get("/visitor_update_by_admin",function(req,res){
res.redirect("/Profile");
});
app.post("/visitor_update_by_admin",function(req,res){
var username=req.body.username;
console.log(username);
console.log(req.user.name);
// username=username.slice(1,username.length);
// console.log(username);
User.findOne({username:username},function(err,user){
if(err)
{
console.log(err)
}
else{
if(user)
{
User.updateOne({username:req.body.username},{name:req.body.name,email:req.body.email,mobile:req.body.mobile,address:req.body.address,staus:req.body.status},function(){
User.find({username:{ $regex: /^v/ }},function(err,check){
if(err)
console.log(err);
else{
// console.log(user.email);
user={
"name":"",
"sex":"",
"username":"",
"address":"",
"email":"",
"mobile":"",
"aadhar":"",
"password":"",
"status":""
};
req.session.message={
type:'success',
intro:'Updated',
message:'Details updated successfully'
}
res.render("admin_profile.ejs",{Admin_Name:req.user.name,details:check,visitor:user,message:req.session.message});
// res.redirect("/");
}
})
// res.redirect("/profile");
});
}
else{
//USER DOES NPT EXIST MESSAGE
User.find({username:{ $regex: /^v/ }},function(err,check){
if(err)
console.log(err);
else{
user={
"name":"",
"sex":"",
"username":"",
"address":"",
"email":"",
"mobile":"",
"aadhar":"",
"password":"",
"status":""
};
User.find({username:{ $regex: /^v/ }},function(err,check){
if(err)
console.log(err);
else{
req.session.message={
type:'danger',
intro:'Invalid ID',
message:'Enter valid visitor ID'
}
res.render("admin_profile.ejs",{Admin_Name:req.user.name,details:check,visitor:user,message:req.session.message});
// res.alert("NOT VALID ID")
}
});
// res.alert("Enter valid id");
}
})
}
}
})
});
//other routes..
}