최정민

FEAT : 2차로그인 기능추가

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

-
This diff is collapsed. Click to expand it.
...@@ -10,8 +10,10 @@ ...@@ -10,8 +10,10 @@
10 "debug": "~2.6.9", 10 "debug": "~2.6.9",
11 "ejs": "^3.1.6", 11 "ejs": "^3.1.6",
12 "express": "^4.16.4", 12 "express": "^4.16.4",
13 + "express-session": "^1.17.1",
13 "google-auth-library": "^7.0.4", 14 "google-auth-library": "^7.0.4",
14 "http-errors": "~1.6.3", 15 "http-errors": "~1.6.3",
15 - "morgan": "~1.9.1" 16 + "morgan": "~1.9.1",
17 + "session-file-store": "^1.5.0"
16 } 18 }
17 } 19 }
......
...@@ -3,6 +3,14 @@ var router = express.Router(); ...@@ -3,6 +3,14 @@ var router = express.Router();
3 var {OAuth2Client} = require('google-auth-library'); 3 var {OAuth2Client} = require('google-auth-library');
4 var CLIENT_ID = "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com" 4 var CLIENT_ID = "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com"
5 var client= new OAuth2Client(CLIENT_ID); 5 var client= new OAuth2Client(CLIENT_ID);
6 +var session =require('express-session');
7 +var FileStore=require('session-file-store')(session);
8 +router.use(session({
9 + secret: '209', // 암호화
10 + resave: false,
11 + saveUninitialized: true,
12 + store: new FileStore()
13 +}))
6 14
7 /* GET home page. */ 15 /* GET home page. */
8 router.get('/', function(req, res, next) { 16 router.get('/', function(req, res, next) {
...@@ -30,7 +38,16 @@ router.post('/index', (req, res) => { ...@@ -30,7 +38,16 @@ router.post('/index', (req, res) => {
30 38
31 router.get('/login', checkAuthenticated, (req,res )=>{ 39 router.get('/login', checkAuthenticated, (req,res )=>{
32 let user=req.user; 40 let user=req.user;
33 - res.render('login', {user}) 41 + req.session.user=user;
42 + res.render('login', {user:req.session.user})
43 +});
44 +
45 +router.post('/login' ,(req, res)=>{
46 +
47 + console.log(req.body.nickname);
48 + console.log(req.body.age);
49 + console.log(req.body.gender);
50 + return res.render('login', {user:req.session.user})
34 }); 51 });
35 module.exports = router; 52 module.exports = router;
36 53
...@@ -58,7 +75,7 @@ function checkAuthenticated(req, res, next){ ...@@ -58,7 +75,7 @@ function checkAuthenticated(req, res, next){
58 next(); 75 next();
59 }) 76 })
60 .catch(err=>{ 77 .catch(err=>{
61 - res.redirect('/login') 78 + res.redirect('/index')
62 }) 79 })
63 80
64 } 81 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +{"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 ...\ No newline at end of file
...@@ -8,8 +8,22 @@ ...@@ -8,8 +8,22 @@
8 </head> 8 </head>
9 <body> 9 <body>
10 10
11 -<a href="/index" onclick="signOut();">Sign Out</a>
12 <h1>Hi <%= user.name %></h1> 11 <h1>Hi <%= user.name %></h1>
12 +<form method="post">
13 + NickName:<br>
14 + <input type="text" name="nickname" value="MickeyMouse"><br>
15 + Age:<br>
16 + <input type="text" name="age" value="19"><br><br>
17 +
18 + <input type="radio" id="male" name="gender" value="male">
19 + <label for="male">Male</label><br>
20 + <input type="radio" id="female" name="gender" value="female">
21 + <label for="female">Female</label><br>
22 +
23 + <input type="submit" value="Submit">
24 +</form>
25 +<a href="/index" onclick="signOut();">Sign Out</a>
26 +
13 27
14 </body> 28 </body>
15 <script> 29 <script>
......