Jeongmin Seo

Add design on login form

1 +'use strict';
2 +
3 +const UserStorage = require("./UserStorage");
4 +
5 +class User {
6 + constructor(body) {
7 + this.body = body;
8 + }
9 +
10 + login() {
11 + const body = this.body
12 + const {id, password} = UserStorage.getUserInfo(body.id);
13 + // console.log(id, password);
14 + if (id) {
15 + if (id === body.id && password === body.password) {
16 + return { success: true};
17 + }
18 + return { success : false, msg: "비밀번호가 틀렸습니다."};
19 + }
20 + return {success: false, msg: "존재하지 않는 아이디입니다."};
21 + }
22 +}
23 +
24 +module.exports = User;
...\ No newline at end of file ...\ No newline at end of file
...@@ -19,6 +19,18 @@ class UserStorage { ...@@ -19,6 +19,18 @@ class UserStorage {
19 }, {}); 19 }, {});
20 return newUsers; 20 return newUsers;
21 } 21 }
22 +
23 + static getUserInfo(id) {
24 + const users = this.#users;
25 + const idx = users.id.indexOf(id);
26 + const userKeys = Object.keys(users); // [id, password, name]
27 + const userInfo = userKeys.reduce((newUser, info) => {
28 + newUser[info] = users[info][idx];
29 + return newUser;
30 + }, {});
31 +
32 + return userInfo;
33 + }
22 } 34 }
23 35
24 module.exports = UserStorage; 36 module.exports = UserStorage;
...\ No newline at end of file ...\ No newline at end of file
......
1 +@import url(https://fonts.googleapis.com/css?family=Roboto:300);
2 +
3 +.login-page {
4 + width: 360px;
5 + padding: 12% 0 0;
6 + margin: auto;
7 +}
8 +.form {
9 + position: relative;
10 + z-index: 1;
11 + background: #FFFFFF;
12 + max-width: 360px;
13 + margin: 0 auto 100px;
14 + padding: 45px;
15 + text-align: center;
16 + box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
17 +}
18 +.form input {
19 + font-family: "Roboto", sans-serif;
20 + outline: 0;
21 + background: #f2f2f2;
22 + width: 100%;
23 + border: 0;
24 + margin: 0 0 15px;
25 + padding: 15px;
26 + box-sizing: border-box;
27 + font-size: 14px;
28 +}
29 +.form button {
30 + font-family: "Roboto", sans-serif;
31 + text-transform: uppercase;
32 + outline: 0;
33 + background: rebeccapurple;
34 + width: 100%;
35 + border: 0;
36 + padding: 15px;
37 + color: #FFFFFF;
38 + font-size: 14px;
39 + -webkit-transition: all 0.3 ease;
40 + transition: all 0.3 ease;
41 + cursor: pointer;
42 +}
43 +.form button:hover,.form button:active,.form button:focus {
44 + background: rebeccapurple;
45 +}
46 +.form .message {
47 + margin: 15px 0 0;
48 + color: #b3b3b3;
49 + font-size: 12px;
50 +}
51 +.form .message a {
52 + color: rebeccapurple;
53 + text-decoration: none;
54 +}
55 +.form .register-form {
56 + display: none;
57 +}
58 +.container {
59 + position: relative;
60 + z-index: 1;
61 + max-width: 300px;
62 + margin: 0 auto;
63 +}
64 +.container:before, .container:after {
65 + content: "";
66 + display: block;
67 + clear: both;
68 +}
69 +.container .info {
70 + margin: 50px auto;
71 + text-align: center;
72 +}
73 +.container .info h1 {
74 + margin: 0 0 15px;
75 + padding: 0;
76 + font-size: 36px;
77 + font-weight: 300;
78 + color: #1a1a1a;
79 +}
80 +.container .info span {
81 + color: #4d4d4d;
82 + font-size: 12px;
83 +}
84 +.container .info span a {
85 + color: #000000;
86 + text-decoration: none;
87 +}
88 +.container .info span .fa {
89 + color: #EF3B3A;
90 +}
91 +
92 +/* #id::placeholder #password::placeholder {
93 + color: black;
94 + font-style: italic;
95 + font-weight: bold;
96 +} */
97 +
98 +body {
99 + background: rebeccapurple; /* fallback for old browsers */
100 + /* background: rebeccapurple; */
101 + background: linear-gradient(90deg, rebeccapurple 0%, rebeccapurple 0%);
102 + font-family: "Roboto", sans-serif;
103 + -webkit-font-smoothing: antialiased;
104 + -moz-osx-font-smoothing: grayscale;
105 +}
106 +
107 +/* Copyright (c) 2022 by Aigars Silkalns (https://codepen.io/colorlib/pen/rxddKy) */
...\ No newline at end of file ...\ No newline at end of file
1 +@import url(https://fonts.googleapis.com/css?family=Roboto:300);
2 +
3 +.login-page {
4 + width: 360px;
5 + padding: 8% 0 0;
6 + margin: auto;
7 +}
8 +.form {
9 + position: relative;
10 + z-index: 1;
11 + background: #FFFFFF;
12 + max-width: 360px;
13 + margin: 0 auto 100px;
14 + padding: 45px;
15 + text-align: center;
16 + box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
17 +}
18 +.form input {
19 + font-family: "Roboto", sans-serif;
20 + outline: 0;
21 + background: #f2f2f2;
22 + width: 100%;
23 + border: 0;
24 + margin: 0 0 15px;
25 + padding: 15px;
26 + box-sizing: border-box;
27 + font-size: 14px;
28 +}
29 +.form button {
30 + font-family: "Roboto", sans-serif;
31 + text-transform: uppercase;
32 + outline: 0;
33 + background: rebeccapurple;
34 + width: 100%;
35 + border: 0;
36 + padding: 15px;
37 + color: #FFFFFF;
38 + font-size: 14px;
39 + -webkit-transition: all 0.3 ease;
40 + transition: all 0.3 ease;
41 + cursor: pointer;
42 +}
43 +.form button:hover,.form button:active,.form button:focus {
44 + background: rebeccapurple;
45 +}
46 +.form .message {
47 + margin: 15px 0 0;
48 + color: #b3b3b3;
49 + font-size: 12px;
50 +}
51 +.form .message a {
52 + color: rebeccapurple;
53 + text-decoration: none;
54 +}
55 +.form .register-form {
56 + display: none;
57 +}
58 +.container {
59 + position: relative;
60 + z-index: 1;
61 + max-width: 300px;
62 + margin: 0 auto;
63 +}
64 +.container:before, .container:after {
65 + content: "";
66 + display: block;
67 + clear: both;
68 +}
69 +.container .info {
70 + margin: 50px auto;
71 + text-align: center;
72 +}
73 +.container .info h1 {
74 + margin: 0 0 15px;
75 + padding: 0;
76 + font-size: 36px;
77 + font-weight: 300;
78 + color: #1a1a1a;
79 +}
80 +.container .info span {
81 + color: #4d4d4d;
82 + font-size: 12px;
83 +}
84 +.container .info span a {
85 + color: #000000;
86 + text-decoration: none;
87 +}
88 +.container .info span .fa {
89 + color: #EF3B3A;
90 +}
91 +
92 +/* #id::placeholder #password::placeholder {
93 + color: black;
94 + font-style: italic;
95 + font-weight: bold;
96 +} */
97 +
98 +body {
99 + background: rebeccapurple; /* fallback for old browsers */
100 + /* background: rebeccapurple; */
101 + background: linear-gradient(90deg, rebeccapurple 0%, rebeccapurple 0%);
102 + font-family: "Roboto", sans-serif;
103 + -webkit-font-smoothing: antialiased;
104 + -moz-osx-font-smoothing: grayscale;
105 +}
106 +
107 +/* Copyright (c) 2022 by Aigars Silkalns (https://codepen.io/colorlib/pen/rxddKy) */
...\ No newline at end of file ...\ No newline at end of file
1 "use strict"; 1 "use strict";
2 2
3 -const UserStorage = require("../../models/UserStorage"); 3 +const User = require("../../models/User");
4 4
5 const output = { 5 const output = {
6 hello: (req, res) => { 6 hello: (req, res) => {
...@@ -10,27 +10,34 @@ const output = { ...@@ -10,27 +10,34 @@ const output = {
10 login: (req, res) => { 10 login: (req, res) => {
11 res.render("home/login"); 11 res.render("home/login");
12 }, 12 },
13 +
14 + register: (req, res) => {
15 + res.render("home/register");
16 + }
13 }; 17 };
14 18
15 const process = { 19 const process = {
16 login: (req, res) => { 20 login: (req, res) => {
17 - const id = req.body.id, 21 + const user = new User(req.body);
18 - password = req.body.password; 22 + const response = user.login();
19 - const users = UserStorage.getUsers("id", "password");
20 - // console.log(UserStorage.getUsers("id", "password","name"));
21 - const response = {};
22 -
23 - if (users.id.includes(id)) {
24 - const idx = users.id.indexOf(id);
25 - if (users.password[idx] === password) {
26 - response.success = true;
27 return res.json(response); 23 return res.json(response);
28 - } 24 + // const id = req.body.id,
29 - } 25 + // password = req.body.password;
26 + // const users = UserStorage.getUsers("id", "password");
27 + // // console.log(UserStorage.getUsers("id", "password","name"));
28 + // const response = {};
30 29
31 - response.success = false; 30 + // if (users.id.includes(id)) {
32 - response.msg = "로그인에 실패하였습니다." 31 + // const idx = users.id.indexOf(id);
33 - return res.json(response); 32 + // if (users.password[idx] === password) {
33 + // response.success = true;
34 + // return res.json(response);
35 + // }
36 + // }
37 +
38 + // response.success = false;
39 + // response.msg = "로그인에 실패하였습니다."
40 + // return res.json(response);
34 }, 41 },
35 }; 42 };
36 43
......
...@@ -7,6 +7,7 @@ const ctrl = require("./home.ctrl"); ...@@ -7,6 +7,7 @@ const ctrl = require("./home.ctrl");
7 7
8 router.get("/", ctrl.output.hello); 8 router.get("/", ctrl.output.hello);
9 router.get("/login", ctrl.output.login); 9 router.get("/login", ctrl.output.login);
10 +router.get("/register", ctrl.output.register);
10 router.post("/login", ctrl.process.login); 11 router.post("/login", ctrl.process.login);
11 12
12 module.exports = router; 13 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -4,12 +4,31 @@ ...@@ -4,12 +4,31 @@
4 <meta charset="UTF-8" /> 4 <meta charset="UTF-8" />
5 <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7 + <link rel="stylesheet" href="/css/home/login.css" />
7 <script src="/js/home/login.js" defer></script> 8 <script src="/js/home/login.js" defer></script>
8 <title>Document</title> 9 <title>Document</title>
9 </head> 10 </head>
10 <body> 11 <body>
11 - <input id="id" type="text" placeholder="아이디" /><br /> 12 + <div class="login-page">
12 - <input id="password" type="text" placeholder="비밀번호" /><br /> 13 + <div class="form">
13 - <button>로그인</button> 14 + <!-- <form class="register-form">
15 + <input type="text" placeholder="name" />
16 + <input type="password" placeholder="password" />
17 + <input type="text" placeholder="email address" />
18 + <button>create</button>
19 + <p class="message">Already registered? <a href="#">Sign In</a></p>
20 + </form> -->
21 + <form class="login-form">
22 + <input id="id" type="text" placeholder="아이디" />
23 + <input id="password" type="password" placeholder="비밀번호" />
24 + <button>LOGIN</button>
25 + <p class="message">
26 + 계정이 없으신가요? <a href="/register">회원가입</a>
27 + </p>
28 + </form>
29 + </div>
30 + </div>
14 </body> 31 </body>
15 </html> 32 </html>
33 +
34 +<!-- Copyright (c) 2022 by Aigars Silkalns (https://codepen.io/colorlib/pen/rxddKy) -->
......
1 +<!DOCTYPE html>
2 +<html lang="ko">
3 + <head>
4 + <meta charset="UTF-8" />
5 + <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6 + <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7 + <link rel="stylesheet" href="/css/home/register.css" />
8 + <script src="/js/home/login.js" defer></script>
9 + <title>Document</title>
10 + </head>
11 + <body>
12 + <div class="login-page">
13 + <div class="form">
14 + <!-- <form class="register-form">
15 + <input type="text" placeholder="name" />
16 + <input type="password" placeholder="password" />
17 + <input type="text" placeholder="email address" />
18 + <button>create</button>
19 + <p class="message">Already registered? <a href="#">Sign In</a></p>
20 + </form> -->
21 + <form class="login-form">
22 + <input id="id" type="text" placeholder="아이디" />
23 + <input id="name" type="text" placeholder="이름" />
24 + <input id="password" type="password" placeholder="비밀번호" />
25 + <input
26 + id="confirm-password"
27 + type="password"
28 + placeholder="비밀번호 확인"
29 + />
30 + <button>SIGN UP</button>
31 + <p class="message">계정이 있으신가요? <a href="/login">로그인</a></p>
32 + </form>
33 + </div>
34 + </div>
35 + </body>
36 +</html>
37 +
38 +<!-- Copyright (c) 2022 by Aigars Silkalns (https://codepen.io/colorlib/pen/rxddKy) -->