Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
cded7f6
feat: project init
scheng0718 Aug 22, 2023
d0c33f4
feat: setup all data models and relations
scheng0718 Aug 23, 2023
aea3c22
feat: add user seeder data
scheng0718 Aug 23, 2023
60f5a17
fix: update two foreign key issues based on test result
scheng0718 Aug 23, 2023
79f0c6a
feat: add tweet seeder data
scheng0718 Aug 23, 2023
1f443cd
Merge pull request #1 from scheng0718/feature/add-database-setup
gibbs-shih Aug 23, 2023
441ec4f
modify string limit and Like related association
gibbs-shih Aug 23, 2023
a52053b
modify models string limit and like related association
gibbs-shih Aug 23, 2023
610f058
Merge pull request #2 from scheng0718/feature/a
anniehuang0410 Aug 23, 2023
a3fad77
feat: add replies seeder data
scheng0718 Aug 23, 2023
1c94696
feat: add project's common folders
scheng0718 Aug 23, 2023
6e51010
feat: add likeCounts and replyCounts to tweet table
scheng0718 Aug 23, 2023
6d7c379
fix: update bootstrap CDN in main file
scheng0718 Aug 24, 2023
7c57e1c
Merge pull request #3 from scheng0718/feature/update-seeder-data
anniehuang0410 Aug 24, 2023
cf44ea6
Merge pull request #4 from scheng0718/feature/update-project-folders
anniehuang0410 Aug 24, 2023
6b8f019
feat: add followship function and routes
gibbs-shih Aug 24, 2023
9b2ade8
feat: add followship function and routes
gibbs-shih Aug 24, 2023
1e162f5
feat: follow功能新增判斷自己、改modles載入路徑
gibbs-shih Aug 24, 2023
bcd3f55
Merge pull request #5 from scheng0718/followship_function_and_routes
anniehuang0410 Aug 24, 2023
c5dd54b
feat: add icons and logo image
anniehuang0410 Aug 24, 2023
763d391
feat: add css basic style and google font
anniehuang0410 Aug 24, 2023
c840001
add passport config and auth middleware
gibbs-shih Aug 24, 2023
c0288a3
Merge pull request #6 from scheng0718/feature/images
scheng0718 Aug 24, 2023
cdd9f1f
modify passport typo
gibbs-shih Aug 24, 2023
b532969
Merge pull request #7 from scheng0718/followship_function_and_routes
scheng0718 Aug 24, 2023
906acea
feature: add common files in helpers and middleware
scheng0718 Aug 24, 2023
7c08afd
Merge pull request #8 from scheng0718/feature/add-common-files
anniehuang0410 Aug 24, 2023
2a9899d
feature: remove two columns from tweet table
scheng0718 Aug 24, 2023
9959fa5
Merge pull request #9 from scheng0718/feature/remove-tweet-columns
gibbs-shih Aug 24, 2023
9547b3d
feature: setup app.js file
scheng0718 Aug 24, 2023
1176c93
feat: add admin sign in page
scheng0718 Aug 24, 2023
243c81c
feat: add admin signin page and flash message
scheng0718 Aug 25, 2023
3188234
feat: add session secret to .env
scheng0718 Aug 25, 2023
576b9cc
fix admin's failure redirect
scheng0718 Aug 25, 2023
e3b45be
Merge pull request #10 from scheng0718/feature/add-admin-page-login
anniehuang0410 Aug 25, 2023
d9cf3a9
feat: implement admin login and logout function and add admin tweets …
scheng0718 Aug 25, 2023
7a6d725
feat: add left sidebar view and getTweet route for test
anniehuang0410 Aug 25, 2023
70570cf
seperate modal from the doc and add submit form
anniehuang0410 Aug 25, 2023
b202915
feat: signin page
gibbs-shih Aug 25, 2023
da524fc
Merge pull request #11 from scheng0718/feature/implement-admin-login
gibbs-shih Aug 25, 2023
abd24f2
uninstall nodemon
gibbs-shih Aug 25, 2023
538a6d8
modify signup page
gibbs-shih Aug 25, 2023
e338461
Merge pull request #12 from scheng0718/feature/signin
scheng0718 Aug 25, 2023
740f76c
feat: add getTweets route
anniehuang0410 Aug 25, 2023
ae0e208
resolve merge problem
anniehuang0410 Aug 25, 2023
6314db9
Merge branch 'master' into feature/frontend-left-sidebar
anniehuang0410 Aug 25, 2023
3d0795b
Merge pull request #13 from scheng0718/feature/frontend-left-sidebar
scheng0718 Aug 25, 2023
e911d06
feat: check the switch between user and admin login page
scheng0718 Aug 25, 2023
9011b2e
feat: logOut
gibbs-shih Aug 26, 2023
526a887
feat: add editUser and getUserTweets functions
anniehuang0410 Aug 26, 2023
86b3fa1
feat: add admin tweets page
scheng0718 Aug 26, 2023
b82f7c1
remove duplicate route
scheng0718 Aug 26, 2023
b1fae2b
feat: signup function
gibbs-shih Aug 26, 2023
5ebd9b4
Merge pull request #14 from scheng0718/feature/frontend-left-sidebar-v2
gibbs-shih Aug 26, 2023
ec10e33
feat: add basic frame of right sidebar
anniehuang0410 Aug 26, 2023
22c8a55
Merge branch 'master' into feature/add-admin-tweets-page
anniehuang0410 Aug 26, 2023
37d358a
Merge pull request #15 from scheng0718/feature/add-admin-tweets-page
anniehuang0410 Aug 26, 2023
7b0833e
Merge branch 'master' into feature/signup
anniehuang0410 Aug 26, 2023
57b296e
Merge pull request #16 from scheng0718/feature/signup
anniehuang0410 Aug 26, 2023
6919132
feat: modify SQL password
anniehuang0410 Aug 26, 2023
a1c1911
feat: left-sidebar gap fixed and modify some UI display
anniehuang0410 Aug 26, 2023
2361446
Merge pull request #18 from scheng0718/feature/modify-admin-left-sidebar
scheng0718 Aug 26, 2023
8f8cf60
Merge pull request #17 from scheng0718/feature/frontend-right-sidebar
scheng0718 Aug 26, 2023
3401fcc
feat: add main nav
anniehuang0410 Aug 27, 2023
14545fa
change password
anniehuang0410 Aug 27, 2023
627e9d8
feat: setting page
gibbs-shih Aug 27, 2023
3a2863d
Merge pull request #19 from scheng0718/feature/main-middle-nav
scheng0718 Aug 27, 2023
66e4098
fix setting page
gibbs-shih Aug 27, 2023
b97b653
Merge branch 'master' into feature/setting_page
gibbs-shih Aug 27, 2023
52b3d3f
Merge pull request #20 from scheng0718/feature/setting_page
scheng0718 Aug 27, 2023
7f564b6
feat: add tweet cards to main page
anniehuang0410 Aug 27, 2023
2e19dda
feat: implement admin's get users controller and route
scheng0718 Aug 27, 2023
47e2999
feat: add admin's handlebars template for all users page
scheng0718 Aug 28, 2023
5f9bffa
Merge branch 'master' into feature/add-admin-users-page
scheng0718 Aug 28, 2023
d640f2c
fix test case of shoule see all user list
scheng0718 Aug 28, 2023
eb5a722
feat: implement admin's delete tweet and adjust front-end page
scheng0718 Aug 28, 2023
9839ea7
feat: add tweet view template and tweetCount
anniehuang0410 Aug 28, 2023
8131c18
feat: optimize reply modal
anniehuang0410 Aug 28, 2023
caad336
feat: modify getUserTweets route
anniehuang0410 Aug 28, 2023
4d78793
fix: conflicts by merging master
anniehuang0410 Aug 28, 2023
64f7017
feat: add postTweet route
anniehuang0410 Aug 28, 2023
8278252
Merge pull request #21 from scheng0718/feature/add-admin-users-page
gibbs-shih Aug 28, 2023
4aaedc3
Merge branch 'master' into feature/admin-delete-tweet
gibbs-shih Aug 28, 2023
69f74df
Merge pull request #22 from scheng0718/feature/admin-delete-tweet
gibbs-shih Aug 28, 2023
64e1e5a
Merge branch 'master' into feature/main-page
gibbs-shih Aug 28, 2023
79de4f5
Merge pull request #23 from scheng0718/feature/main-page
gibbs-shih Aug 28, 2023
a020f37
fix amdin user controller and css setting
scheng0718 Aug 28, 2023
abfd82d
Merge pull request #24 from scheng0718/fix/admin-controller-format
gibbs-shih Aug 28, 2023
527801e
add heroku procfile
scheng0718 Aug 28, 2023
8869418
Merge pull request #25 from scheng0718/feature/heroku-setting
gibbs-shih Aug 28, 2023
48bdca0
fix seeder data format for heroku
scheng0718 Aug 28, 2023
85216da
Merge pull request #26 from scheng0718/fix/seeder-data-format
gibbs-shih Aug 28, 2023
42a92fc
fix replies seeder data format for heroku
scheng0718 Aug 28, 2023
04004fc
Merge pull request #27 from scheng0718/fix/replies-seeder-data-format
anniehuang0410 Aug 28, 2023
da219df
feat: add like and unlike controller
scheng0718 Aug 29, 2023
e7fc3ff
feat: add like and unlike a tweet
scheng0718 Aug 29, 2023
6dcf738
feat: add red-like icon and remove right side bar from setting page
scheng0718 Aug 29, 2023
ebd1ac2
Merge pull request #28 from scheng0718/feature/add-like-unlike-tweet
anniehuang0410 Aug 29, 2023
4a7a168
feat: add profile middle part
anniehuang0410 Aug 29, 2023
6da4e5a
feat: create upper part of getTweet page
anniehuang0410 Aug 29, 2023
7060203
Merge pull request #29 from scheng0718/feature/build-views
scheng0718 Aug 29, 2023
f5a4fe1
fix test case of like and unlike feature
scheng0718 Aug 29, 2023
2b88e97
Merge pull request #30 from scheng0718/fix-like-unlike-test
gibbs-shih Aug 29, 2023
dd7d7c4
feat: followship pages and function
gibbs-shih Aug 29, 2023
c62854e
Merge branch 'master' into feature/followship
gibbs-shih Aug 29, 2023
d9a211a
Merge pull request #31 from scheng0718/feature/followship
scheng0718 Aug 29, 2023
e4dbf1c
fix test case for followers and followings
scheng0718 Aug 29, 2023
1629b6d
feat: add controller and routes for all likes tab
scheng0718 Aug 30, 2023
5e40aa4
Merge pull request #32 from scheng0718/fix-followship-test
gibbs-shih Aug 30, 2023
7118612
feat: add post reply function
anniehuang0410 Aug 30, 2023
7a694d6
fix: remove check console
anniehuang0410 Aug 30, 2023
ac8805e
feat: render all replies
anniehuang0410 Aug 30, 2023
b0978c1
feat: modify reply order logic
anniehuang0410 Aug 30, 2023
172fff5
Merge pull request #33 from scheng0718/feature/add-reply
scheng0718 Aug 30, 2023
f156262
Merge pull request #34 from scheng0718/feature/show-replies
scheng0718 Aug 30, 2023
7209a0b
Merge branch 'master' into feature/add-all-likes-tab
scheng0718 Aug 30, 2023
c735a4a
feat: modify getLikes and render the all liked tab
scheng0718 Aug 30, 2023
84adc14
feat: update get user tweets controller and render the tab
scheng0718 Aug 31, 2023
6ea3f33
fix reply bug for get likes route
scheng0718 Aug 31, 2023
8841034
fix and unify the naming format
scheng0718 Aug 31, 2023
1a2a75c
feat: right side bar
gibbs-shih Aug 31, 2023
0f43093
Merge branch 'master' into feature/right_sidebar
gibbs-shih Aug 31, 2023
2fc4a06
feat: add get replies tab
scheng0718 Aug 31, 2023
905f6ab
Merge pull request #36 from scheng0718/feature/add-all-tabs
anniehuang0410 Aug 31, 2023
d488981
Merge branch 'master' into feature/right_sidebar
scheng0718 Aug 31, 2023
de9c8d6
Merge pull request #35 from scheng0718/feature/right_sidebar
scheng0718 Aug 31, 2023
f400913
fix curly bracket issue
scheng0718 Aug 31, 2023
73caa63
Merge pull request #37 from scheng0718/fix-tweet-controller
anniehuang0410 Aug 31, 2023
98acf99
feat: add edit-user-modal view
anniehuang0410 Aug 31, 2023
3708b0e
fix: take away useless psrt
anniehuang0410 Aug 31, 2023
48362bf
Merge branch 'master' into feature/edit-user-modal-view
anniehuang0410 Aug 31, 2023
5c29693
fix: make new user browse three tabs and topUsers and add default val…
scheng0718 Sep 1, 2023
55811c1
fix admin tweets description limit
scheng0718 Sep 1, 2023
d17da7e
fix each route for user info page
scheng0718 Sep 1, 2023
7cff756
fix return page and round circle avatar
scheng0718 Sep 1, 2023
ea4a62f
Merge pull request #39 from scheng0718/fix-new-user-default
gibbs-shih Sep 1, 2023
be51f10
fix: change to taking elements by tweetsUser
anniehuang0410 Sep 1, 2023
d4a0a7f
fix: add req logout bug
scheng0718 Sep 1, 2023
43c3824
Merge branch 'master' into feature/edit-user-modal-view
anniehuang0410 Sep 1, 2023
5101d9e
Merge pull request #40 from scheng0718/fix-logout-function
gibbs-shih Sep 1, 2023
04cb2f2
feat: add two icons
anniehuang0410 Sep 1, 2023
e6c72cf
Merge branch 'master' into feature/edit-user-modal-view
anniehuang0410 Sep 1, 2023
d2e2681
Merge pull request #38 from scheng0718/feature/edit-user-modal-view
scheng0718 Sep 2, 2023
5dbb156
feat: add profile logic
anniehuang0410 Sep 2, 2023
b05498f
Merge branch 'master' into feature/profile-middle-button-logic
anniehuang0410 Sep 2, 2023
21a3757
modify notifications
gibbs-shih Sep 2, 2023
72582d9
modify signin page
gibbs-shih Sep 2, 2023
de5ca3d
modify admin signin page
gibbs-shih Sep 2, 2023
de1536d
modify signup page
gibbs-shih Sep 2, 2023
cf40a7f
modify notifications position
gibbs-shih Sep 2, 2023
654ac51
modify setting page
gibbs-shih Sep 2, 2023
1c108f6
add wordCount in signin admin-signin signup setting
gibbs-shih Sep 2, 2023
e57a0f5
add 字數超出上限 in form
gibbs-shih Sep 2, 2023
908e365
Merge pull request #41 from scheng0718/feature/profile-middle-button-…
gibbs-shih Sep 2, 2023
5f89e74
modify 密碼不一致 and hover&focus class
gibbs-shih Sep 2, 2023
e32fde0
fix: modify admin login
scheng0718 Sep 2, 2023
8df0383
feat: add post api route
anniehuang0410 Sep 2, 2023
32cef19
fix: wrong password
anniehuang0410 Sep 2, 2023
2a8506d
Merge pull request #43 from scheng0718/fix-admin-user-login
gibbs-shih Sep 2, 2023
8a0bfa7
feat: add post route and success in changing name and description
anniehuang0410 Sep 2, 2023
7d4dedd
feat: modify modal button UI
anniehuang0410 Sep 2, 2023
d82803b
Merge pull request #42 from scheng0718/modify/notification_and_form
scheng0718 Sep 2, 2023
3789a79
Merge pull request #44 from scheng0718/feature/post-user-route
gibbs-shih Sep 2, 2023
098f60c
fix: modify imgurFileHandler
scheng0718 Sep 3, 2023
edb74ac
fix: admin log in
scheng0718 Sep 3, 2023
60a1c20
fix: modify api post user to pass test case
scheng0718 Sep 3, 2023
e84cb60
Merge pull request #45 from scheng0718/fix-image-upload
gibbs-shih Sep 3, 2023
66f00af
user and admin left side bar
gibbs-shih Sep 3, 2023
e46440b
fix: scroll bar
gibbs-shih Sep 3, 2023
cbcfc95
fix: admin side bar and edge
gibbs-shih Sep 3, 2023
92ba52c
Merge pull request #46 from scheng0718/fix/admin_page
anniehuang0410 Sep 3, 2023
9b2a139
feat: fix some input UI issues and add middle scrollbar
anniehuang0410 Sep 3, 2023
1e20cc2
Merge branch 'master' into feature/modify-views
anniehuang0410 Sep 3, 2023
38cd3dc
add confirming messages for leaving setting page
gibbs-shih Sep 3, 2023
fd59a6d
update putUser redirect
gibbs-shih Sep 3, 2023
daa66a5
modify 前後台 登入無權限 訊息
gibbs-shih Sep 3, 2023
7310156
modify passport localStrategy for user/admin validation
gibbs-shih Sep 3, 2023
b58bd57
for push again
gibbs-shih Sep 3, 2023
afeccec
modify success msg
gibbs-shih Sep 3, 2023
e5051f9
Merge pull request #47 from scheng0718/fix/some_routes
scheng0718 Sep 3, 2023
e3911e3
Merge branch 'master' into feature/modify-views
scheng0718 Sep 3, 2023
3059e28
Merge pull request #48 from scheng0718/feature/modify-views
scheng0718 Sep 3, 2023
53ba4bf
fix: add session secret to app.js
scheng0718 Sep 3, 2023
e389808
Merge pull request #49 from scheng0718/fix-session-secret
gibbs-shih Sep 3, 2023
84c9d08
fix: modify passport setting
scheng0718 Sep 3, 2023
1c3d630
Merge pull request #50 from scheng0718/fix-travis-test
gibbs-shih Sep 3, 2023
1aed022
fix: modify api json section
scheng0718 Sep 3, 2023
e979c4a
Merge pull request #51 from scheng0718/fix-api-controller-test
gibbs-shih Sep 3, 2023
3e78eed
fix: frontend ui validation
anniehuang0410 Sep 3, 2023
260d924
feat: add README and modify .env.example file
scheng0718 Sep 3, 2023
d8faa0b
Merge pull request #52 from scheng0718/add-readme-file
anniehuang0410 Sep 3, 2023
47c6026
feat: add thiner scroll bar to display the button
scheng0718 Sep 3, 2023
66ee0f5
feat: add ellipis for tweets over 50 length in admin tweets page
scheng0718 Sep 4, 2023
8dad9f4
Merge pull request #53 from scheng0718/adjust-width-scroll-bar
gibbs-shih Sep 4, 2023
5cda7ff
Merge pull request #54 from scheng0718/add-ellipis-admin-tweets
gibbs-shih Sep 4, 2023
c134a45
fix: add root default account and password in readme
scheng0718 Sep 4, 2023
8a36993
Merge pull request #55 from scheng0718/add-root-account-readme
gibbs-shih Sep 4, 2023
30c2ec2
fix: tweet replies page
gibbs-shih Sep 4, 2023
8cbf1a6
Merge pull request #56 from scheng0718/fix/replies_page
scheng0718 Sep 4, 2023
da5b7f5
fix: add global installation for nodemon in readme file
scheng0718 Sep 4, 2023
ab658bd
Merge pull request #57 from scheng0718/modify-install-nodemon-readme
gibbs-shih Sep 4, 2023
0133e80
feat: add reply modal validations
anniehuang0410 Sep 4, 2023
38e4276
Merge branch 'master' into feature/bug-fix
anniehuang0410 Sep 4, 2023
7eba78c
fix: fix password
anniehuang0410 Sep 4, 2023
1c35aab
Merge pull request #58 from scheng0718/feature/bug-fix
gibbs-shih Sep 4, 2023
d142885
Revert "Merge pull request #58 from scheng0718/feature/bug-fix"
scheng0718 Sep 4, 2023
6b59d9b
feat: implement preview of uploading avatar and cover photo and delet…
scheng0718 Sep 29, 2023
a7d2204
Merge pull request #59 from scheng0718/feature/add-preview-avatar-cover
gibbs-shih Sep 29, 2023
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IMGUR_CLIENT_ID=SKIP
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/*
/test/*
14 changes: 14 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
env:
browser: true
commonjs: true
es2021: true
extends:
- standard
parserOptions:
ecmaVersion: 12
rules:
arrow-parens:
- warn
- as-needed


53 changes: 53 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
* text=auto

# Source code
*.css text diff=css
*.html text diff=html
*.js text
*.json text

# Documentation
*.markdown text diff=markdown
*.md text diff=markdown
*.txt text

# Templates
*.handlebars text
*.hbs text

# Configs
*.cnf text
*.conf text
*.config text
.editorconfig text
.env text
.env.* text
.gitattributes text
.gitconfig text
*.lock text -diff
package.json text eol=lf
package-lock.json text -diff
yarn.lock text -diff
*.yaml text
*.yml text
browserslist text

# Heroku
Procfile text

# Graphics
*.gif binary
*.ico binary
*.jpg binary
*.jpeg binary
*.pdf binary
*.png binary
# SVG treated as an asset (binary) by default.
*.svg text
# If you want to treat it as binary,
# use the following line instead.
# *.svg binary
*.webp binary

# Ignore files (like .npmignore or .gitignore)
*.*ignore text
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ typings/
.fusebox/

# DynamoDB Local files
.dynamodb/
.dynamodb/

# image related
temp/
upload/
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: NODE_ENV=production node app.js
107 changes: 107 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

# Simple Twitter

使用 node.js 和 express 打造的社交網站。使用者可以進行註冊、登入、登出、瀏覽和發布推文,編輯個人資料或瀏覽他人資料,瀏覽其他人的推文及回覆。此外,網站還設有後台管理功能,允許管理者瀏覽和刪除特定推文,以及查看所有使用者的資訊。

# 功能 Features

- 使用者功能
- 註冊/登入/登出功能。
- 重複註冊/登入資訊錯誤/尚未登入使用網站服務,會出現錯誤提示。
- 使用者能在首頁瀏覽所有的推文。
- 使用者可以新增推文。
- 使用者能查看特定貼文的內容與回覆串。
- 使用者能回覆別人推文。
- 點擊貼文中使用者頭像時,能瀏覽該使用者的個人資料及推文內容。
- 使用者可以追蹤/取消追蹤其他使用者。
- 使用者能編輯自己的名稱、介紹、大頭照和個人背景。
- 使用者可以對別人的推文按讚或取消讚。
- 使用者在右側欄位能瀏覽並追蹤/取消追蹤排名前 10 的使用者推薦清單。
- 後台管理功能
- 管理者可以瀏覽全站的推文內容清單 & 刪除特定推文。
- 管理者可以瀏覽站內所有的使用者清單。


# 環境安裝 Environment Setup

詳細資訊請參考 package.json 檔案
- Visual Studio Code: 1.81.1
- Node.js: 14.16.0
- Express.js: 4.16.4
- Express-handlebars: 5.3.3
- bcryptjs: 2.4.3
- express-session: 1.15.6
- method-override: 3.0.0
- passport: 0.4.0
- passport-local: 1.0.0
- sequelize: 6.18.0
- sequelize-cli: 6.2.0

# 安裝與執行 Install & Execution

1. 安裝 Node.js
2. 開啟終端機將本專案存至本機:
```
git clone https://github.com/scheng0718/twitter-fullstack-2020.git
```
3. 進入存放專案的資料夾
```
cd twitter-fullstack-2020
```
4. 設定環境變數
參考根目錄底下的 .env.example 檔案,替換 SKIP 的內容,新增至 .env 檔案。

5. 建立資料庫
開啟 MySQL workbench,連線至本地資料庫,建立以下資料庫

```
drop database if exists ac_twitter_workspace;
create database ac_twitter_workspace;
use ac_twitter_workspace;

drop database if exists ac_twitter_workspace_test;
create database ac_twitter_workspace_test;
use ac_twitter_workspace_test;
```
6. 安裝 npm 套件
```
npm install
```
7. 安裝 nodemon
```
npm install -g nodemon
```
8. 資料庫遷移設定
```
npx sequelize db:migrate
```
9. 加入預設種子資料
```
npx sequelize db:seed:all
```
10. 啟動專案
```
npm run dev
```
11. 瀏覽器開啟本機頁面
當終端機出現下列訊息" "Example app listening on port 3000!" 表示本機伺服器建立成功,在瀏覽器輸入 http://localhost:3000 使用本專案。

12. 預設前台使用者及後台管理者帳號
加入種子資料後,可以使用預設帳號/密碼登入網站
- User Account 1
- 帳號: user1
- 密碼: 12345678
- User Account 2
- 帳號: user2
- 密碼: 12345678
- 管理者帳號
- 帳號: root
- 密碼: 12345678

13. 結束專案
```
Ctrl + C
```

## 開發人員 Developers
Annie/Evan/瑞晨
12 changes: 6 additions & 6 deletions _helpers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function ensureAuthenticated(req) {
return req.isAuthenticated();
function ensureAuthenticated (req) {
return req.isAuthenticated()
}

function getUser(req) {
return req.user;
function getUser (req) {
return req.user
}

module.exports = {
ensureAuthenticated,
getUser,
};
getUser
}
43 changes: 36 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const path = require('path')
const express = require('express')
const helpers = require('./_helpers');

const handlebars = require('express-handlebars')
const session = require('express-session')
const passport = require('./config/passport')
const handlebarsHelpers = require('./helpers/handlebars-helpers')
const flash = require('connect-flash')
const methodOverride = require('method-override')
const routes = require('./routes')
const helpers = require('./_helpers')
const app = express()
const port = 3000

// use helpers.getUser(req) to replace req.user
// use helpers.ensureAuthenticated(req) to replace req.isAuthenticated()
const port = process.env.PORT || 3000
const SESSION_SECRET = 'secret'

app.get('/', (req, res) => res.send('Hello World!'))
app.engine('hbs', handlebars({ defaultLayout: 'main', extname: '.hbs', helpers: handlebarsHelpers }))
app.set('view engine', 'hbs')
app.use(express.urlencoded({ extended: true }))
app.use(express.static('public'))
app.use(express.json())
app.use(session({
secret: SESSION_SECRET,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(flash())
app.use(methodOverride('_method'))
app.use('/upload', express.static(path.join(__dirname, 'upload')))
app.use((req, res, next) => {
res.locals.success_messages = req.flash('success_messages')
res.locals.error_messages = req.flash('error_messages')
res.locals.user = helpers.getUser(req)
next()
})
app.use(routes)
app.listen(port, () => console.log(`Example app listening on port ${port}!`))

module.exports = app
6 changes: 1 addition & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
"logging": false
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
"use_env_variable": "MYSQL_DATABASE_URL"
},
"travis": {
"username": "travis",
Expand Down
49 changes: 49 additions & 0 deletions config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const passport = require('passport')
const LocalStrategy = require('passport-local')
const bcrypt = require('bcryptjs')
const { User, Like, Reply, Tweet } = require('../models')

passport.use(new LocalStrategy(
{
usernameField: 'account',
passwordField: 'password',
passReqToCallback: true
},
(req, account, password, cb) => {
User.findOne({ where: { account } })
.then(user => {
if (!user) return cb(null, false, req.flash('error_messages', '帳號不存在!'))
if (req.originalUrl === '/admin/signin') {
if (user.dataValues.role !== 'admin') return cb(null, false, req.flash('error_messages', '帳號不存在!'))
}
if (req.originalUrl === '/signin') {
if (user.dataValues.role === 'admin') return cb(null, false, req.flash('error_messages', '帳號不存在!'))
}
bcrypt.compare(password, user.password)
.then(res => {
if (!res) return cb(null, false, req.flash('error_messages', '密碼輸入錯誤!'))
return cb(null, user)
})
})
}
))

passport.serializeUser((user, cb) => {
cb(null, user.id)
})

passport.deserializeUser((id, cb) => {
return User.findByPk(id, {
include: [
{ model: User, as: 'Followers' },
{ model: User, as: 'Followings' },
{ model: Like, as: 'LikedTweets', include: Tweet },
{ model: Reply, include: Tweet },
{ model: Tweet }
]
})
.then(user => cb(null, user.toJSON()))
.catch(err => cb(err))
})

module.exports = passport
Loading