Flare-k

[Modified] User controller Join

import routes from "../routes";
import User from "../models/User";
// 회원가입 -> 완료 -> 홈화면으로 Redirect
export const getJoin = (req, res) => {
res.render("join", { pageTitle: "Join" });
};
export const postJoin = (req, res) => {
export const postJoin = async (req, res) => {
const {
body: { name, email, password, password2 },
} = req;
......@@ -12,6 +13,15 @@ export const postJoin = (req, res) => {
res.status(400);
res.render("join", { pageTitle: "Join" });
} else {
try {
const user = await User.create({
name,
email,
});
await User.register(user, password);
} catch (error) {
console.log(error);
}
// To Do: Register User
// To Do: Log user in
res.redirect(routes.home);
......
......@@ -4,3 +4,6 @@ import User from "./models/User";
// passport에게 strategy(로그인 방식)를 사용하도록 요청한다.
// passportLocalMongooser가 제공하는 strategy를 이용한다. -> username과 password를 사용.
passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
......