-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_visitor.js
80 lines (71 loc) · 2.25 KB
/
search_visitor.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
// require('server');
const mongoose =require("mongoose");
const passport = require('passport');
const passportLocalMongoose = require('passport-local-mongoose');
module.exports = function(app){
const User= mongoose.model("User");
app.get("/search_visitor",function(req,res){
res.redirect("/admin_profile");
});
app.post("/search_visitor",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.find({username:{ $regex: /^v/ }},function(err,check){
if(err)
console.log(err);
else{
// console.log(user.email);
res.render("admin_profile.ejs",{Admin_Name:req.user.name,details:check,visitor:user});
// res.redirect("/");
}
})
}
else{
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..
}