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

全端組:阿佑、汭蓉、leo #315

Open
wants to merge 221 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
221 commits
Select commit Hold shift + click to select a range
812ad67
feat : Updata package-lock.json
ZHENG-YOU-LU Dec 11, 2022
0320e50
feat : Update "start", "dev","test"
ZHENG-YOU-LU Dec 11, 2022
c9fbc76
add simple someing for view
ZHENG-YOU-LU Dec 11, 2022
f53e769
feat : create models "Followship","Like","Reply","Tweet","User"
ZHENG-YOU-LU Dec 13, 2022
ae6ac2d
Merge pull request #1 from Rae-Lee/feature/c
Rae-Lee Dec 13, 2022
9f400b3
feat: add standard
lomo007 Dec 14, 2022
40938f6
feat:modify models association
Rae-Lee Dec 14, 2022
29b84d0
feat:like model add isLike
Rae-Lee Dec 14, 2022
43ea6a0
feat: user model add background and account
Rae-Lee Dec 14, 2022
4bac224
feat: modify like, tweet, user model
Rae-Lee Dec 14, 2022
fe99ea4
Merge pull request #2 from Rae-Lee/feature/create-models
Rae-Lee Dec 15, 2022
0d8cb97
feat : add user-signin , user-singup and admin-signin
ZHENG-YOU-LU Dec 15, 2022
48b15fb
merge
lomo007 Dec 15, 2022
f1930df
feat : Merge branch "feature/login"
ZHENG-YOU-LU Dec 15, 2022
ad15654
feat : update error_messages
ZHENG-YOU-LU Dec 16, 2022
d1042f5
feat: tweet home page
lomo007 Dec 16, 2022
4483afc
feat: merge
lomo007 Dec 16, 2022
02a2a0a
feat: merge conflict
lomo007 Dec 16, 2022
2c10f0a
feat: merge conflict
lomo007 Dec 16, 2022
6e33531
Merge pull request #5 from Rae-Lee/feature/tweetPage
Rae-Lee Dec 17, 2022
12e3c9e
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 17, 2022
1e544a3
feat : update model like
ZHENG-YOU-LU Dec 17, 2022
afa89c8
feat : update model like
ZHENG-YOU-LU Dec 17, 2022
cc02e13
feat : update models
ZHENG-YOU-LU Dec 17, 2022
26a5e67
feat : update tweets.hbs
ZHENG-YOU-LU Dec 17, 2022
d546bb9
Merge pull request #6 from Rae-Lee/feature/update-models
Rae-Lee Dec 17, 2022
721bede
feat: modify conflict
lomo007 Dec 17, 2022
0d805db
feat:merge conflict modify
Rae-Lee Dec 17, 2022
1b2a2a5
feat : update express-handlebars
ZHENG-YOU-LU Dec 17, 2022
50d9a79
Merge pull request #3 from Rae-Lee/feature/login
Rae-Lee Dec 17, 2022
69ff258
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
Rae-Lee Dec 17, 2022
3484312
feat: page modify
lomo007 Dec 17, 2022
a1603ba
feat: temp logout btn
lomo007 Dec 17, 2022
7b50de8
feat: modify auth
lomo007 Dec 17, 2022
e5db968
feat: modify auth2
lomo007 Dec 17, 2022
b57672c
feat: merge conflict of auth
lomo007 Dec 17, 2022
16355fb
feat: merge conflict of auth
lomo007 Dec 17, 2022
5f7f5ad
Merge pull request #7 from Rae-Lee/feature/twitterPage2
Rae-Lee Dec 17, 2022
29b623c
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 17, 2022
136180e
feat :add users-seed-file
ZHENG-YOU-LU Dec 17, 2022
229993c
feat : add tweets-seed-file
ZHENG-YOU-LU Dec 17, 2022
8285f58
feat : add repelies-seed-file
ZHENG-YOU-LU Dec 17, 2022
3935c98
Merge pull request #9 from Rae-Lee/feature/create-seeders
Rae-Lee Dec 17, 2022
8594a42
feat : update login-page register-page
ZHENG-YOU-LU Dec 18, 2022
15992aa
feat : update login style
ZHENG-YOU-LU Dec 18, 2022
a6de546
feat: admin tweets and tweet page
lomo007 Dec 18, 2022
26ec47e
Merge pull request #10 from Rae-Lee/feature/login-page
lomo007 Dec 18, 2022
aaeb7cf
Update style.css
ZHENG-YOU-LU Dec 18, 2022
4c19fef
Merge branch 'main' into feature/tweetCRUD
ZHENG-YOU-LU Dec 18, 2022
8e77f42
Merge pull request #11 from Rae-Lee/feature/tweetCRUD
ZHENG-YOU-LU Dec 18, 2022
94c4eeb
update package
ZHENG-YOU-LU Dec 18, 2022
4d89d8f
feat : update error-messages
ZHENG-YOU-LU Dec 19, 2022
1ea7eac
feat: modify ui rwd
lomo007 Dec 19, 2022
39374d8
feat: add tweet-controller addlike/removelike
lomo007 Dec 19, 2022
fa60673
feat: add getTweets isLike
lomo007 Dec 20, 2022
e8bcf06
feat : create admin-user route and page
ZHENG-YOU-LU Dec 20, 2022
798aff4
feat: modify like change and count
lomo007 Dec 20, 2022
5fd2f55
Merge pull request #13 from Rae-Lee/feature/admin-user
lomo007 Dec 20, 2022
98d5df8
Update style.css
ZHENG-YOU-LU Dec 20, 2022
45ea8f0
Merge branch 'main' into feature/error-mseeages
ZHENG-YOU-LU Dec 20, 2022
1db117f
Merge branch 'main' into feature/like
lomo007 Dec 20, 2022
b8be735
Merge pull request #14 from Rae-Lee/feature/error-mseeages
lomo007 Dec 20, 2022
1beb1c0
Merge branch 'main' into feature/like
ZHENG-YOU-LU Dec 20, 2022
a7431aa
Merge pull request #15 from Rae-Lee/feature/like
ZHENG-YOU-LU Dec 20, 2022
a9a3c5b
feat: add public/style.css and topFollowers partial page
Rae-Lee Dec 20, 2022
41dc239
feat:add reply function
Rae-Lee Dec 20, 2022
3945949
feat:add reply modal to tweets page
Rae-Lee Dec 20, 2022
01b0b50
feat: add public/style.css and topFollowers partial page
Rae-Lee Dec 16, 2022
f23a78a
feat:add follow function and following/follower page
Rae-Lee Dec 20, 2022
1a411db
feat: build tweet-head
lomo007 Dec 21, 2022
39d4d33
Merge pull request #18 from Rae-Lee/feature/replies
ZHENG-YOU-LU Dec 21, 2022
dadfbc0
Merge pull request #19 from Rae-Lee/feature/addreplymodal
ZHENG-YOU-LU Dec 21, 2022
de68aab
Merge branch 'main' into feature/followed
ZHENG-YOU-LU Dec 21, 2022
5a549db
Merge pull request #20 from Rae-Lee/feature/followed
ZHENG-YOU-LU Dec 21, 2022
a77ada9
feat: self-medal
lomo007 Dec 21, 2022
c8c591e
Merge branch 'main' into feature/tweetpage-head
lomo007 Dec 21, 2022
03577f1
feat:modify followship page
Rae-Lee Dec 21, 2022
ce3710f
feat:add follow tabs
Rae-Lee Dec 21, 2022
af7fc76
Merge pull request #23 from Rae-Lee/feature/modifyfollowpage
ZHENG-YOU-LU Dec 21, 2022
8cbbb52
feat: merge
lomo007 Dec 21, 2022
148e8a0
feat: conflict merge
lomo007 Dec 21, 2022
35c49f1
feat: router modify
lomo007 Dec 21, 2022
f3a2ece
feat: temp-mixed
lomo007 Dec 21, 2022
c3a769d
Merge pull request #24 from Rae-Lee/feature/temp-mixd
Rae-Lee Dec 21, 2022
4a87df2
feat: modify router
lomo007 Dec 21, 2022
64c7e81
feat: temp
lomo007 Dec 21, 2022
17bb02e
Merge pull request #25 from Rae-Lee/feature/temp-mixed
Rae-Lee Dec 21, 2022
b97a517
Merge pull request #22 from Rae-Lee/feature/tweetpage-head
ZHENG-YOU-LU Dec 21, 2022
8fc5b5a
feat : create edit-page
ZHENG-YOU-LU Dec 21, 2022
3d28b84
Merge pull request #26 from Rae-Lee/feature/create-edit
lomo007 Dec 21, 2022
f2e3bb1
feat: assertError, style modify
lomo007 Dec 22, 2022
d1c8988
feat:refactor follow partials
Rae-Lee Dec 22, 2022
3eeed47
refactor:add follow and getTweets services.
Rae-Lee Dec 23, 2022
25804ca
feat: modify router
Rae-Lee Dec 16, 2022
cb93a07
feat:delete topFollowers partial page and add following function
Rae-Lee Dec 16, 2022
3f22bb1
feat:add logout in leftbar partial
Rae-Lee Dec 23, 2022
c88bdbb
feat:add reply page and user-profile partial
Rae-Lee Dec 23, 2022
1c7be4d
img change
lomo007 Dec 23, 2022
9da0b50
Merge pull request #27 from Rae-Lee/feature/refactorfollowandgettweet
ZHENG-YOU-LU Dec 23, 2022
03232dd
feat:add followship page nav
Rae-Lee Dec 17, 2022
fbe7e9f
feat:merge conflict modify
Rae-Lee Dec 17, 2022
a078a11
Merge pull request #28 from Rae-Lee/feature/selfpage
Rae-Lee Dec 23, 2022
db8caee
feat:modify conflict
Rae-Lee Dec 23, 2022
d628ef7
feat:add bcrypt
Rae-Lee Dec 23, 2022
caaecd4
Merge pull request #29 from Rae-Lee/feature/modify
Rae-Lee Dec 23, 2022
caa8e25
merge version
lomo007 Dec 23, 2022
107a489
feat : test
ZHENG-YOU-LU Dec 23, 2022
364eb0b
merge version
lomo007 Dec 23, 2022
3788a44
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 23, 2022
269caf8
merge version
lomo007 Dec 23, 2022
d9a00bc
feat:correct user page
Rae-Lee Dec 24, 2022
cf6928b
feat: delete islike
lomo007 Dec 24, 2022
64bec38
feat : update seeders
ZHENG-YOU-LU Dec 24, 2022
1990fcc
feat : update style.css
ZHENG-YOU-LU Dec 24, 2022
78b569f
feat : update background
ZHENG-YOU-LU Dec 24, 2022
e0f4e4e
feat : update admin-page and admin-controller-getUsers
ZHENG-YOU-LU Dec 24, 2022
60fd272
feat: ui modify and data views
lomo007 Dec 24, 2022
13057a1
feat : update avatar and background
ZHENG-YOU-LU Dec 24, 2022
d2e719f
Merge pull request #30 from Rae-Lee/feature/correct-userpage
ZHENG-YOU-LU Dec 24, 2022
1a01ab3
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 24, 2022
bb59ecf
feat:add like page.
Rae-Lee Dec 24, 2022
379beb5
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2…
Rae-Lee Dec 24, 2022
74735a3
Merge pull request #31 from Rae-Lee/feature/update-seeder
Rae-Lee Dec 24, 2022
d90e40c
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 24, 2022
3b43199
Merge branch 'main' into feature/update-admin-page
ZHENG-YOU-LU Dec 24, 2022
02a07e8
Merge pull request #32 from Rae-Lee/feature/update-admin-page
Rae-Lee Dec 24, 2022
f779a4a
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 24, 2022
db411ca
feat:add user-put in pages
Rae-Lee Dec 24, 2022
bbad4d7
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2…
Rae-Lee Dec 24, 2022
6c2cf10
Merge branch 'main' into feature/view-number
lomo007 Dec 24, 2022
56ed54e
feat:modify user-profile
Rae-Lee Dec 24, 2022
6c6acb0
Merge pull request #34 from Rae-Lee/feature/likepage
ZHENG-YOU-LU Dec 24, 2022
527990f
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 24, 2022
bbed855
Merge branch 'main' into feature/view-number
lomo007 Dec 24, 2022
30e8564
Merge pull request #33 from Rae-Lee/feature/view-number
ZHENG-YOU-LU Dec 24, 2022
02f5aa1
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 24, 2022
0c2292a
feat: modify merge
lomo007 Dec 24, 2022
1dcb8b0
feat: merge conflict
lomo007 Dec 24, 2022
7d1def5
feat:modify homepage
Rae-Lee Dec 24, 2022
4828711
Merge pull request #35 from Rae-Lee/feature/modify-homepage
lomo007 Dec 24, 2022
786fe0f
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
lomo007 Dec 24, 2022
8863f6e
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 24, 2022
15a369d
feat:modify profile page
Rae-Lee Dec 24, 2022
573922c
Merge pull request #36 from Rae-Lee/feature/modify-profile
Rae-Lee Dec 24, 2022
c3393c9
feat: modify profile page
lomo007 Dec 24, 2022
ddb1228
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 24, 2022
ffb9261
feat: ui modify
lomo007 Dec 24, 2022
32b9848
Merge branch 'main' into feature/ui-modify
lomo007 Dec 24, 2022
c69f7c8
Merge pull request #37 from Rae-Lee/feature/ui-modify
ZHENG-YOU-LU Dec 24, 2022
4c92ceb
feat:modify vo.2
Rae-Lee Dec 24, 2022
0ddc24d
feat:modify follower count
Rae-Lee Dec 24, 2022
cf137a7
feat:modify description link
Rae-Lee Dec 24, 2022
794466e
feat
ZHENG-YOU-LU Dec 24, 2022
1d5a31d
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 24, 2022
769d039
feat : update views
ZHENG-YOU-LU Dec 24, 2022
75a4876
Merge pull request #38 from Rae-Lee/feature/update-all-views
lomo007 Dec 24, 2022
ddb7a94
feat: merge version
lomo007 Dec 24, 2022
ec5b66c
feat: merge version
lomo007 Dec 24, 2022
48be4d5
feat : update views
ZHENG-YOU-LU Dec 24, 2022
6098443
Merge pull request #39 from Rae-Lee/feature/update-all-views
lomo007 Dec 24, 2022
909eaea
feat: merge version
lomo007 Dec 24, 2022
08577a8
feat : update views
ZHENG-YOU-LU Dec 24, 2022
b69fbe5
Merge pull request #40 from Rae-Lee/feature/update-view
Rae-Lee Dec 25, 2022
ae5c313
feat:add follow feature
Rae-Lee Dec 18, 2022
29219aa
merge version
lomo007 Dec 25, 2022
7093595
feat : update views
ZHENG-YOU-LU Dec 25, 2022
9ea9684
feat : update
ZHENG-YOU-LU Dec 25, 2022
7497102
Merge pull request #41 from Rae-Lee/feature/update-view
lomo007 Dec 25, 2022
fa1dd3d
feat: merge version
lomo007 Dec 25, 2022
ea010af
feat: rightbar border radius
lomo007 Dec 25, 2022
949fdd2
feat: user-put erase input outline
lomo007 Dec 25, 2022
e1c3148
feat:modify reply modal
Rae-Lee Dec 25, 2022
062e78b
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2…
Rae-Lee Dec 25, 2022
7f1fd82
feat:correct numbers
Rae-Lee Dec 25, 2022
dfe5ab6
feat:add tweets modal
Rae-Lee Dec 25, 2022
f11b38f
Merge pull request #42 from Rae-Lee/feature/update-view
Rae-Lee Dec 25, 2022
1a20b26
feat:merge conflict
Rae-Lee Dec 25, 2022
a166199
Merge pull request #43 from Rae-Lee/feature/modify-modal
Rae-Lee Dec 25, 2022
1682f1d
feat : create README
ZHENG-YOU-LU Dec 25, 2022
a74fffe
feat:update view
Rae-Lee Dec 25, 2022
42c3701
Merge pull request #45 from Rae-Lee/feature/update2
Rae-Lee Dec 25, 2022
d05b9d2
feat:add user avatar
Rae-Lee Dec 25, 2022
12fcfcb
Merge pull request #46 from Rae-Lee/feature/update+
Rae-Lee Dec 25, 2022
c16d5d6
feat:modify icon to fontAwesome
Rae-Lee Dec 25, 2022
7461fe6
Merge pull request #48 from Rae-Lee/feature/modify-icon
ZHENG-YOU-LU Dec 25, 2022
3eb6d20
feat: modify user-put
lomo007 Dec 25, 2022
c17d3fe
feat: user-tweet
lomo007 Dec 25, 2022
bf49262
feat: input hint
lomo007 Dec 25, 2022
f57e978
feat: add required
lomo007 Dec 25, 2022
c68ddc1
feat: modify hint
lomo007 Dec 25, 2022
205b3db
feat: modify hint
lomo007 Dec 25, 2022
c2afc63
Merge pull request #49 from Rae-Lee/feature/point-view
ZHENG-YOU-LU Dec 25, 2022
80847e1
Merge pull request #44 from Rae-Lee/feature/create-README
lomo007 Dec 25, 2022
477e243
Update README.md
lomo007 Dec 25, 2022
681a7f3
Update README.md
lomo007 Dec 25, 2022
c1eb6ad
Merge pull request #50 from Rae-Lee/lomo007-patch-1
ZHENG-YOU-LU Dec 25, 2022
c1808f2
Update README.md
ZHENG-YOU-LU Dec 25, 2022
223f272
Merge pull request #51 from Rae-Lee/ZHENG-YOU-LU-patch-1
lomo007 Dec 25, 2022
6ff1e1d
feat : update
ZHENG-YOU-LU Dec 25, 2022
0f63680
update
ZHENG-YOU-LU Dec 25, 2022
828e16f
Merge branch 'feature/update-some'
ZHENG-YOU-LU Dec 25, 2022
7694c89
Merge pull request #52 from Rae-Lee/feature/update-some
lomo007 Dec 26, 2022
b5f79f0
Merge branch 'main' of https://github.com/Rae-Lee/twitter-fullstack-2020
ZHENG-YOU-LU Dec 26, 2022
38db769
feat: modify config for heroku
ZHENG-YOU-LU Dec 26, 2022
660201a
add follow button on profile
Rae-Lee Dec 26, 2022
3d7e95d
Merge pull request #56 from Rae-Lee/feature/all
Rae-Lee Dec 26, 2022
1541e64
Merge pull request #55 from Rae-Lee/feature/heroku
Rae-Lee Dec 26, 2022
6c1772b
feat:update profile
Rae-Lee Dec 26, 2022
6c1eec5
Merge pull request #57 from Rae-Lee/feature/profile
Rae-Lee Dec 26, 2022
9c63d41
feat:modify like page
Rae-Lee Dec 26, 2022
1de7c35
Merge pull request #58 from Rae-Lee/feature/like
Rae-Lee Dec 26, 2022
26f9dfa
feat:correct getLikes controller
Rae-Lee Dec 26, 2022
2bde527
Merge pull request #59 from Rae-Lee/feature/correct
Rae-Lee Dec 26, 2022
9832423
feat:modify reply modal avatar
Rae-Lee Dec 26, 2022
bcd200f
Merge pull request #60 from Rae-Lee/feature/reply-avatar
Rae-Lee Dec 26, 2022
02de967
feat:update reply avatar
Rae-Lee Dec 26, 2022
6b7598d
feat:delete reply-modal partial
Rae-Lee Dec 26, 2022
6ff25a4
Merge pull request #61 from Rae-Lee/feature/avatar2
Rae-Lee Dec 26, 2022
07ff334
feat: modify admin tweets page
Rae-Lee Dec 26, 2022
5a2a237
Merge pull request #62 from Rae-Lee/feature/adminpage
Rae-Lee Dec 26, 2022
11e9f24
correct admin-controller
Rae-Lee Dec 26, 2022
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IMGUR_CLIENT_ID=
PORT =
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/

temp

upload
1 change: 1 addition & 0 deletions Profile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: NODE_ENV=production node app.js
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Simple Twitter

使用 Node.js & Express 打造的類Twitter網站。

## 功能列表

- 註冊/登入/登出
- 使用者一定要登入才能使用網站
- 使用者註冊內容錯誤 或 與他人資料重複 及 登入失敗時,會看到對應的系統訊息
- 使用者
- 使用者能在首頁瀏覽所有的推文
- 使用者能新增推文
- 使用者點擊貼文方塊時,能查看該則貼文的詳情與回覆串
- 點擊貼文中使用者頭像時,能瀏覽該使用者的個人資料及推文
- 使用者能回覆別人的推文
- 使用者可以追蹤/取消追蹤其他使用者
- 使用者能對推文按 喜歡/不喜歡
- 使用者能編輯自己的名稱、介紹、大頭照和個人背景
- 使用者能在首頁的側邊欄,看見跟隨者數量排列前 10 的使用者推薦名單
- 使用者能在個人資料內,看見自己發布的貼文、回覆的文章、喜歡的貼文、追隨者及跟隨者
- 後台管理
- 管理者可以瀏覽全站所有的使用者清單
- 管理者可以瀏覽全站的推文清單
- 管理者可以在推文清單上直接刪除任何人的推文

## 畫面預覽

![login](./public/images/tweets-login.jpg)

![index](./public/images/tweets-index.jpg)

![admin](./public/images/admin.jpg)

## 安裝流程

1.開啟終端機將專案存至本機,在終端機輸入 :
```
git clone https://github.com/Rae-Lee/twitter-fullstack-2020.git
```
2.進入專案資料夾,在終端機輸入:
```
cd twitter-fullstack-2020
```
3.安裝`npm`套件,在終端機輸入:
```
npm install
```
4.環境變數設定 請參考.env.example檔案設定環境變數,並將檔名改為.env
```
IMGUR_CLIENT_ID=
PORT=3000
```
5.建立資料庫
開啟 MySQL workbench,再連線至本地資料庫,輸入以下建立資料庫
```
drop database if exists ac_twitter_workspace;
create database ac_twitter_workspace;
use ac_twitter_workspace;
```
6.建立 mySQL Table,在終端機輸入:
```
npx sequelize db:migrate
```
7.建立種子資料,在終端機輸入:
```
npx sequelize db:seed:all
```
8.執行專案,在終端機輸入:
```
npm run dev
```
9.使用
終端機出現下列訊息" "Example app listening on port 3000!"
可開啟瀏覽器輸入 http://localhost:3000 使用

10.預設使用者 Seed User
加入種子資料後,可使用下列預設帳號/密碼進行登入
| 帳號 | 密碼 |
| :------------- | :------------- |
| root | 12345678 |
| user1 | 12345678 |
| user2 | 12345678 |
| user3 | 12345678 |
| user4 | 12345678 |
| user5 | 12345678 |

# 共同開發人員

- [lomo007](https://github.com/lomo007)
- [Rae-Lee](https://github.com/Rae-Lee)
- [ZHENG-YOU-LU](https://github.com/ZHENG-YOU-LU)
18 changes: 13 additions & 5 deletions _helpers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
function ensureAuthenticated(req) {
return req.isAuthenticated();
function ensureAuthenticated (req) {
return req.isAuthenticated()
}

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

const dayjs = require('dayjs')
const relativetime = require('dayjs/plugin/relativeTime')
dayjs.extend(relativetime)

module.exports = {
ensureAuthenticated,
getUser,
};
relativetimeFromNNow: a => dayjs(a).fromNow(),
ifCond: function (a, b, options) {
return a === b ? options.fn(this) : options.inverse(this)
}
}
84 changes: 84 additions & 0 deletions _services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const { Op } = require('sequelize')
const helpers = require('./_helpers')
const db = require('./models')
const User = db.User
const Tweet = db.Tweet
const Like = db.Like
const Reply = db.Reply
const Followship = db.Followship
module.exports = {
// 推薦追蹤用戶
getTopUsers: async (req) => {
const viewUser = helpers.getUser(req)
const followingList = viewUser && viewUser.Followings.map(following => following.id)
const allUsers = await User.findAll({
where: {
role: 'user',
id: { [Op.not]: Number(helpers.getUser(req).id) }
},
include: [{ model: User, as: 'Followers' }],
nest: true
})
const topFollowings = allUsers
.sort((a, b) => {
b.Followers.length - a.Followers.length
})
.slice(0, 10)
.map(topFollowing => {
return {
...topFollowing.toJSON(),
isFollowed: followingList.includes(topFollowing.id)
}
})
return topFollowings
},
// 貼文抓取
getTweets: async (req) => {
const viewUser = helpers.getUser(req)
const UserId = req.params.id || ''
const tweets = await Tweet.findAll({
where: UserId ? { UserId } : {},
order: [['createdAt', 'DESC']],
include: [User, Like, Reply],
nest: true
}) || []
const data = tweets.map(t => ({
...t.toJSON(),
User: t.User.dataValues,
description: t.description.substring(0, 140),
isLiked: t.Likes.some(f => f.UserId === viewUser.id)
}))
return data
},
// 單一貼文回覆抓取
getReplies: async (req) => {
const TweetId = req.params.id || ''
const replies = await Reply.findAll({
where: { TweetId },
order: [['createdAt', 'DESC']],
include: [User],
nest: true,
raw: true
}) || []
return replies
},
// 抓取個人檔案用戶
getUser: async (req) => {
const userId = req.params.id
const viewUser = helpers.getUser(req)
const followingList = viewUser && viewUser.Followings.map(following => following.id)
const findUser = await User.findByPk(userId, {
include: [
Tweet,
{ model: User, as: 'Followings', order: [[Followship, 'createdAt', 'DESC']]},
{ model: User, as: 'Followers', order: [[Followship, 'createdAt', 'DESC']] }
],
nest: true
})
const user = {
...findUser.toJSON(),
isFollowed: followingList.includes(findUser.id)
}
return user
}
}
39 changes: 34 additions & 5 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 helpers = require('./_helpers')
const flash = require('connect-flash')
const session = require('express-session')
const routes = require('./routes')
const passport = require('./config/passport')
const methodOverride = require('method-override')

const app = express()
const port = 3000
const port = process.env.PORT || 3000
const SESSION_SECRET = 'secret'

// use helpers.getUser(req) to replace req.user
// use helpers.ensureAuthenticated(req) to replace req.isAuthenticated()
app.engine('hbs', handlebars({ extname: '.hbs', helpers }))
app.set('view engine', 'hbs')
app.use(express.static('public'))

app.use(express.urlencoded({ extended: true }))
app.use(methodOverride('_method'))
app.use(session({ secret: SESSION_SECRET, resave: false, saveUninitialized: false }))
app.use(passport.initialize())
app.use(passport.session())
app.use('/upload', express.static(path.join(__dirname, 'upload')))
app.use(flash())
app.use((req, res, next) => {
res.locals.success_messages = req.flash('success_messages')
res.locals.error_messages = req.flash('error_messages')
res.locals.viewUser = helpers.getUser(req)
next()
})

app.use(express.static('public'))

app.use(routes)

app.get('/', (req, res) => res.send('Hello World!'))
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": "CLEARDB_DATABASE_URL"
},
"travis": {
"username": "travis",
Expand Down
41 changes: 41 additions & 0 deletions config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const passport = require('passport')
const LocalStrategy = require('passport-local')
const bcrypt = require('bcryptjs')
const db = require('../models')
const User = db.User
const Tweet = db.Tweet
const Like = db.Like

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', '帳號不存在'))
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) => {
User.findByPk(id, {
include: [
{ model: User, as: 'Followers' },
{ model: User, as: 'Followings' }
], nest: true
}).then(user => {
user = user.toJSON()
console.log(user)
return cb(null, user)
})
})
module.exports = passport
Loading