Jeongmin Seo

merge feature/login_signup branch

1 +# Logs
2 +logs
3 +*.log
4 +npm-debug.log*
5 +yarn-debug.log*
6 +yarn-error.log*
7 +lerna-debug.log*
8 +.pnpm-debug.log*
9 +
10 +# Diagnostic reports (https://nodejs.org/api/report.html)
11 +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12 +
13 +# Runtime data
14 +pids
15 +*.pid
16 +*.seed
17 +*.pid.lock
18 +
19 +# Directory for instrumented libs generated by jscoverage/JSCover
20 +lib-cov
21 +
22 +# Coverage directory used by tools like istanbul
23 +coverage
24 +*.lcov
25 +
26 +# nyc test coverage
27 +.nyc_output
28 +
29 +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30 +.grunt
31 +
32 +# Bower dependency directory (https://bower.io/)
33 +bower_components
34 +
35 +# node-waf configuration
36 +.lock-wscript
37 +
38 +# Compiled binary addons (https://nodejs.org/api/addons.html)
39 +build/Release
40 +
41 +# Dependency directories
42 +**node_modules/
43 +jspm_packages/
44 +
45 +# Snowpack dependency directory (https://snowpack.dev/)
46 +web_modules/
47 +
48 +# TypeScript cache
49 +*.tsbuildinfo
50 +
51 +# Optional npm cache directory
52 +.npm
53 +
54 +# Optional eslint cache
55 +.eslintcache
56 +
57 +# Microbundle cache
58 +.rpt2_cache/
59 +.rts2_cache_cjs/
60 +.rts2_cache_es/
61 +.rts2_cache_umd/
62 +
63 +# Optional REPL history
64 +.node_repl_history
65 +
66 +# Output of 'npm pack'
67 +*.tgz
68 +
69 +# Yarn Integrity file
70 +.yarn-integrity
71 +
72 +# dotenv environment variables file
73 +.env
74 +.env.test
75 +.env.production
76 +
77 +# parcel-bundler cache (https://parceljs.org/)
78 +.cache
79 +.parcel-cache
80 +
81 +# Next.js build output
82 +.next
83 +out
84 +
85 +# Nuxt.js build / generate output
86 +.nuxt
87 +dist
88 +
89 +# Gatsby files
90 +.cache/
91 +# Comment in the public line in if your project uses Gatsby and not Next.js
92 +# https://nextjs.org/blog/next-9-1#public-directory-support
93 +# public
94 +
95 +# vuepress build output
96 +.vuepress/dist
97 +
98 +# Serverless directories
99 +.serverless/
100 +
101 +# FuseBox cache
102 +.fusebox/
103 +
104 +# DynamoDB Local files
105 +.dynamodb/
106 +
107 +# TernJS port file
108 +.tern-port
109 +
110 +# Stores VSCode versions used for testing VSCode extensions
111 +.vscode-test
112 +
113 +# yarn v2
114 +.yarn/cache
115 +.yarn/unplugged
116 +.yarn/build-state.yml
117 +.yarn/install-state.gz
118 +.pnp.*
...\ No newline at end of file ...\ No newline at end of file
1 +"use strict";
2 +//모듈
3 +const express = require("express");
4 +const bodyParser = require("body-parser");
5 +//환경변수 (운영체제간 gap 없애고자)
6 +const dotenv = require("dotenv");
7 +dotenv.config();
8 +const app = express();
9 +//라우팅
10 +const home = require("./src/routes/home");
11 +// 앱 세팅
12 +app.set("views", "./src/views");
13 +app.set("view engine", "ejs");
14 +app.use(express.static(`${__dirname}/src/public`));
15 +app.use(bodyParser.json());
16 +//url통해 전달되는 데이터에 한글, 공백 등의 문자 오류 해결
17 +app.use(bodyParser.urlencoded({extended: true}));
18 +
19 +app.use("/", home); //미들웨어 등록해주는 method
20 +
21 +module.exports = app;
...\ No newline at end of file ...\ No newline at end of file
1 +"use strict";
2 +
3 +const app = require("../app");
4 +const PORT = process.env.PORT || 3000;
5 +
6 +app.listen(PORT, () => {
7 + console.log("서버 가동");
8 +});
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
1 +{
2 + "name": "login",
3 + "version": "1.0.0",
4 + "main": "app.js",
5 + "bin": {
6 + "login": "www.js"
7 + },
8 + "dependencies": {
9 + "body-parser": "^1.20.0",
10 + "dotenv": "^16.0.1",
11 + "ejs": "^3.1.8",
12 + "express": "^4.18.1",
13 + "mysql": "^2.18.1"
14 + },
15 + "devDependencies": {},
16 + "scripts": {
17 + "start": "nodemon ./bin/www.js",
18 + "test": "echo \"Error: no test specified\" && exit 1"
19 + },
20 + "author": "",
21 + "license": "ISC",
22 + "keywords": [],
23 + "description": ""
24 +}
1 +const mysql = require("mysql");
2 +
3 +const db = mysql.createConnection({
4 + host: process.env.DB_HOST,
5 + user: process.env.DB_USER,
6 + password: process.env.DB_PASSWORD,
7 + database: process.env.DB_DATABASE,
8 +});
9 +
10 +db.connect();
11 +
12 +module.exports = db;
...\ No newline at end of file ...\ No newline at end of file
1 +'use strict';
2 +//for DB manipulate
3 +const UserStorage = require("./UserStorage");
4 +
5 +class User {
6 + constructor(body) {
7 + this.body = body;
8 + }
9 +
10 + async login() {
11 + const client = this.body;
12 + try {
13 +
14 + const {id, password} = await UserStorage.getUserInfo(client.id);
15 + // console.log(id, password);
16 +
17 + if (id) {
18 + if (id === client.id && password === client.password) {
19 + return { success: true};
20 + }
21 + return { success : false, msg: "비밀번호가 틀렸습니다."};
22 + }
23 + return {success: false, msg: "존재하지 않는 아이디입니다."};
24 + } catch (err) {
25 + return {success: false, msg: err};
26 + }
27 + }
28 +
29 + async register() {
30 + const client = this.body;
31 + try {
32 + const response = await UserStorage.save(client);
33 + // console.log(response);
34 + return response;
35 + } catch (err) {
36 +
37 + return {success: false, msg : err};
38 + }
39 + }
40 +}
41 +
42 +module.exports = User;
...\ No newline at end of file ...\ No newline at end of file
1 +'use strict';
2 +//for DB CRUD
3 +const db = require("../config/db");
4 +
5 +
6 +class UserStorage {
7 + // static getUsers(isAll, ...fields) {
8 + // }
9 +
10 + static getUserInfo(id) {
11 + return new Promise((resolve, reject) => {
12 + const query = "SELECT * FROM users WHERE id = ?;";
13 + db.query(query, [id], (err, data) => {
14 + if (err) reject(`${err}`);
15 + // console.log(data[0]);
16 + resolve(data[0]);
17 + });
18 + });
19 + }
20 +
21 + static async save(userInfo) {
22 + return new Promise((resolve, reject) => {
23 + const query = "INSERT INTO users(id, name, password) VALUES(?, ?, ?);";
24 + db.query(
25 + query,
26 + [userInfo.id, userInfo.name, userInfo.password],
27 + (err, data) => {
28 + if (err) reject(`${err}`);
29 + // console.log(data[0]);
30 + resolve({ success: true});
31 + }
32 + );
33 + });
34 + }
35 +}
36 +
37 +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: 89%;
35 + border: 0;
36 + margin: 0 auto;
37 + padding: 15px;
38 + color: #FFFFFF;
39 + font-size: 14px;
40 + -webkit-transition: all 0.3 ease;
41 + transition: all 0.3 ease;
42 + cursor: pointer;
43 +}
44 +.form #button:hover,.form #button:active,.form #button:focus {
45 + background: rebeccapurple;
46 +}
47 +.form .message {
48 + margin: 15px 0 0;
49 + color: #b3b3b3;
50 + font-size: 12px;
51 +}
52 +.form .message a {
53 + color: rebeccapurple;
54 + text-decoration: none;
55 +}
56 +.form .register-form {
57 + display: none;
58 +}
59 +.container {
60 + position: relative;
61 + z-index: 1;
62 + max-width: 300px;
63 + margin: 0 auto;
64 +}
65 +.container:before, .container:after {
66 + content: "";
67 + display: block;
68 + clear: both;
69 +}
70 +.container .info {
71 + margin: 50px auto;
72 + text-align: center;
73 +}
74 +.container .info h1 {
75 + margin: 0 0 15px;
76 + padding: 0;
77 + font-size: 36px;
78 + font-weight: 300;
79 + color: #1a1a1a;
80 +}
81 +.container .info span {
82 + color: #4d4d4d;
83 + font-size: 12px;
84 +}
85 +.container .info span a {
86 + color: #000000;
87 + text-decoration: none;
88 +}
89 +.container .info span .fa {
90 + color: #EF3B3A;
91 +}
92 +
93 +/* #id::placeholder #password::placeholder {
94 + color: black;
95 + font-style: italic;
96 + font-weight: bold;
97 +} */
98 +
99 +body {
100 + background: rebeccapurple; /* fallback for old browsers */
101 + /* background: rebeccapurple; */
102 + background: linear-gradient(90deg, rebeccapurple 0%, rebeccapurple 0%);
103 + font-family: "Roboto", sans-serif;
104 + -webkit-font-smoothing: antialiased;
105 + -moz-osx-font-smoothing: grayscale;
106 +}
107 +
108 +/* 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: 89%;
35 + border: 0;
36 + margin: 0 auto;
37 + padding: 15px;
38 + color: #FFFFFF;
39 + font-size: 14px;
40 + -webkit-transition: all 0.3 ease;
41 + transition: all 0.3 ease;
42 + cursor: pointer;
43 +}
44 +.form #button:hover,.form #button:active,.form #button:focus {
45 + background: rebeccapurple;
46 +}
47 +.form .message {
48 + margin: 15px 0 0;
49 + color: #b3b3b3;
50 + font-size: 12px;
51 +}
52 +.form .message a {
53 + color: rebeccapurple;
54 + text-decoration: none;
55 +}
56 +.form .register-form {
57 + display: none;
58 +}
59 +.container {
60 + position: relative;
61 + z-index: 1;
62 + max-width: 300px;
63 + margin: 0 auto;
64 +}
65 +.container:before, .container:after {
66 + content: "";
67 + display: block;
68 + clear: both;
69 +}
70 +.container .info {
71 + margin: 50px auto;
72 + text-align: center;
73 +}
74 +.container .info h1 {
75 + margin: 0 0 15px;
76 + padding: 0;
77 + font-size: 36px;
78 + font-weight: 300;
79 + color: #1a1a1a;
80 +}
81 +.container .info span {
82 + color: #4d4d4d;
83 + font-size: 12px;
84 +}
85 +.container .info span a {
86 + color: #000000;
87 + text-decoration: none;
88 +}
89 +.container .info span .fa {
90 + color: #EF3B3A;
91 +}
92 +
93 +/* #id::placeholder #password::placeholder {
94 + color: black;
95 + font-style: italic;
96 + font-weight: bold;
97 +} */
98 +
99 +body {
100 + background: rebeccapurple; /* fallback for old browsers */
101 + /* background: rebeccapurple; */
102 + background: linear-gradient(90deg, rebeccapurple 0%, rebeccapurple 0%);
103 + font-family: "Roboto", sans-serif;
104 + -webkit-font-smoothing: antialiased;
105 + -moz-osx-font-smoothing: grayscale;
106 +}
107 +
108 +/* 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';
2 +
3 +const id = document.querySelector("#id"),
4 + password = document.querySelector("#password"),
5 + loginBtn = document.querySelector("#button");
6 +
7 +loginBtn.addEventListener("click", login);
8 +
9 +function login() {
10 + const req = {
11 + id : id.value,
12 + password : password.value,
13 + };
14 +
15 + fetch("/login", {
16 + method: "POST",
17 + headers: {
18 + "Content-Type": "application/json"
19 + },
20 + body: JSON.stringify(req),
21 + })
22 + .then((res) => res.json())
23 + .then((res) => {
24 + if (res.success) {
25 + //성공하면 이동
26 + location.href = "/";
27 + } else {
28 + alert(res.msg);
29 + }
30 + })
31 + .catch((err) => {
32 + console.error("로그인 중 에러 발생");
33 + });
34 +}
...\ No newline at end of file ...\ No newline at end of file
1 +'use strict';
2 +
3 +const id = document.querySelector("#id"),
4 + name = document.querySelector("#name"),
5 + password = document.querySelector("#password"),
6 + confirmPassword = document.querySelector("#confirm-password"),
7 + registerBtn = document.querySelector("#button");
8 +
9 +registerBtn.addEventListener("click", register);
10 +
11 +function register() {
12 + if(!id.value) {
13 + return alert("아이디를 입력해주세요.")
14 + }
15 +
16 + if(!name.value) {
17 + return alert("이름을 입력해주세요.")
18 + }
19 + if(!password.value) {
20 + return alert("비밀번호를 입력해주세요.")
21 + }
22 + if(!confirmPassword.value) {
23 + return alert("비밀번호를 확인해주세요.")
24 + }
25 + if (password.value !== confirmPassword.value) {
26 + return alert("비밀번호가 일치하지 않습니다.")
27 + }
28 +
29 + const req = {
30 + id : id.value,
31 + name : name.value,
32 + password : password.value,
33 + };
34 +
35 + fetch("/register", {
36 + method: "POST",
37 + headers: {
38 + "Content-Type": "application/json"
39 + },
40 + body: JSON.stringify(req),
41 + })
42 + .then((res) => res.json())
43 + .then((res) => {
44 + if (res.success) {
45 + //성공하면 이동
46 + location.href = "/login";
47 + } else {
48 + alert(res.msg);
49 + }
50 + })
51 + .catch((err) => {
52 + console.error("회원가입 중 에러 발생");
53 + });
54 +}
...\ No newline at end of file ...\ No newline at end of file
1 +"use strict";
2 +
3 +const User = require("../../models/User");
4 +
5 +const output = {
6 + hello: (req, res) => {
7 + res.render("home/index");
8 + },
9 +
10 + login: (req, res) => {
11 + res.render("home/login");
12 + },
13 +
14 + register: (req, res) => {
15 + res.render("home/register");
16 + }
17 +};
18 +
19 +const process = {
20 + login: async (req, res) => {
21 + const user = new User(req.body);
22 + const response = await user.login();
23 + return res.json(response);
24 + },
25 +
26 + register: async (req, res) => {
27 + const user = new User(req.body);
28 + const response = await user.register();
29 + return res.json(response);
30 + },
31 + // const id = req.body.id,
32 + // password = req.body.password;
33 + // const users = UserStorage.getUsers("id", "password");
34 + // // console.log(UserStorage.getUsers("id", "password","name"));
35 + // const response = {};
36 +
37 + // if (users.id.includes(id)) {
38 + // const idx = users.id.indexOf(id);
39 + // if (users.password[idx] === password) {
40 + // response.success = true;
41 + // return res.json(response);
42 + // }
43 + // }
44 +
45 + // response.success = false;
46 + // response.msg = "로그인에 실패하였습니다."
47 + // return res.json(response);
48 +};
49 +
50 +module.exports = {
51 + output,
52 + process,
53 +};
...\ No newline at end of file ...\ No newline at end of file
1 +"use strict";
2 +
3 +const express = require("express");
4 +const router = express.Router();
5 +
6 +const ctrl = require("./home.ctrl");
7 +
8 +router.get("/", ctrl.output.hello);
9 +router.get("/login", ctrl.output.login);
10 +router.get("/register", ctrl.output.register);
11 +
12 +router.post("/login", ctrl.process.login);
13 +router.post("/register", ctrl.process.register);
14 +
15 +module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
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 + <title>Document</title>
8 + </head>
9 + <body>
10 + 여기는 루트입니다.
11 + </body>
12 +</html>
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/login.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="password" type="password" placeholder="비밀번호" />
24 + <p id="button">LOGIN</p>
25 + <p class="message">
26 + 계정이 없으신가요? <a href="/register">회원가입</a>
27 + </p>
28 + </form>
29 + </div>
30 + </div>
31 + </body>
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/register.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 + <p id="button">SIGN UP</p>
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) -->
1 +{
2 + "lockfileVersion": 1
3 +}