8 ๊ธ ๋ณด์ - 1 ์์ 8 ๊น์ง (์ด 8 ์ค์์)
-
๊ธ์ด์ด๊ธ
-
2022๋ 11์ 14์ผ 16:19 #53947

themapa์ฐธ๊ฐ์๋ก๊ทธ์ธ์ ์คํจํ์ ๊ฒฝ์ฐ ์๋์ ๋์ฐ๋ ๊ธฐ๋ฅ์ ๋ง๋ค๋ ค๊ณ $('.btn').click(function(){ $.ajax({ method : 'POST', url : '/', data : {id : String($('.id').val()), pw : String($('.pw').val())}, }).done((๊ฒฐ๊ณผ) => { window.location.replace('/login_success') }).fail((xhr,code,err) => { window.location.replace('/') }) }) passport.authenticate('local')์ passport.authenticate('local', (err, user, info) => { console.log(info.message) ... }) ๋ก ๋ณ๊ฒฝํด์ message๋ฅผ ๊ฐ์ ธ์ค๋ ์ง ํ์ธํ๊ณ ๋ก๊ทธ์ธ ์๋๋ฅผ ํ๋ ์ ๋๋ ๋ก๊ทธ์ธ์ด ์๋๊ณ crbug/1173575, non-JS module files deprecated ๋ฐ์ํฉ๋๋ค. passport.authenticate์ ์ธ์๋ฅผ ์ถ๊ฐํ ๋ ๋ฐ๋ก ์ค์ ํด์ผํ๋ ๊ฒ์ด ์๋๊ฑด๊ฐ์?? ์ ํ๋ธ๋ก ์์ ๋ค์ผ๋ฉด์ ์ฝ๋ฉํด์ ์ธํฐ๋ท ๋ฌธ์ ๋ ์๋๋ฐ passport๋ฅผ ์์ ํด์ผํ๋์??2022๋ 11์ 14์ผ 19:39 #53969
codingappleํค ๋ง์คํฐconsole.log(info.message) ๋ฃ์ ๋๋ง ์ด์ํด์ง๋๊ฑฐ๋ฉด info์ .message๊ฐ ์๊ฑฐ๋ ๊ทธ๋ฐ๊ฒฝ์ฐ๊ฐ๊ณ ์๋๋ฉด ์ปดํจํฐ ๊ป๋ค์ผญ์๋ค
2022๋ 11์ 15์ผ 17:04 #54156
themapa์ฐธ๊ฐ์์ค๊ฐ์ message๋ฅผ ์๋ณด๋ธ ๊ฒ ์์ด์ message๋ค ๋ณด๋ด๊ฒํ๋ ๊ณ์ ๋ก๋ฉ์ค์ผ๋ก ๋ค์ ํ์ด์ง๋ก ๋์ด๊ฐ์ง ์์ต๋๋ค. console.log(info.message)ํ๋ ํฐ๋ฏธ๋์ฐฝ์ ์ ๋์ค๋ ๊ฑธ ํ์ธํ์ต๋๋ค. ์ ์๋ message๋ฅผ ๋๊ธฐ๋ ค๋ฉด ์๋ต.status(400).send({message : '์ด๋ฏธ ์ฌ์ฉ์ค์ธ ์์ด๋์ ๋๋ค.'}) ์ด๋ฐ์ฉ์ผ๋ก ์ฝ๋๋ฅผ ์ง์ผํ ๊ฑฐ ๊ฐ์๋ฐ (err, user, info) => { console.log(info.message) ์ด๊ฑฐ ์์ฐ๊ณ message๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ด ์๋์???2022๋ 11์ 15์ผ 20:30 #54179
codingappleํค ๋ง์คํฐconsole.log(info.message) ๋ฐ์ ์๋ต.send ์ด์ฉ๊ตฌ๋ ๊ฐ์ด์ฐ๋ฉด ๋ ๋ฏ์
2022๋ 11์ 16์ผ 17:49 #54329
themapa์ฐธ๊ฐ์app.post('/', passport.authenticate('local', {failureRedirect : '/', successRedirect: '/login_success', failureMessage: true}), function(์์ฒญ, ์๋ต){ ์๋ต.status(200).send({message : "๋ก๊ทธ์ธํ์ต๋๋ค."}) })์ ์๋ ์์ ์ฝ๋๋ก ์ ๊ฐ ๋ผ์ฐํ ์ ํ๊ณ ์์ต๋๋ค. ๋ก๊ทธ์ธ์ด ์คํจํ ๊ฒฝ์ฐ์๋ function์ชฝ์ด ์๋์ด ์ํ๋ ๊ฑธ๋ก ์๊ณ ์์ต๋๋ค. ์๋ต.send๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด function ๋ค์ ์์ฑํด์ผํ๋๋ฐ ์ด๋ป๊ฒํด์ผํ ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋ค๋ฅธ ๋ฐฉ๋ฒ์ด ์๋ ์ฐพ์๋ณด๋ค๊ฐ connect-flash์ฐ๋ฉด ๋๋ค๊ณ ํ๊ธธ๋ ์ด๊ฒ๋ ๋ณด๋๊น ์๋ต.send๋ฅผ ํด์ผํ๋ ๊ฑฐ๋๋ผ๊ตฌ์ใ ใ
2022๋ 11์ 17์ผ 09:37 #54414
codingappleํค ๋ง์คํฐajax๋ก ๋ณด๋ด๋๊ฑฐ๋ฉด ๋ฏธ๋ค์จ์ด๋ก ์ฐ์ง๋ง๊ณ app.post('/login', function (์์ฒญ, ์๋ต) { passport.authenticate('local', {}, function(error, user, msg){ if (!user) { ์๋ต.send('fail') } else { ์์ฒญ.login(user, function(err){ if(err){ return next(err); } ์๋ต.send('success') }); } })(์์ฒญ, ์๋ต); }); ์ด๋ฐ๊ฑฐ ์์๋ค2022๋ 11์ 24์ผ 16:24 #55438
themapa์ฐธ๊ฐ์์ ์๋ ์ฌ๋ ค์ฃผ์ ์ฝ๋๋ฅผ ์์ ํด์ ๊ธฐ๋ฅ์ ๊ตฌํํ์ต๋๋ค. ์์ฒญ.login <- ์๋ ์ด๋ป๊ฒ ์๋ํ๋ ํจ์์ธ๊ฐ์?? ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ ๊ฒฝ์ฐ ์ ์ ์ id๋ฅผ ์ด์ฉํด์ 5๋ฒ ์ด์ ํ๋ฆด์ ์์ด๋๋ฅผ ์ ์์ ๋ง์๋ ค๊ณ ํ๊ณ ์์ต๋๋ค. ๊ทธ๋์ passport์์ ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ ๊ฒฝ์ฐ false ๋ฐํํ๋ ๊ฑธ ๊ฒฐ๊ณผ๋ก ๋ฐ๊ฟจ๋๋ ๋ก๊ทธ์ธ์ด ์๋๋ค์ใ ใ
app.post('/', function (์์ฒญ, ์๋ต) { passport.authenticate('local', {}, function(error, user, msg){ if (user !== "๋ก๊ทธ์ธ์ฑ๊ณตํ์ด์") { if(msg.message === "๋น๋ฒํ๋ ธ์ด์"){ console.log(msg) } ์๋ต.status(400).send({message : msg}) } else { ์์ฒญ.login(user, function(err){ if(err){ ์๋ต.status(400).send({message : msg}) return next(err) } ์๋ต.status(200).send({name : user}) }); } })(์์ฒญ, ์๋ต); });passport.use(new LocalStrategy({ usernameField: 'id', passwordField: 'pw', session: true, passReqToCallback: false, }, function (์ ๋ ฅํ์์ด๋, ์ ๋ ฅํ๋น๋ฒ, done) { db.collection('user').findOne({ id: ์ ๋ ฅํ์์ด๋ }, function (์๋ฌ, ๊ฒฐ๊ณผ) { // ์๋ฌํ์ธ if (์๋ฌ) return done(์๋ฌ, {message: '์๋ฌ๊ฐ ์์ต๋๋ค.'})// ์์ด๋ ํ์ธ if (!๊ฒฐ๊ณผ) return done(null, false, { message: '์กด์ฌํ์ง์๋ ์์ด๋์ ๋๋ค' })// ๋น๋ฐ๋ฒํธ ํ์ธ // ์ํธ๋ณต๊ตฌ let userPW = ๊ฒฐ๊ณผ.pw let bytes = CryptoJS.AES.decrypt(userPW, secretKey) let decrypted = JSON.parse(bytes.toString(CryptoJS.enc.Utf8)) console.log('์ํธ๋ณต๊ตฌ : ' + decrypted)if (์ ๋ ฅํ๋น๋ฒ == decrypted) { return done(null, ๊ฒฐ๊ณผ, {message : "๋ก๊ทธ์ธ์ฑ๊ณตํ์ด์"}) } else { return done(null, ๊ฒฐ๊ณผ, { message: '๋น๋ฒํ๋ ธ์ด์' }) } }) }));2022๋ 11์ 24์ผ 19:54 #55470
codingappleํค ๋ง์คํฐ์ฌ์ฉ๋ฒ์ ์๋ง ๊ณต์๋ฌธ์์ ๋์์์ต๋๋ค ๋ก๊ทธ์ธ์์ผ์ฃผ๋ ํจ์์ ๋๋ค done ํจ์์ false๋ ๊ฑด๋๋ฆฌ์ง ๋ง์๋ค
-
๊ธ์ด์ด๊ธ
8 ๊ธ ๋ณด์ - 1 ์์ 8 ๊น์ง (์ด 8 ์ค์์)
- ๋ต๋ณ์ ๋ก๊ทธ์ธ ํ ๊ฐ๋ฅํฉ๋๋ค.
