index.js
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var express = require('express')
var app = express()
var router = express.Router();
var path = require('path') // 상대경로
var mysql_odbc = require('../../db/db_board')();
var myinfo = mysql_odbc.init();
// main page는 login이 된 상태(세션정보가 있을때만) 접근이 가능하게 하자 -> info에 구현해놓음.
router.get('/', function(req, res){
var id = req.user.ID;
if(!id) res.sendFile(path.join(__dirname, "../../public/login.html"))
if(id){
var sql = "select profilemsg, type from userdb where id =?";
myinfo.query(sql,[id],function(err,rows) {
if (err) console.error("err : " + err);
var nickname = req.user.nickname;
var type = rows[0].type;
var profilemsg = rows[0].profilemsg;
console.log(req.user.ID+'('+nickname+') 유저가 프로필을 보고있습니다.')
res.render('profile.ejs', {'ID':id, 'nickname': nickname, 'profilemsg': profilemsg, 'type': type})
})
}
});
router.get('/update', function(req,res){
var sql = 'select profilemsg from userdb where id ="'+req.user.ID+'"';
myinfo.query(sql, function(err,rows) {
if (err) console.error("err : " + err);
var id = req.user.ID;
var nickname = req.user.nickname;
var profilemsg = rows[0].profilemsg;
res.render('profmsgedit.ejs', {'ID':id, 'nickname': nickname, 'profilemsg': profilemsg});
})
})
router.post('/update', function(req,res,next){
var id = req.user.ID;
var profilemsg = req.body.profilemsg;
var nickname = req.body.nickname;
var type = req.body.type;
var datas = [profilemsg, nickname, type, id]
var sql = "update userdb set profilemsg =?, nickname=?, type=? where id =?"
myinfo.query(sql,datas,function(err,result){
if(err) console.error(err)
console.log(req.user.ID+'('+nickname+') 유저가 프로필을 수정했습니다.')
res.redirect('/profile')
})
})
module.exports = router;