Showing
2 changed files
with
14 additions
and
1 deletions
1 | import routes from "../routes"; | 1 | import routes from "../routes"; |
2 | +import User from "../models/User"; | ||
2 | 3 | ||
3 | // 회원가입 -> 완료 -> 홈화면으로 Redirect | 4 | // 회원가입 -> 완료 -> 홈화면으로 Redirect |
4 | export const getJoin = (req, res) => { | 5 | export const getJoin = (req, res) => { |
5 | res.render("join", { pageTitle: "Join" }); | 6 | res.render("join", { pageTitle: "Join" }); |
6 | }; | 7 | }; |
7 | -export const postJoin = (req, res) => { | 8 | +export const postJoin = async (req, res) => { |
8 | const { | 9 | const { |
9 | body: { name, email, password, password2 }, | 10 | body: { name, email, password, password2 }, |
10 | } = req; | 11 | } = req; |
... | @@ -12,6 +13,15 @@ export const postJoin = (req, res) => { | ... | @@ -12,6 +13,15 @@ export const postJoin = (req, res) => { |
12 | res.status(400); | 13 | res.status(400); |
13 | res.render("join", { pageTitle: "Join" }); | 14 | res.render("join", { pageTitle: "Join" }); |
14 | } else { | 15 | } else { |
16 | + try { | ||
17 | + const user = await User.create({ | ||
18 | + name, | ||
19 | + email, | ||
20 | + }); | ||
21 | + await User.register(user, password); | ||
22 | + } catch (error) { | ||
23 | + console.log(error); | ||
24 | + } | ||
15 | // To Do: Register User | 25 | // To Do: Register User |
16 | // To Do: Log user in | 26 | // To Do: Log user in |
17 | res.redirect(routes.home); | 27 | res.redirect(routes.home); | ... | ... |
... | @@ -4,3 +4,6 @@ import User from "./models/User"; | ... | @@ -4,3 +4,6 @@ import User from "./models/User"; |
4 | // passport에게 strategy(로그인 방식)를 사용하도록 요청한다. | 4 | // passport에게 strategy(로그인 방식)를 사용하도록 요청한다. |
5 | // passportLocalMongooser가 제공하는 strategy를 이용한다. -> username과 password를 사용. | 5 | // passportLocalMongooser가 제공하는 strategy를 이용한다. -> username과 password를 사용. |
6 | passport.use(User.createStrategy()); | 6 | passport.use(User.createStrategy()); |
7 | + | ||
8 | +passport.serializeUser(User.serializeUser()); | ||
9 | +passport.deserializeUser(User.deserializeUser()); | ... | ... |
-
Please register or login to post a comment