Advertisement
Guest User

Untitled

a guest
Mar 4th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by edisoni on 04.03.16.
  3.  */
  4.  
  5. var express = require('express');
  6. var app = express();
  7. var port = 3000;
  8.  
  9. const jwt = require('jsonwebtoken');
  10. const passport = require('passport');
  11. const Strategy = require('passport-local');
  12. var morgan = require('morgan');
  13.  
  14. app.use(morgan('dev'));
  15. app.use(passport.initialize());
  16. app.use(passport.session());
  17.  
  18. passport.use(new Strategy(
  19.     function (username, password, done) {
  20.         console.log("Local");
  21.         if (username === 'Edisoni' && password === '666') {
  22.             done(null, {
  23.                 id: 666,
  24.                 firstname: 'Edisoni'
  25.             });
  26.         }
  27.         else {
  28.             done(null, false);
  29.         }
  30.     }
  31. ));
  32.  
  33. app.post('/auth', passport.authenticate('local'));
  34.  
  35. passport.serializeUser(function (user, done) {
  36.     done(null, user.id);
  37. });
  38.  
  39. passport.deserializeUser(function (id, done) {
  40.     done(err, {
  41.         id: id,
  42.         firstname: 'Edisoni'
  43.     });
  44. });
  45.  
  46.  
  47. app.listen(port, function () {
  48.     console.log('Listening on port ', port)
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement