-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemp
185 lines (160 loc) · 4.24 KB
/
temp
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
User.findOne({
linkedinId: profile.id
}, (err, user)=>{
if(err){
return done(err);
}
//No user was found, Create new
if(!user){
user = new User({
linkedinId: profile.id,
name: profile.displayName,
email: profile.emails
});
user.save((err)=>{
if(err){
console.log(err);
return done(err, user);
}
});
} else{
//found user. return
return done(err, user);
}
});
redirect user.id route
// Serialize
passport.serializeUser((user, done)=> {
done(null, user.id);
});
// Deserialize
passport.deserializeUser((id, done)=>{
User.findById(id).then((user)=>{
done(null, user);
});
});
Form routes
// Form1
router.get('/login/create-user/:user/form-1', (req, res)=>{
const data = {
title: 'Age & Gender, Location Form'
user: req.user
}
res.render('form1', {user: req.user});
});
router.post('/login/create-user/:user._id/form-1', (req, res)=>{
// Get Params & Into Database
res.redirect('/auth/login/create-user/:user._id/form-2');
});
// Form2
router.get('/login/create-user/:user._id/form-2', (req, res)=>{
res.render('form2');
});
router.post('/login/create-user/:user._id/form-2', (req, res)=>{
// Get Params & Into Database
// Redirect Form3
res.redirect('/auth/login/create-user/:user._id/form-3');
});
// Form3
router.get('/login/create-user/:user._id/form-3', (req, res)=>{
res.render('form3');
});
router.post('/login/create-user/:user._id/form-3', (req, res)=>{
// Get Params & Into Database
// Redirect Form4
res.redirect('/auth/login/create-user/:user._id/form-4');
});
// Form4
router.get('/login/create-user/:user._id/form-4', (req, res)=>{
res.render('form4');
});
router.post('/login/create-user/:user._id/form-4', (req, res)=>{
// Get Params & Into Database
//
// isComplated = True
// Redirect Index
res.redirect('/');
});
Form Kontrol
if (!User.isComplated) {
console.log(req.user);
const user = req.user._id
res.redirect('/auth/login/create-user/:user');
} else {
console.log(req.user);
res.redirect('/');
}
typeof profile._json.pictureUrl.values === 'undefined'
Question.find({},(err,question)=>{
{
for(i=0;i<question.length;i++)
{
arranswer[i]=req.body[question[i].question.tr]
console.log(req.body[question[i]]);
// newPost.targetReceivers.push(req.body[question[i].question.tr]);
// Post.update({_id: newPost._id},{
// $push: {
// questionId: ,
// selectedAnswer: req.body[question[i].question.tr]
// }
// })
}
Answer.find({answer:{$in:arranswer}},(err,answer)=>{
for(i=0;i<answer.length;i++)
{
User.find({_id:answer[i].userId},(err,user)=>{
console.log(user);
})
}
})
}
// let questionAndAnswers = []
// for (var i = 0; i < data.length; i++) {
// if(data[i][0] != "body" && data[i][0] != "title" && data[i][0] != "isRepliable" && data[i][0] != "isPrivate"){
// let question = data[i][0];
// let answer = data[i][1];
// let questionAndAnswerArray = [question, answer];
// questionAndAnswers.push(questionAndAnswerArray);
// }
// }
// let usersArray = []
// questionAndAnswers.forEach((data)=>{
// User.find({
// $and : [{"answeredQuestions.answer": data[1]}]
// }, (err, user) => {
// if (err) console.log(err);
// })
// }, (user) => {
// res.redirect('/');
//
// })
let update = {
// "$inc": {"inbox.$.itemCount": 1},
"$push" : {
"inbox.$.mail" : createdPost._id,
"inbox" :{
"$set":
{
"inbox.$.isDeleted" : false,
"inbox.$.isArchived" : false,
"inbox.$.isDraft" : false,
"inbox.$.isSpam" : false,
"inbox.$.isDeleted" : false,
"inbox.$.isReaded" : false,
}
}
}
};
for (var i = 0; i < data.length; i++) {
let questionAndAnswers = {'question': data[i][0], 'answer': data[i][1]}
User.findOneAndUpdate({'_id': req.user._id},
{$push: {answeredQuestions: questionAndAnswers}
}, (err, updatedUser) => {
if(err){
console.log(err);
} else {
console.log(updatedUser);
res.redirect('/profile');
}
})
}