-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
259 lines (208 loc) · 6.87 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
248
249
250
251
252
253
254
255
// require('babel-register');
// var React = require('react');
// var ReactDOM = require('react-dom/server');
//var components = require('./public/components.js'); // change path later
//var HelloMessage = React.createFactory(components.HelloMessage); //???
var express = require('express');
var fs = require('fs');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var bourbon = require('node-bourbon');
var Parse = require('parse/node');
var React = require('react');
var ReactDOM = require('react-dom');
var ReactBootstrap = require('react-bootstrap');
var TagsInput = require('react-tagsinput');
var Loading = require('react-loading');
var socket_io = require( "socket.io" );
var exphbs = require('express-handlebars');
var aws = require('aws-sdk');
var s3 = new aws.S3();
var passport = require('passport');
var LocalStrategy = require('passport-local');
var helmet = require('helmet')
var dbconfig = require('./config/configs');
var app = express();
var io = socket_io();
app.io = io;
Parse.initialize(dbconfig.db_name, dbconfig.username, dbconfig.password);
Parse.serverURL = dbconfig.url;
aws.config.update({
accessKeyId: "XXXXX",
secretAccessKey: "XXXXXX"
});
// view engine setup
// Configure express to use handlebars templates
var hbs = exphbs.create({
defaultLayout: 'main', //we will be creating this layout shortly
partialsDir: [
'views/'
]
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(cookieParser());
app.use(session({
secret: "SYNCHOLARTOKEN",
// store: todo,
proxy: true,
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
/*
* ROUTES
*/
require('./routes/routes')(app,Parse,io);
require('./routes/organization')(app,Parse,io);
require('./routes/user')(app,Parse,io);
require('./routes/gettingstarted')(app,Parse,io);
require('./routes/equipment')(app,Parse,io);
require('./routes/project')(app,Parse,io);
require('./routes/publication')(app,Parse,io);
require('./routes/data')(app,Parse,io);
require('./routes/model')(app,Parse,io);
require('./routes/newsfeed')(app,Parse,io);
require('./routes/search')(app,Parse,io);
require('./routes/group')(app,Parse,io);
require('./routes/report')(app,Parse,io);
require('./routes/discussion')(app,Parse,io);
require('./routes/notification')(app,Parse,io);
require('./routes/widget')(app,Parse,io);
/*
* SOCKET IO
*/
io.on('connection', function(socket){
socket.on('registerUser', function (data) {
socket.join(data.userId,function(){
console.log(socket.rooms);
});
});
socket.on("friendrequest",function(data){
console.log("hahaha");
console.log(data);
});
});
//===============PASSPORT=================
// Use the LocalStrategy within Passport to login/�signin� users.
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
},function(email, password, done) {
var query = new Parse.Query(Parse.User);
query.equalTo("email", email);
query.first({
success: function (user) {
if(user === undefined)
{
return done(null, false, {message: 'Invalid username or password'});
}
else {
Parse.User.logIn(user.get("username"), password, {
success: function(user) {
return done(null, user.attributes.username);
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
return done(null, false, {message: 'Invalid username or password'});
}
});
}
},
error: function(user,error){
console.log(error.message);
}
});
}));
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(username, done) {
var query = new Parse.Query(Parse.User);
query.equalTo("username", username);
query.first({
success: function (user) {
var jsonUser={
id: user.id,
username: user.attributes.username,
cover_imgURL:user.attributes.cover_imgURL,
email: user.attributes.email,
about: user.attributes.about,
emailVerified: user.attributes.emailVerified,
fullname:user.attributes.fullname,
firstname:user.attributes.firstname,
lastname: user.attributes.lastname,
imgUrl:user.attributes.picture.url(),
summary:user.attributes.summary,
interests:user.attributes.interests,
interestsTag:user.attributes.interestsTag,
educations: user.attributes.educations,
workExperience: user.attributes.workExperience,
projects:user.attributes.projects,
linkedin_id:user.attributes.linkedin_id,
signup_steps:user.attributes.signup_steps,
last_seen_notification:user.attributes.last_seen_notification
};
done(null, jsonUser);
}
,error:function(user,error)
{
console.log("Error in deserialize user: "+error.message);
}
});
});
app.use(helmet.frameguard({
action: 'allow-from',
domain: '*'
}))
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next){
var err = req.session.error,
msg = req.session.notice,
success = req.session.success;
delete req.session.error;
delete req.session.success;
delete req.session.notice;
if (err) res.locals.error = err;
if (msg) res.locals.notice = msg;
if (success) res.locals.success = success;
next();
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;