Flare-k

Add mixin and Modify Join&Login

export const join = (req, res) => res.render("join", { pageTitle: "Join" });
export const login = (req, res) => res.render("login", { pageTitle: "Login" });
export const logout = (req, res) => res.render("logout", { pageTitle: "Logout" });
import routes from "../routes";
// 회원가입 -> 완료 -> 홈화면으로 Redirect
export const getJoin = (req, res) => {
res.render("join", { pageTitle: "Join" });
};
export const postJoin = (req, res) => {
const {
body: { name, email, password, password2 },
} = req;
if (password !== password2) {
res.status(400);
res.render("join", { pageTitle: "Join" });
} else {
// To Do: Register User
// To Do: Log user in
res.redirect(routes.home);
}
};
export const getLogin = (req, res) =>
res.render("login", { pageTitle: "Login" });
export const postLogin = (req, res) => {
res.redirect(routes.home);
};
export const logout = (req, res) =>
res.render("logout", { pageTitle: "Logout" });
export const users = (req, res) => res.render("users", { pageTitle: "Users" });
export const userDetail = (req, res) => res.render("userDetail", { pageTitle: "User Detail" });
export const editProfile = (req, res) => res.render("editProfile", { pageTitle: "Edit Profile" });
export const changePassword = (req, res) => res.render("changePassword", { pageTitle: "Change Password" });
\ No newline at end of file
export const userDetail = (req, res) =>
res.render("userDetail", { pageTitle: "User Detail" });
export const editProfile = (req, res) =>
res.render("editProfile", { pageTitle: "Edit Profile" });
export const changePassword = (req, res) =>
res.render("changePassword", { pageTitle: "Change Password" });
\ No newline at end of file
......
export const home = (req, res) => res.render("home", { pageTitle: "Home" });
import { videos } from "../db";
export const home = (req, res) => {
res.render("home", { pageTitle: "Home", videos });
};
export const search = (req, res) => {
const {
query: { term: searchingBy }
query: { term: searchingBy },
} = req; // == const searchingBy = req.query.term;
res.render("search", { pageTitle: "Search", searchingBy });
}
res.render("search", { pageTitle: "Search", searchingBy, videos });
};
export const videos = (req, res) => res.send("videos", { pageTitle: "Videos" });
export const upload = (req, res) => res.render("upload", { pageTitle: "Upload" });
export const videoDetail = (req, res) => res.render("videoDetail", { pageTitle: "Video Detail" });
export const editVideo = (req, res) => res.render("editVideo", { pageTitle: "Edit Video" });
......
export const videos = [{
id: 324393,
title: "Video awesome",
description: "This is something I love",
views: 24,
videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
creator: {
id: 121212,
name: "Nicolas",
email: "nico@las.com",
},
},
{
id: 1212121,
title: "Video super",
description: "This is something I love",
views: 24,
videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
creator: {
id: 121212,
name: "Nicolas",
email: "nico@las.com",
},
},
{
id: 55555,
title: "Video nice",
description: "This is something I love",
views: 24,
videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
creator: {
id: 121212,
name: "Nicolas",
email: "nico@las.com",
},
},
{
id: 11111,
title: "Video perfect",
description: "This is something I love",
views: 24,
videoFile: "https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4",
creator: {
id: 121212,
name: "Nicolas",
email: "nico@las.com",
},
},
];
\ No newline at end of file
......@@ -3,5 +3,9 @@ import routes from "./routes";
export const localsMiddleware = (req, res, next) => {
res.locals.siteName = 'my Youtube';
res.locals.routes = routes;
res.locals.user = {
isAuthenticated: true,
id: 1,
};
next();
};
\ No newline at end of file
......
import express from "express";
import routes from "../routes";
import { home, search } from "../controllers/videoController";
import { join, login, logout } from "../controllers/userController";
import {
logout,
getJoin,
postJoin,
getLogin,
postLogin,
} from "../controllers/userController";
const globalRouter = express.Router();
globalRouter.get(routes.home, home);
globalRouter.get(routes.join, join);
globalRouter.get(routes.login, login);
globalRouter.get(routes.join, getJoin);
globalRouter.post(routes.join, postJoin);
globalRouter.get(routes.login, getLogin);
globalRouter.post(routes.login, postLogin);
globalRouter.get(routes.logout, logout);
globalRouter.get(routes.search, search);
export default globalRouter;
\ No newline at end of file
......
import express from "express";
import routes from "../routes";
import { users, userDetail, editProfile, changePassword } from "../controllers/userController";
import {
userDetail,
editProfile,
changePassword,
} from "../controllers/userController";
const userRouter = express.Router();
userRouter.get(routes.users, users);
userRouter.get(routes.editProfile, editProfile);
userRouter.get(routes.userDetail, userDetail);
userRouter.get(routes.changePassword, changePassword);
userRouter.get(routes.userDetail(), userDetail);
export default userRouter;
/*
userRouter.get("/", (req, res) => res.send("user index"));
userRouter.get("/edit", (req, res) => res.send("user edit"));
......
import express from "express";
import routes from "../routes";
import { videos, upload, videoDetail, editVideo, deleteVideo } from "../controllers/videoController";
import {
upload,
videoDetail,
editVideo,
deleteVideo,
} from "../controllers/videoController";
//export const videoRouter = express.Router(); 이렇게하면 이 변수만 export하게 된다.
const videoRouter = express.Router();
videoRouter.get(routes.videos, videos);
videoRouter.get(routes.upload, upload);
videoRouter.get(routes.videoDetail, videoDetail);
videoRouter.get(routes.editVideo, editVideo);
videoRouter.get(routes.videoDetail(), videoDetail);
videoRouter.get(routes.deleteVideo, deleteVideo);
export default videoRouter;
\ No newline at end of file
......
//Global
// Global
const HOME = "/";
const JOIN = "/join";
const LOGIN = "/login";
......@@ -25,14 +25,26 @@ const routes = {
logout: LOGOUT,
search: SEARCH,
users: USERS,
userDetail: USER_DETAIL,
userDetail: (id) => {
if (id) {
return `/users/${id}`;
} else {
return USER_DETAIL;
}
},
editProfile: EDIT_PROFILE,
changePassword: CHANGE_PASSWORD,
videos: VIDEOS,
upload: UPLOAD,
videoDetail: VIDEO_DETAIL,
videoDetail: (id) => {
if (id) {
return `/videos/${id}`;
} else {
return VIDEO_DETAIL;
}
},
editVideo: EDIT_VIDEO,
deleteVideo: DELETE_VIDEO
deleteVideo: DELETE_VIDEO,
};
export default routes;
\ No newline at end of file
......
extends layouts/main
block content
p Hello This is change Password
\ No newline at end of file
.form-container
form(action=`/users${routes.changePassword}`, method="post")
input(type="password", name="oldPasswod", placeholder="Current Password")
input(type="password", name="newPassword", placeholder="New Password")
input(type="password", name="newPassword1", placeholder="Verify New Password")
input(type="submit", value="Change Password")
\ No newline at end of file
......
......@@ -8,4 +8,4 @@ block content
input(type="text", placeholder="Name", name="name")
input(type="email", placeholder="Email", name="email")
input(type="submit", value="Update Profile")
a.form-container__link(href=routes.changePassword) Change Password
\ No newline at end of file
a.form-container__link(href=`/users${routes.changePassword}`) Change Password
\ No newline at end of file
......
extends layouts/main
block content
p Hello This is edit Video
\ No newline at end of file
.form-container
form(action=`/videos${routes.editVideo}`, method="post")
input(type="text", placeholder="Title", name="title")
textarea(name="description", placeholder="Description")
input(type="submit", value="Update Video")
a.form-container__link.form-container__link--delete(href=`/videos${routes.deleteVideo}`) Delete Video
\ No newline at end of file
......
extends layouts/main
include mixins/videoBlock
block content
.videos
h1 Video
\ No newline at end of file
each item in videos
+videoBlock({
title : item.title,
views: item.views,
videoFile:item.videoFile
})
\ No newline at end of file
......
mixin videoBlock(video = {})
.videoBlock
video.videoBlock__thumbnail(src=video.videoFile, controls=true)
h4.videoBlock__title=video.title
h6.videoBlock__views=video.views
\ No newline at end of file
......@@ -7,7 +7,15 @@ header.header
input(type="text", placeholder="Search by term...", name="term")
.header__column
ul
if !user.isAuthenticated
li
a(href=routes.join) Join
li
a(href=routes.login) Log In
else
li
a(href=routes.upload) Upload
li
a(href=routes.userDetail(user.id)) Profile
li
a(href=routes.logout) Log out
......
extends layouts/main
include mixins/videoBlock
block content
.search__header
h3 Searching for: #{searchingBy}
.search__videos
each item in videos
+videoBlock({
title : item.title,
views: item.views,
videoFile:item.videoFile
})
\ No newline at end of file
......
extends layouts/main
block content
p Hello This is Upload
\ No newline at end of file
.form-container
form(action=`/videos${routes.upload}`, method="post")
label(for="file") Video File
input(type="file", id="file", name="file")
input(type="text", placeholder="Title", name="title")
textarea(name="description", placeholder="Description")
input(type="submit", value="Upload Video")
\ No newline at end of file
......