-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
247 lines (207 loc) · 6.92 KB
/
app.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
var express = require('express');
var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var neo4j = require('neo4j-driver');
var app = express();
//Viev Engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
var driver = neo4j.driver('bolt://localhost', neo4j.auth.basic('neo4j', '123456'))
app.get('/', (req, res) => {
res.render('login')
})
//---------------------------------GETS----------------------------
//--------------ADMIN LOGIN
app.get('/adminLogin', (req, res) => {
var session = driver.session();
session
.run('MATCH(a:Arastirmaci) RETURN a LIMIT 25')
.then(result => {
var personArr = [];
result.records.forEach(record => {
personArr.push({
id: record._fields[0].identity.low,
name: record._fields[0].properties.name,
sname: record._fields[0].properties.sname,
YayinId: record._fields[0].properties.YayinId
})
//console.log(record._fields[0].properties);
})
session
.run('MATCH(y:Yayinlar) RETURN y LIMIT 25')
.then(result2 => {
var yayinArr = [];
result2.records.forEach(record => {
yayinArr.push({
id: record._fields[0].identity.low,
yName: record._fields[0].properties.yName,
yil: record._fields[0].properties.yil,
typeId: record._fields[0].properties.typeId
})
})
res.render('adminLogin', {
persons: personArr,
yayinlar: yayinArr
})
console.log(yayinArr);
})
.catch(err => {
console.log(err);
})
})
.catch(err => {
console.log(err);
})
})
//------------------USER LOGIN
app.get('/userLogin', (req, res) => {
var session6 = driver.session();
session6
.run('MATCH(a:Arastirmaci) RETURN a LIMIT 25')
.then(result => {
var personArr = [];
result.records.forEach(record => {
personArr.push({
id: record._fields[0].identity.low,
name: record._fields[0].properties.name,
sname: record._fields[0].properties.sname,
YayinId: record._fields[0].properties.YayinId
})
//console.log(record._fields[0].properties);
})
session6
.run('MATCH(y:Yayinlar) RETURN y LIMIT 25')
.then(result2 => {
var yayinArr = [];
result2.records.forEach(record => {
yayinArr.push({
id: record._fields[0].identity.low,
yName: record._fields[0].properties.yName,
yil: record._fields[0].properties.yil,
typeId: record._fields[0].properties.typeId
})
})
res.render('userLogin', {
persons: personArr,
yayinlar: yayinArr
})
console.log(yayinArr);
})
.catch(err => {
console.log(err);
})
})
.catch(err => {
console.log(err);
})
})
app.get('/neovis',(req,res)=>{
res.render('neovis');
})
//----------------------------------POST---------------------
//--------------ADMIN LOGIN
app.post('/admin/login', (req, res) => {
var session2 = driver.session();
var name = req.body.admin_name;
var pass = req.body.admin_password;
session2
.run('MATCH (a:Admin) WHERE a.name=$nameParam and a.pass=$passParam return a', { nameParam: name, passParam: pass })
.then(result => {
if (result.records.length > 0) {
res.redirect('../adminLogin');
} else {
console.log("Girilen bilgiler yanlis")
res.redirect('/');
}
session2.close();
})
.catch(err => {
console.log(err);
})
})
//----------------USER LOGIN
app.post('/user/login', (req, res) => {
var session5 = driver.session();
var name = req.body.user_name;
var pass = req.body.user_password;
session5
.run('MATCH (u:User) WHERE u.name=$nameParam and u.pass=$passParam return u', { nameParam: name, passParam: pass })
.then(result => {
if (result.records.length > 0) {
res.redirect('../userLogin');
} else {
console.log("Girilen bilgiler yanlis")
res.redirect('/');
}
session5.close();
})
.catch(err => {
console.log(err);
})
console.log("Girilen bilgiler yanlis")
})
//----------Arastirmaci ekleme
app.post('/person/add',(req,res)=>{
var session7 = driver.session();
var name = req.body.name;
var sname = req.body.sname;
var yayinId = req.body.yayinId;
session7
.run('CREATE (a:Arastirmaci {name:$nameParam,sname:$snameParam,YayinId:$yayinIdParam}) return a',{nameParam:name,snameParam:sname,yayinIdParam:yayinId})
.then( result => {
res.redirect('/adminLogin');
session7.close();
})
.catch(err => {
console.log(err);
})
res.redirect('/adminLogin');
})
//--------------Arastirmaci silme
app.post('/person/del',(req,res)=>{
var session8 = driver.session();
var name = req.body.name;
var sname = req.body.sname;
var yayinId = req.body.yayinId;
session8
.run('MATCH (a:Arastirmaci {name:$nameParam,sname:$snameParam}) delete a',{nameParam:name,snameParam:sname})
.then( result => {
res.redirect('/adminLogin');
session8.close();
})
.catch(err => {
console.log(err);
})
res.redirect('/adminLogin');
})
app.post('/person/rel',(req,res)=>{
var session9 = driver.session();
var name = req.body.name;
var yName = req.body.yName;
session9
.run('MATCH (a:Arastirmaci {name:$nameParam}),(b:Yayinlar {yName:$yNameParam}) MERGE (a)-[r:YAZAR]-(b)',{nameParam:name,yNameParam:yName})
.then(result => {
res.redirect('/adminLogin');
session9.close();
})
.catch(err => {
console.log(err);
})
})
app.post('/vis',(req,res)=>{
res.redirect('/neovis');
})
app.post('/back',(req,res)=>{
res.redirect('/adminLogin');
})
app.post('/exit',(req,res)=>{
res.redirect('/');
})
app.listen(3000);
console.log("Server Started on Port 3000");
module.exports = app;