Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[김민재] Assignment 2: Express API - 유저 회원가입 하기(암호화) #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions minjae/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const port = 3000;

const app = express();

const bcrypt = require("bcrypt");
const saltRounds = 12;

const mySqlDataSource = new DataSource({
type: process.env.DB_CONNECTION,
host: process.env.DB_HOST,
Expand All @@ -27,11 +30,17 @@ app.get("/ping", (req, res) => {
});

app.post("/users", async (req, res) => {
const { id, pwd, name, phone, email, guest_yn } = req.body;
const { user_id, pwd, name, phone, email, guest_yn } = req.body;
const makeHash = async (pwd, saltRounds) => {
return await bcrypt.hash(pwd, saltRounds);
};
const cryptedpassword = await makeHash(pwd, saltRounds);

console.log(cryptedpassword);

await mySqlDataSource.query(
"INSERT INTO westagram.users (user_id, password, name, phone, email, guest_yn) VALUES (?, ?, ?, ?, ?, ?);",
[id, pwd, name, phone, email, guest_yn]
[user_id, cryptedpassword, name, phone, email, guest_yn]
);
res.status(201).json({ message: "successfully created" });
});
Expand Down
15 changes: 15 additions & 0 deletions minjae/db/migrations/20230809083758_create_users_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- migrate:up
CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_id VARCHAR(20) NOT NULL,
password CHAR(53) NOT NULL,
name VARCHAR(20) NOT NULL,
phone VARCHAR(20) NOT NULL,
email VARCHAR(150) NOT NULL,
guest_yn BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- migrate:down
DROP TABLE users;
Loading