routes-account.js 17.8 KB
Newer Older
1
2
3
4
const fs = require('fs')
const SamlStrategy = require('passport-saml').Strategy
const dbconn = require('./dbconn')
const methods = require('./methods')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
5
// pwd encryption
6
7
8
const bcrypt = require('bcryptjs');
const saltRounds = 10;
const salt = 64; // salt length
Rosanny Sihombing's avatar
Rosanny Sihombing committed
9
// forgot pwd
10
11
const async = require('async')
const crypto = require('crypto')
Wolfgang Knopki's avatar
Wolfgang Knopki committed
12
const mailer = require('./mailer')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
13

14
module.exports = function (app, config, passport, i18n) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
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

  // =========== PASSPORT =======
  passport.serializeUser(function (user, done) {
    done(null, user);
  });

  passport.deserializeUser(function (user, done) {
    done(null, user);
  });

  var samlStrategy = new SamlStrategy({
      // URL that goes from the Identity Provider -> Service Provider
      callbackUrl: config.passport.saml.path,
      // Base address to call logout requests
      logoutUrl: config.passport.saml.logoutUrl,
      
      entryPoint: config.passport.saml.entryPoint,
      issuer: config.passport.saml.issuer,
      identifierFormat: null,
      
      // Service Provider private key
      decryptionPvk: fs.readFileSync(__dirname + '/cert/key.pem', 'utf8'),
      // Service Provider Certificate
      privateCert: fs.readFileSync(__dirname + '/cert/key.pem', 'utf8'),
      // Identity Provider's public key
      cert: fs.readFileSync(__dirname + '/cert/cert_idp.pem', 'utf8'),
      
      validateInResponseTo: false,
      disableRequestedAuthnContext: true
44
45
46
47
48
49
50
51
  },
  function (profile, done) {
    return done(null, {
      id: profile.nameID,
      idFormat: profile.nameIDFormat,
      email: profile.email,
      firstName: profile.givenName,
      lastName: profile.sn
Rosanny Sihombing's avatar
Rosanny Sihombing committed
52
    });
53
  });
Rosanny Sihombing's avatar
Rosanny Sihombing committed
54
55
  
  passport.use(samlStrategy);
56
57
58
59
60

  // ============= SAML ==============
  app.post(config.passport.saml.path,
    passport.authenticate(config.passport.strategy,
      {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
61
        failureRedirect: '/',
62
63
64
        failureFlash: true
      }),
    function (req, res) {
65
      res.redirect('/account/');
66
67
68
69
70
71
72
73
74
75
76
    }
  );

  // to generate Service Provider's XML metadata
  app.get('/saml/metadata', 
    function(req, res) {
      res.type('application/xml');
      var spMetadata = samlStrategy.generateServiceProviderMetadata(fs.readFileSync(__dirname + '/cert/cert.pem', 'utf8'));
      res.status(200).send(spMetadata);
    }
  );
Wolfgang Knopki's avatar
Wolfgang Knopki committed
77
78
79
80
81
82
  
  // ================ test i18n ==================
  i18n.setLocale('de');
  app.get('/de', function(req, res) {
    var greeting = i18n.__('Hello World')
    res.send(greeting)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
83
  });
84
  
Wolfgang Knopki's avatar
Wolfgang Knopki committed
85
  var lang = 'DE'
86

Wolfgang Knopki's avatar
Wolfgang Knopki committed
87
  // ======== APP ROUTES - ACCOUNT ====================
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
88
89
90
91
92
93
94
95
96
  var updatePasswordMailSubject = "Ihr Passwort für das Transferportal wurde gespeichert."
  var mailSignature = "Mit den besten Grüßen,\ndas Transferportal-Team der HFT Stuttgart\n\n"+
    "Transferportal der Hochschule für Technik Stuttgart\n"+
    "Schellingstr. 24\n"+
    "70174 Stuttgart\n"+
    "m4lab@hft-stuttgart.de\n"+
    "https://transfer.hft-stuttgart.de"
  var updatePasswordMailContent = "Lieber Nutzer,\n\n"+"Ihr Passwort wurde erfolgreich geändert.\n\n"+mailSignature

Rosanny Sihombing's avatar
Rosanny Sihombing committed
97
  app.get('/', function (req, res) {
98
99
100
    if (req.isAuthenticated()) {
      methods.getUserByEmail(req.user.email, function(data, err){
        if (!err) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
101
          res.render(lang+'/account/home', {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
102
            user: data
103
104
105
106
          });
        }
      })
    } else {
107
      res.redirect('/account/login'); // localhost
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
108
    } 
Rosanny Sihombing's avatar
Rosanny Sihombing committed
109
110
111
  });

  app.get('/error', function (req, res) {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
112
    res.render(lang+'/error')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
113
114
115
116
117
  });

  app.get('/login',
    passport.authenticate(config.passport.strategy,
      {
118
        successRedirect: '/',
119
        failureRedirect: '/login'
Rosanny Sihombing's avatar
Rosanny Sihombing committed
120
121
122
      })
  );

123
124
  app.get('/logout', function (req, res) {
    if (req.user == null) {
125
      return res.redirect('/account/');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
126
    }
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    
    req.user.nameID = req.user.id;
    req.user.nameIDFormat = req.user.idFormat;
    return samlStrategy.logout(req, function(err, uri) {
      req.logout();
      
      if ( req.session ) {
        req.session.destroy((err) => {
          if(err) {
              return console.log(err);
          }
        });
      }
     
      return res.redirect(uri);
    });
  });
Rosanny Sihombing's avatar
Rosanny Sihombing committed
144
145

  app.get('/profile', function (req, res) {
146
147
148
    if (req.isAuthenticated()) {
      methods.getUserByEmail(req.user.email, function(data, err){
        if (!err) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
149
          res.render(lang+'/account/profile', {
150
151
152
153
154
            user: data,
            email: req.user.email
          });
        }
      })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
155
    } else {
156
      res.redirect('/account/login');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
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
    }
  });

  app.get('/services', function (req, res) {
    if (req.isAuthenticated()) {
      async.waterfall([
        // get userId by email from userdb
        function(done) {
          methods.getUserIdByEmail(req.user.email, function(userId, err) {
            if (!err) {
              done(err, userId)
            }
          })
        },
        // get user-project-role from userdb
        function(userId, done) {
          methods.getUserProjectRole(userId, function(userProjects, err) {
            if (!err) {
              done(err, userProjects)
            }
          })
        },
        // get all projects from projectdb
        function(userProjects, done) {
          methods.getAllProjects(function(projectsOverview, err) {
            if (!err) {
              done(err, userProjects, projectsOverview)
            }
          })
        },
        // create JSON object of projects and user status for front-end
        function(userProjects, projectsOverview, done) {
          var allProjects = []  // JSON object
          
          var userProjectId = []  // array of user's project_id
          for (var i = 0; i < userProjects.length; i++) {
            userProjectId.push(userProjects[i].project_id)
          }

          for (var i = 0; i < projectsOverview.length; i++) {
            // check if projectId is exist in userProjectId[]
Rosanny Sihombing's avatar
Rosanny Sihombing committed
198
            var status = false
Rosanny Sihombing's avatar
Rosanny Sihombing committed
199
            if (userProjectId.indexOf(projectsOverview[i].id) > -1) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
200
              status = true
Rosanny Sihombing's avatar
Rosanny Sihombing committed
201
202
203
204
205
206
207
208
209
210
211
212
            }
            // add data to JSON object
            allProjects.push({
              id: projectsOverview[i].id,
              title: projectsOverview[i].title,
              summary: projectsOverview[i].onelinesummary,
              cp: projectsOverview[i].contact_email,
              userStatus: status
            });
          }

          // render the page
Rosanny Sihombing's avatar
Rosanny Sihombing committed
213
          res.render(lang+'/account/services', {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
214
215
216
217
218
219
            user: req.user,
            project: allProjects
          });
        }
      ])
    } else {
220
      res.redirect('/account/login');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
221
222
223
224
225
    }
  });

  app.get('/security', function (req, res) {
    if (req.isAuthenticated()) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
226
      res.render(lang+'/account/security', {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
227
228
229
        user: req.user // useful for view engine, useless for HTML
      });
    } else {
230
      res.redirect('/account/login');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
231
232
233
234
235
    }
  });

  app.post('/updateProfile', function (req, res) {
    var userData = {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
236
      salutation: req.body.inputSalutation,
Rosanny Sihombing's avatar
Rosanny Sihombing committed
237
238
239
240
241
242
243
244
245
246
247
      title: req.body.inputTitle,
      firstname: req.body.inputFirstname,
      lastname: req.body.inputLastname,
      email: req.body.inputEmail,
      organisation: req.body.inputOrganisation,
      industry: req.body.inputIndustry,
      speciality: req.body.inputSpeciality,
    }
    
    if (req.isAuthenticated()) {
      if (userData.email) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
248
        dbconn.user.query('UPDATE user SET ? WHERE email = "' +userData.email+'"', userData, function (err, rows, fields) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
249
250
251
252
253
254
255
            //if (err) throw err;
            if (err) {
              req.flash('error', "Failed");
            }
            else {
              req.flash('success', 'Profile updated!');
            }
256
            res.redirect('lang+/account/profile');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
257
258
259
        })
      }
    } else {
260
      res.redirect('/account/login');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
261
262
263
264
265
266
267
268
269
    }
  });
  
  app.post('/changePwd', function (req, res) {
    if (req.isAuthenticated()) {
      var currPwd = req.body.inputCurrPwd
      var newPwd = req.body.inputNewPwd
      var retypePwd = req.body.inputConfirm

270
271
272
273
274
      methods.getUserIdByEmail(req.user.email, function(userId, err) {
        if (!err) {
          // Load hashed passwd from DB
          dbconn.user.query('SELECT password FROM credential WHERE user_id='+userId, function (err, rows, fields) {
            if (err) {
275
              res.redirect('/account/500')
276
              throw err
Rosanny Sihombing's avatar
Rosanny Sihombing committed
277
            }
278
279
280
281
282
            var userPwd = rows[0].password

            // check if the password is correct
            bcrypt.compare(currPwd, userPwd, function(err, isMatch) {
              if (err) {
283
                res.redirect('/account/500')
284
285
286
                throw err
              }
              else if (!isMatch) {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
287
288
                //req.flash('error', "Sorry, your password was incorrect. Please double-check your password.")
                req.flash('error', "Das Passwort ist leider falsch. Bitte überprüfen Sie Ihre Eingabe.")
289
290
                //res.redirect('/account/security')
                res.redirect('/account/security')
291
292
293
294
              }
              else {
                if ( newPwd != retypePwd ) {
                  req.flash('error', "Passwords do no match. Please make sure you re-type your new password correctly.")
295
                  res.redirect(lang+'/account/security')
296
297
298
299
300
301
302
303
304
305
306
                }
                else {
                  // update password
                  bcrypt.genSalt(saltRounds, function(err, salt) {
                    bcrypt.hash(newPwd, salt, function(err, hash) {
                      var credentialData = {
                        password: hash,
                        user_id: userId
                      }
                      methods.updateCredential(credentialData, function(err){
                        if (err) {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
307
308
                          //req.flash('error', "Database error: Password cannot be modified.")
                          req.flash('error', "Datenbankfehler: Passwort kann nicht geändert werden.")
309
310
311
                          throw err
                        }
                        else {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
312
313
                          //req.flash('success', "Pasword updated!")
                          req.flash('success', "Passwort aktualisiert!")
Wolfgang Knopki's avatar
Wolfgang Knopki committed
314
                          mailer.options.to = req.user.email
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
315
                          //mailOptions.subject = "Your M4_LAB Password has been updated."
Wolfgang Knopki's avatar
Wolfgang Knopki committed
316
317
318
                          mailer.options.subject = updatePasswordMailSubject
                          mailer.options.text = updatePasswordMailContent
                          mailer.transport.sendMail(mailer.options, function(err) {
319
320
321
322
                            if (err) {
                              console.log(err)
                            }
                          });
323
                        }
324
                        res.redirect('/account/security')
325
326
327
328
329
330
                      })
                    });
                  });
                }
              }
          }) 
Rosanny Sihombing's avatar
Rosanny Sihombing committed
331
        })
332
333
334
335
        }
      })  
    }
    else {
336
      res.redirect('/account/login');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
337
338
339
340
    }
  });

  app.get('/forgotPwd', function (req, res) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
341
    res.render(lang+'/account/forgotPwd', {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
342
343
344
345
346
347
      user: req.user
    });
  });

  app.post('/forgotPwd', function(req, res, next) {
    //methods.currentDate();
348

Rosanny Sihombing's avatar
Rosanny Sihombing committed
349
    var emailAddress = req.body.inputEmail;
350
  /*  var emailContent = "Hi there,\n\n"+
Rosanny Sihombing's avatar
Rosanny Sihombing committed
351
352
      "we've received a request to reset your password. However, this email address is not on our database of registered users.\n\n"+
      "Thanks,\nM4_LAB Team";
353
    var emailSubject = "Account Access Attempted"; */
Rosanny Sihombing's avatar
Rosanny Sihombing committed
354
355
356
357
358
359
360
361
362
363
364
365
    
    async.waterfall([
      function(done) {
        crypto.randomBytes(20, function(err, buf) {
          var token = buf.toString('hex');
          done(err, token);
        });
      },
      function(token, done) {
        methods.checkUserEmail(emailAddress, function(err, user){
          if (user) {
            console.log("email: user found");
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
366
367
368
            //var emailSubject = "M4_LAB Password Reset";
            var emailSubject = "Ihre Passwort-Anfrage an das Transferportal der HFT Stuttgart";
            /* var emailContent = "Hi User,\n\n"+
Rosanny Sihombing's avatar
Rosanny Sihombing committed
369
              "we've received a request to reset your password. If you didn't make the request, just ignore this email.\n\n"+
370
              "Otherwise, you can reset your password using this link: http://m4lab.hft-stuttgart.de/account/reset/" + token + "\n" +
Rosanny Sihombing's avatar
Rosanny Sihombing committed
371
              "This password reset is only valid for 1 hour.\n\n"+
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
372
373
374
              "Thanks,\nM4_LAB Team" */
            var emailContent = "Lieber Nutzer,\n\n"+
              "wir haben Ihre Anfrage zur Erneuerung Ihres Passwortes erhalten. Falls Sie diese Anfrage nicht gesendet haben, ignorieren Sie bitte diese E-Mail.\n\n"+
Wolfgang Knopki's avatar
Wolfgang Knopki committed
375
376
              "Sie können Ihr Passwort mit dem Klick auf diesen Link ändern: http://m4lab.hft-stuttgart.de/account/reset/" + token + "\n" + // test server
              //"Sie können Ihr Passwort mit dem Klick auf diesen Link ändern: http://localhost:9989/reset/" + token + "\n" + // localhost
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
377
378
              "Dieser Link ist aus Sicherheitsgründen nur für 1 Stunde gültig.\n\n"+mailSignature

379
380
381
382
383
384
            var credentialData = {
              user_id: user.id,
              resetPasswordToken: token,
              resetPasswordExpires: Date.now() + 3600000 // 1 hour
            }
            methods.updateCredential(credentialData, function(err) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
385
386
              done(err, token, user);
            });
387
388

            // send email
Wolfgang Knopki's avatar
Wolfgang Knopki committed
389
390
391
392
            mailer.options.to = emailAddress;
            mailer.options.subject = emailSubject;
            mailer.options.text = emailContent;
            mailer.transport.sendMail(mailer.options, function(err) {
393
394
              done(err, 'done');
            });
Rosanny Sihombing's avatar
Rosanny Sihombing committed
395
396
          }
          else {
397
398
            //done(err, null, null);
            done(err, 'no user found');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
399
400
401
402
403
          }
        });
      }
    ], function(err) {
      if (err) {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
404
405
        //req.flash('error', 'An error occured. Please try again.');
        req.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
406
407
      }
      else {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
408
409
        //req.flash('success', 'If your email is registered, an e-mail has been sent to ' + emailAddress + ' with further instructions.');
        req.flash('success', 'Wenn Ihre E-Mail-Adresse registriert ist, wurde eine E-Mail mit dem weiteren Vorgehen an ' + emailAddress + ' versendet.');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
410
      }
411
412
      //res.redirect('/account/forgotPwd'); // deployment
      res.redirect('/account/forgotPwd'); // localhost
Rosanny Sihombing's avatar
Rosanny Sihombing committed
413
414
415
416
    });
  });

  app.get('/reset/:token', function(req, res) {
417
    methods.getUserByToken(req.params.token, function(err, user){
Rosanny Sihombing's avatar
Rosanny Sihombing committed
418
      if (!user) {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
419
420
        //req.flash('error', 'Password reset token is invalid or has expired.');
        req.flash('error', 'Der Schlüssel zum zurücksetzen des Passworts ist ungültig oder abgelaufen.');
421
422
        //res.redirect('/account/forgotPwd'); // deployment
        res.redirect('/account/forgotPwd'); // localhost
Rosanny Sihombing's avatar
Rosanny Sihombing committed
423
424
      }
      else {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
425
        res.render(lang+'/account/reset');
Rosanny Sihombing's avatar
Rosanny Sihombing committed
426
427
428
429
430
      }
    });
  });

  app.post('/reset/:token', function(req, res) {
Wolfgang Knopki's avatar
Wolfgang Knopki committed
431
    var newPwd = req.body.inputNewPwd  
432
    methods.getUserByToken(req.params.token, function(err, user){
Rosanny Sihombing's avatar
Rosanny Sihombing committed
433
      if (user) {
434
        // encrypt password
Rosanny Sihombing's avatar
Rosanny Sihombing committed
435
        bcrypt.genSalt(saltRounds, function(err, salt) {
Wolfgang Knopki's avatar
Wolfgang Knopki committed
436
          bcrypt.hash(newPwd, salt, function(err, hash) {
437
438
439
440
441
442
            var credentialData = {
              password: hash,
              user_id: user.user_id
            }
            // update password
            methods.updateCredential(credentialData, function(err){
Rosanny Sihombing's avatar
Rosanny Sihombing committed
443
              if (err) {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
444
445
                //req.flash('error', "Database error: Password cannot be modified.")
                req.flash('error', "Datenbankfehler: Passwort kann nicht geändert werden.")
Rosanny Sihombing's avatar
Rosanny Sihombing committed
446
447
448
                throw err
              }
              else {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
449
450
                //req.flash('success', "Your pasword has been updated.")
                req.flash('success', "Passwort aktualisiert!")
451
                // send notifiaction email
Wolfgang Knopki's avatar
Wolfgang Knopki committed
452
453
454
455
                mailer.options.to = user.email
                mailer.options.subject = updatePasswordMailSubject
                mailer.options.text = updatePasswordMailContent
                mailer.transport.sendMail(mailer.options, function(err) {
456
457
458
459
460
                  if (err) {
                    console.log(err)
                  }
                });
                // redirect to login page
461
                res.redirect('/account/login')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
462
463
464
465
466
467
468
              }
            })
          });
        });
      }
      else {
        req.flash('error', "User not found.")
469
        res.redirect('/account/login')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
470
471
472
473
474
      }
    });
   
  });

475
476
  // todo: user registration with captcha
  app.get('/registration', function(req, res) {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
477
    res.render(lang+'/account/registration')
478
479
480
481
482
483
484
485
486
487
  })

  app.post('/registration', function(req, res) {
    // TODO:
    // create gitlab account?
    // send email to activate profile?

    // user data
    var curDate = new Date()
    var userData = {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
488
      salutation: req.body.inputSalutation,
489
490
491
492
493
494
495
496
      title: req.body.inputTitle,
      firstname: req.body.inputFirstname,
      lastname: req.body.inputLastname,
      email: req.body.inputEmail,
      organisation: req.body.inputOrganisation,
      industry: req.body.inputIndustry,
      speciality: req.body.inputSpeciality,
      createdDate: curDate.toISOString().slice(0,10)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
497
    }
498
499
500
501
502
503
504
505
506
507
    // encrypt password
    bcrypt.genSalt(saltRounds, function(err, salt) {
      bcrypt.hash(req.body.inputPassword, salt, function(err, hash) {
        // create account
        var newAccount = {
          profile: userData,
          password: hash
        }
        methods.registerNewUser(newAccount, function(err){
          if (err) {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
508
509
            //req.flash('error', "Failed")
            req.flash('error', "Fehlgeschlagen")
Rosanny Sihombing's avatar
Rosanny Sihombing committed
510
          }
511
          else {
Rosanny Sihombing's avatar
DE    
Rosanny Sihombing committed
512
513
            //req.flash('success', 'Your account has been created. Please log in.')
            req.flash('success', 'Ihr Benutzerkonto wurde angelegt. Bitte melden Sie sich an.') 
514
          }
515
          res.redirect('/account/registration');
516
517
        })
      });
Rosanny Sihombing's avatar
Rosanny Sihombing committed
518
    });
519
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
520

521
522
523
524
525
526
527
528
529
530
531
532
  app.get('/email/:email', function(req, res) {
    methods.checkUserEmail(req.params.email, function(err, user){
      if (!err) {
        if (user) {
          res.send(false)
        }
        else {
          res.send(true)
        }  
      }
    })
  })
533
  
534
};