Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jeongmin Seo
/
favorite_restaurant
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
Jeongmin Seo
2022-06-01 08:56:18 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cea910e0e78b3303d653d2ae473872a3d2db2fa2
cea910e0
1 parent
07522434
Update login
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
103 additions
and
14 deletions
jeongmin/login/app/app.js
jeongmin/login/app/package-lock.json
jeongmin/login/app/package.json
jeongmin/login/app/src/models/UserStorage.js
jeongmin/login/app/src/public/js/home/login.js
jeongmin/login/app/src/routes/home/home.ctrl.js
jeongmin/login/app/src/routes/home/index.js
jeongmin/login/app/src/views/home/login.ejs
jeongmin/login/app/app.js
View file @
cea910e
"use strict"
;
//모듈
const
express
=
require
(
"express"
);
const
bodyParser
=
require
(
"body-parser"
);
const
app
=
express
();
//라우팅
const
home
=
require
(
"./src/routes/home"
);
...
...
@@ -8,6 +9,9 @@ const home = require("./src/routes/home");
app
.
set
(
"views"
,
"./src/views"
);
app
.
set
(
"view engine"
,
"ejs"
);
app
.
use
(
express
.
static
(
`
${
__dirname
}
/src/public`
));
app
.
use
(
bodyParser
.
json
());
//url통해 전달되는 데이터에 한글, 공백 등의 문자 오류 해결
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
"/"
,
home
);
//미들웨어 등록해주는 method
...
...
jeongmin/login/app/package-lock.json
View file @
cea910e
{
"requires"
:
true
,
"name"
:
"login"
,
"version"
:
"1.0.0"
,
"lockfileVersion"
:
1
,
"requires"
:
true
,
"dependencies"
:
{
"accepts"
:
{
"version"
:
"1.3.8"
,
...
...
jeongmin/login/app/package.json
View file @
cea910e
...
...
@@ -6,12 +6,13 @@
"login"
:
"www.js"
},
"dependencies"
:
{
"body-parser"
:
"^1.20.0"
,
"ejs"
:
"^3.1.8"
,
"express"
:
"^4.18.1"
},
"devDependencies"
:
{},
"scripts"
:
{
"start"
:
"node ./bin/www.js"
,
"start"
:
"node
mon
./bin/www.js"
,
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"author"
:
""
,
...
...
jeongmin/login/app/src/models/UserStorage.js
0 → 100644
View file @
cea910e
'use strict'
;
class
UserStorage
{
//더미데이터
// # = private 변수로 은닉화
static
#
users
=
{
id
:
[
"jeongmin"
,
"jumi"
],
password
:
[
"1234"
,
"1234"
],
name
:
[
"정민"
,
"주미"
],
};
static
getUsers
(...
fields
)
{
const
users
=
this
.
#
users
;
const
newUsers
=
fields
.
reduce
((
newUsers
,
field
)
=>
{
if
(
users
.
hasOwnProperty
(
field
))
{
newUsers
[
field
]
=
users
[
field
];
}
return
newUsers
;
},
{});
return
newUsers
;
}
}
module
.
exports
=
UserStorage
;
\ No newline at end of file
jeongmin/login/app/src/public/js/home/login.js
View file @
cea910e
'use strict'
;
console
.
log
(
"hello"
);
\ No newline at end of file
const
id
=
document
.
querySelector
(
"#id"
),
password
=
document
.
querySelector
(
"#password"
),
loginBtn
=
document
.
querySelector
(
"button"
);
loginBtn
.
addEventListener
(
"click"
,
login
);
function
login
()
{
const
req
=
{
id
:
id
.
value
,
password
:
password
.
value
,
};
fetch
(
"/login"
,
{
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"application/json"
},
body
:
JSON
.
stringify
(
req
),
})
.
then
((
res
)
=>
res
.
json
())
.
then
((
res
)
=>
{
if
(
res
.
success
)
{
//성공하면 이동
location
.
href
=
"/"
;
}
else
{
alert
(
res
.
msg
);
}
})
.
catch
((
err
)
=>
{
console
.
error
(
"로그인 중 에러 발생"
);
});
}
\ No newline at end of file
...
...
jeongmin/login/app/src/routes/home/home.ctrl.js
View file @
cea910e
"use strict"
;
const
hello
=
(
req
,
res
)
=>
{
res
.
render
(
"home/index"
);
const
UserStorage
=
require
(
"../../models/UserStorage"
);
const
output
=
{
hello
:
(
req
,
res
)
=>
{
res
.
render
(
"home/index"
);
},
login
:
(
req
,
res
)
=>
{
res
.
render
(
"home/login"
);
},
};
const
login
=
(
req
,
res
)
=>
{
res
.
render
(
"home/login"
);
const
process
=
{
login
:
(
req
,
res
)
=>
{
const
id
=
req
.
body
.
id
,
password
=
req
.
body
.
password
;
const
users
=
UserStorage
.
getUsers
(
"id"
,
"password"
);
// console.log(UserStorage.getUsers("id", "password","name"));
const
response
=
{};
if
(
users
.
id
.
includes
(
id
))
{
const
idx
=
users
.
id
.
indexOf
(
id
);
if
(
users
.
password
[
idx
]
===
password
)
{
response
.
success
=
true
;
return
res
.
json
(
response
);
}
}
response
.
success
=
false
;
response
.
msg
=
"로그인에 실패하였습니다."
return
res
.
json
(
response
);
},
};
module
.
exports
=
{
hello
,
login
,
output
,
process
,
};
\ No newline at end of file
...
...
jeongmin/login/app/src/routes/home/index.js
View file @
cea910e
...
...
@@ -5,7 +5,8 @@ const router = express.Router();
const
ctrl
=
require
(
"./home.ctrl"
);
router
.
get
(
"/"
,
ctrl
.
hello
);
router
.
get
(
"/login"
,
ctrl
.
login
);
router
.
get
(
"/"
,
ctrl
.
output
.
hello
);
router
.
get
(
"/login"
,
ctrl
.
output
.
login
);
router
.
post
(
"/login"
,
ctrl
.
process
.
login
);
module
.
exports
=
router
;
\ No newline at end of file
...
...
jeongmin/login/app/src/views/home/login.ejs
View file @
cea910e
...
...
@@ -4,12 +4,12 @@
<meta
charset=
"UTF-8"
/>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
/>
<script
src=
"/js/home/login.js"
></script>
<script
src=
"/js/home/login.js"
defer
></script>
<title>
Document
</title>
</head>
<body>
<input
type=
"text"
placeholder=
"아이디"
/><br
/>
<input
type=
"text"
placeholder=
"비밀번호"
/><br
/>
<input
id=
"id"
type=
"text"
placeholder=
"아이디"
/><br
/>
<input
id=
"password"
type=
"text"
placeholder=
"비밀번호"
/><br
/>
<button>
로그인
</button>
</body>
</html>
...
...
Please
register
or
login
to post a comment