최정민

FEAT : 2차로그인 기능추가

session-file-store를 이용하여 회원가입 진행

-
This diff is collapsed. Click to expand it.
......@@ -10,8 +10,10 @@
"debug": "~2.6.9",
"ejs": "^3.1.6",
"express": "^4.16.4",
"express-session": "^1.17.1",
"google-auth-library": "^7.0.4",
"http-errors": "~1.6.3",
"morgan": "~1.9.1"
"morgan": "~1.9.1",
"session-file-store": "^1.5.0"
}
}
......
......@@ -3,6 +3,14 @@ var router = express.Router();
var {OAuth2Client} = require('google-auth-library');
var CLIENT_ID = "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com"
var client= new OAuth2Client(CLIENT_ID);
var session =require('express-session');
var FileStore=require('session-file-store')(session);
router.use(session({
secret: '209', // 암호화
resave: false,
saveUninitialized: true,
store: new FileStore()
}))
/* GET home page. */
router.get('/', function(req, res, next) {
......@@ -30,7 +38,16 @@ router.post('/index', (req, res) => {
router.get('/login', checkAuthenticated, (req,res )=>{
let user=req.user;
res.render('login', {user})
req.session.user=user;
res.render('login', {user:req.session.user})
});
router.post('/login' ,(req, res)=>{
console.log(req.body.nickname);
console.log(req.body.age);
console.log(req.body.gender);
return res.render('login', {user:req.session.user})
});
module.exports = router;
......@@ -58,7 +75,7 @@ function checkAuthenticated(req, res, next){
next();
})
.catch(err=>{
res.redirect('/login')
res.redirect('/index')
})
}
\ No newline at end of file
......
{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1620684562564,"user":{"name":"‍최정민[학생](소프트웨어융합대학 컴퓨터공학과)","email":"cjm2021401@khu.ac.kr","picture":"https://lh3.googleusercontent.com/a/AATXAJzFD3R6CaL2NpysVrfvdGqcQ83vh_wpbN_5hj-0=s96-c"}}
\ No newline at end of file
......@@ -8,8 +8,22 @@
</head>
<body>
<a href="/index" onclick="signOut();">Sign Out</a>
<h1>Hi <%= user.name %></h1>
<form method="post">
NickName:<br>
<input type="text" name="nickname" value="MickeyMouse"><br>
Age:<br>
<input type="text" name="age" value="19"><br><br>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="submit" value="Submit">
</form>
<a href="/index" onclick="signOut();">Sign Out</a>
</body>
<script>
......