Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. /*
  2. * @Author: Adam Eaton
  3. * @Date: 2017-07-19 16:05:29
  4. * @Last Modified by: Adam Eaton
  5. * @Last Modified time: 2017-07-19 16:10:41
  6. */
  7.  
  8. // Define authen to use a callback function
  9. function authen(user, pass, cb) {
  10. ad.authenticate(user, pass, (err, auth) => {
  11. if (err) {
  12. console.log('ERROR: ' + JSON.stringify(err));
  13. } else if (auth) {
  14. console.log('Authenticated');
  15. } else {
  16. console.log('Authentication Failed');
  17. }
  18. cb(auth); // Pass auth to callback
  19. });
  20. }
  21.  
  22. // Use authen in Route
  23. app.post('/login', (req, res) => {
  24. let user = req.body.user + '@mbsbooks.com';
  25. let pass = req.body.pass;
  26. ad.authen(user, pass, (auth) => {
  27. if (auth) { // Successful Login
  28. res.sendFile('./public/html/initial.html');
  29. } else { // Unsuccessful Login
  30. res.sendFile('./public/html/login.html');
  31. }
  32. });
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement