Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
D_Team_Khuloud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
toror33
2020-05-25 18:16:35 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f11c368683aa5cf8c5a8d606fd607ee145ed8e68
f11c3686
1 parent
601da887
user_phone 추가 및 코드 정리
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
59 deletions
backend/app.js
backend/routes/index.js
backend/routes/userlogin/login.js
backend/routes/userlogin/register.js
backend/routes/userlogin/user.js
backend/app.js
View file @
f11c368
...
...
@@ -39,7 +39,7 @@ app.use(cookieParser());
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'public'
)));
app
.
use
(
session
({
secret
:
'
secrettexthere
'
,
secret
:
'
mykey
'
,
saveUninitialized
:
true
,
resave
:
true
}));
...
...
backend/routes/index.js
View file @
f11c368
...
...
@@ -2,9 +2,9 @@ var express = require('express');
var
router
=
express
.
Router
();
/* GET home page. */
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
res
.
render
(
'index'
,
{
title
:
'Express'
});
});
//
router.get('/', function(req, res, next) {
//
res.render('index', { title: 'Express' });
//
});
router
.
get
(
'/logout'
,
function
(
req
,
res
)
{
req
.
logout
();
...
...
backend/routes/userlogin/login.js
View file @
f11c368
...
...
@@ -12,14 +12,14 @@ router.post('/', function(req, res, next) {
var
user_id
=
req
.
body
.
user_id
;
var
user_pw
=
req
.
body
.
user_pw
;
var
sqlquery
=
"SELECT * FROM users WHERE user_id = ?"
;
connection
.
query
(
sqlquery
,
user_id
,
function
(
err
,
r
ows
)
{
connection
.
query
(
sqlquery
,
user_id
,
function
(
err
,
r
esult
)
{
if
(
err
)
{
console
.
log
(
"no match"
);
}
else
{
var
bytes
=
cryptoM
.
decrypt
(
r
ows
[
0
].
user_pw
);
var
bytes
=
cryptoM
.
decrypt
(
r
esult
[
0
].
user_pw
);
if
(
bytes
===
user_pw
)
{
console
.
log
(
"user login successfully"
);
req
.
session
.
user_id
=
r
ows
[
0
].
user_id
;
req
.
session
.
user_id
=
r
esult
[
0
].
user_id
;
res
.
redirect
(
'/main'
);
}
else
{
console
.
log
(
"wrong password!"
);
...
...
@@ -29,4 +29,6 @@ router.post('/', function(req, res, next) {
});
});
module
.
exports
=
router
;
...
...
backend/routes/userlogin/register.js
View file @
f11c368
...
...
@@ -18,15 +18,15 @@ router.post('/', function(req, res, next) {
var
user_pw
=
req
.
body
.
user_pw
;
var
user_email
=
req
.
body
.
user_email
;
var
user_name
=
req
.
body
.
user_name
;
//
var user_phone=req.body.user_phone;
var
user_phone
=
req
.
body
.
user_phone
;
var
sqlquery
=
"SELECT * FROM users WHERE user_id = ?"
;
connection
.
query
(
sqlquery
,
[
user_id
],
function
(
err
,
r
ows
)
{
connection
.
query
(
sqlquery
,
[
user_id
],
function
(
err
,
r
esult
)
{
if
(
rows
.
length
==
0
)
{
user_pw
=
cryptoM
.
encrypt
(
user_pw
);
console
.
log
(
user_pw
);
var
sql
=
'INSERT INTO users(user_id,user_pw, user_email, user_
name) values (
?,?,?,?)'
;
var
values
=
[
user_id
,
user_pw
,
user_email
,
user_name
];
var
sql
=
'INSERT INTO users(user_id,user_pw, user_email, user_
phone, user_name) values (?,
?,?,?,?)'
;
var
values
=
[
user_id
,
user_pw
,
user_email
,
user_
phone
,
user_
name
];
connection
.
query
(
sql
,
values
,
function
(
err
)
{
if
(
err
)
{
console
.
log
(
"inserting user failed"
);
...
...
backend/routes/userlogin/user.js
View file @
f11c368
...
...
@@ -4,62 +4,21 @@ var async = require('async');
var
router
=
express
.
Router
();
var
CryptoJS
=
require
(
"crypto-js"
);
function
get_my_info
(
id
,
cb
){
console
.
log
(
"get_my_info"
);
console
.
log
(
id
);
var
sqlquery
=
"SELECT * FROM users WHERE user_id = ?"
;
var
myinfo
=
new
Array
();
connection
.
query
(
sqlquery
,
id
,
function
(
err
,
rows
){
if
(
!
err
){
myinfo
=
rows
;
console
.
log
(
myinfo
);
cb
(
myinfo
);
}
else
{
console
.
log
(
"내 정보를 가져오는데 실패했습니다!"
);
res
.
send
({
result
:
false
});
//throw err;
}
});
}
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
req
.
session
.
user_id
);
async
.
series
(
[
function
(
callback
)
{
get_my_info
(
req
.
session
.
user_id
,
function
(
myinfo_list
)
{
callback
(
null
,
myinfo_list
);
});
}
],
function
(
err
,
results
)
{
res
.
render
(
'dropbox/user'
,
{
myinfo
:
results
[
0
]
});
}
);
//}
});
router
.
post
(
'/update'
,
function
(
req
,
res
,
next
)
{
var
user_id
=
req
.
body
.
user_id
;
var
user_pw
=
req
.
body
.
user_pw
;
var
user_pw2
=
req
.
body
.
user_pw2
;
var
user_email
=
req
.
body
.
user_email
;
//
var user_phone=req.body.user_phone;
var
user_phone
=
req
.
body
.
user_phone
;
if
(
user_pw
===
user_pw2
)
{
console
.
log
(
user_pw2
);
// user_pw=CryptoJS.AES.encrypt(user_pw, 'secret key 123');
user_pw
=
cryptoM
.
encrypt
(
user_pw
);
var
sql
=
'UPDATE users SET user_pw = ?, user_email= ? WHERE user_id = ?'
;
var
values
=
[
user_pw
,
user_email
,
user_id
];
connection
.
query
(
sql
,
values
,
function
(
err
)
{
var
sql
=
'UPDATE users SET user_pw = ?, user_email= ?
,user_phone = ?
WHERE user_id = ?'
;
var
values
=
[
user_pw
,
user_email
,
user_phone
,
user_id
];
connection
.
query
(
sql
,
values
,
function
(
err
)
{
if
(
err
)
{
console
.
log
(
"updating user failed"
);
//res.send({result:false});
//throw err;
next
(
err
);
}
else
{
console
.
log
(
"user updated successfully"
);
res
.
redirect
(
'back'
);
...
...
@@ -68,8 +27,7 @@ router.post('/update', function(req, res, next) {
}
else
{
console
.
log
(
"비밀번호가 일치하지 않습니다."
);
res
.
send
({
result
:
false
});
console
.
log
(
"password not match"
);
res
.
redirect
(
'back'
);
}
});
...
...
Please
register
or
login
to post a comment