Skip to content
Permalink
Browse files

6.로그인 구현

  • Loading branch information...
egoing committed Aug 12, 2018
1 parent b9399e4 commit 9927381d96f2493b0fccc6d51823372f0d0871c3
Showing with 17 additions and 23 deletions.
  1. +15 −21 lib/passport.js
  2. +2 −2 routes/auth.js
@@ -2,12 +2,6 @@ var db = require('../lib/db');

module.exports = function (app) {

var authData = {
email: 'egoing777@gmail.com',
password: '111111',
nickname: 'egoing'
};

var passport = require('passport'),
LocalStrategy = require('passport-local').Strategy;

@@ -20,30 +14,30 @@ module.exports = function (app) {
});

passport.deserializeUser(function (id, done) {
var user = db.get('users').find({id:id}).value();
console.log('deserializeUser',id, user);
var user = db.get('users').find({
id: id
}).value();
console.log('deserializeUser', id, user);
done(null, user);
});

passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'pwd'
},
function (username, password, done) {
console.log('LocalStrategy', username, password);
if (username === authData.email) {
if (password === authData.password) {
return done(null, authData, {
message: 'Welcome.'
});
} else {
return done(null, false, {
message: 'Incorrect password.'
});
}
function (email, password, done) {
console.log('LocalStrategy', email, password);
var user = db.get('users').find({
email: email,
password: password
}).value();
if (user) {
return done(null, user, {
message: 'Welcome.'
});
} else {
return done(null, false, {
message: 'Incorrect username.'
message: 'Incorrect user information.'
});
}
}
@@ -19,8 +19,8 @@ module.exports = function (passport) {
var html = template.HTML(title, list, `
<div style="color:red;">${feedback}</div>
<form action="/auth/login_process" method="post">
<p><input type="text" name="email" placeholder="email"></p>
<p><input type="password" name="pwd" placeholder="password"></p>
<p><input type="text" name="email" placeholder="email" value="egoing7777@gmail.com"></p>
<p><input type="password" name="pwd" placeholder="password" value="111111"></p>
<p>
<input type="submit" value="login">
</p>

0 comments on commit 9927381

Please sign in to comment.
You can’t perform that action at this time.