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

全端組:莊日嶸、Mark Law、Quinn、Merry #332

Open
wants to merge 184 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
9b8efab
feat: add tweets page
MerryHao Mar 19, 2023
0e0b5d9
feat: adjust tweets width
MerryHao Mar 20, 2023
5ba42f1
feat: add icons
MerryHao Mar 20, 2023
0e428f7
Merge pull request #1 from robert1074004/view_all_tweets_page
robert1074004 Mar 21, 2023
caa7d5a
feat: add login page
robert1074004 Mar 21, 2023
4584343
feat: fix reply and like icon style
MerryHao Mar 21, 2023
75ceb06
feat: adjust card and modal ui
MerryHao Mar 21, 2023
d031864
feat: modify login page and add cross-env
robert1074004 Mar 22, 2023
e67b1a3
Merge pull request #2 from robert1074004/robert
HKMark Mar 22, 2023
3b06396
feat: merge conflict
MerryHao Mar 22, 2023
2d8040d
feat: add modal alert msg, add user name in reply modal, adjust ui
MerryHao Mar 22, 2023
3737860
feat: change modal size
MerryHao Mar 22, 2023
73d0f0b
admin/user
KeYunTinG Mar 22, 2023
e9cad67
Merge pull request #4 from robert1074004/merry_tweets_page_modal
HKMark Mar 22, 2023
c81f44d
fix /admin/user
KeYunTinG Mar 22, 2023
c71c2b8
feat: add replies page
MerryHao Mar 23, 2023
4ef48c3
feat: leftbar add position fix
MerryHao Mar 23, 2023
116a1a7
feat: rightbar add position fix
MerryHao Mar 23, 2023
5e6ca57
fix migrations
KeYunTinG Mar 23, 2023
21f16dd
feat: change hr line color in tweets.hbs
MerryHao Mar 23, 2023
3087c1b
feat: add user profile page
HKMark Mar 23, 2023
ba31dcf
feat: fix replies title's height
MerryHao Mar 23, 2023
5cdf85b
Merge pull request #7 from robert1074004/mark/user-profile
MerryHao Mar 23, 2023
6d81f47
feat: merge conflict
MerryHao Mar 23, 2023
bcc7d2c
Merge pull request #8 from robert1074004/merry_replies_page
KeYunTinG Mar 23, 2023
26720e8
model test
KeYunTinG Mar 23, 2023
f659369
model test
KeYunTinG Mar 23, 2023
3feac0b
Merge branch 'master' into Quinn
KeYunTinG Mar 23, 2023
be8182d
Merge pull request #9 from robert1074004/Quinn
KeYunTinG Mar 24, 2023
6ce2b09
feat: modify users.hbs
HKMark Mar 24, 2023
4cbc128
Merge pull request #10 from robert1074004/mark/user-profile
MerryHao Mar 24, 2023
bb6996f
feat: add regiser_page and modify login_page
robert1074004 Mar 24, 2023
c7bf567
feat: use Camel Case
robert1074004 Mar 24, 2023
c3c6a2c
Merge pull request #11 from robert1074004/robert_register_page
HKMark Mar 24, 2023
0ed80e6
feat: fix conflict class name and add reply modal
MerryHao Mar 24, 2023
6ca3390
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 24, 2023
fe5dac7
Merge pull request #12 from robert1074004/merry_replies_page
robert1074004 Mar 24, 2023
2760376
feat: add user profile edit modal
HKMark Mar 24, 2023
51fd867
Merge pull request #13 from robert1074004/mark/profile-edit
MerryHao Mar 24, 2023
cb1dcb2
feat: add addEventlistener for content length limitation alert msg in…
MerryHao Mar 25, 2023
f8d43cb
Merge pull request #15 from robert1074004/view_all_tweets_page
HKMark Mar 25, 2023
672564d
feat: modify users page and add Notifyship model
robert1074004 Mar 25, 2023
91457c6
Merge pull request #16 from robert1074004/robert_usersPage
MerryHao Mar 25, 2023
3b4eb7c
feat: add add addEventlistener in replies page for content length lim…
MerryHao Mar 25, 2023
d19ffc8
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 25, 2023
5e6b6fd
Merge pull request #17 from robert1074004/merry_replies_page
robert1074004 Mar 25, 2023
10d1369
feat: add setting page
robert1074004 Mar 25, 2023
e541bd8
Merge pull request #18 from robert1074004/robert_settingPage
HKMark Mar 25, 2023
fededd8
add admin/tweets
KeYunTinG Mar 25, 2023
7cb6197
Merge pull request #19 from robert1074004/Quinn_admin_tweets
HKMark Mar 25, 2023
8648e7f
feat: add followers.hbs and followings.hbs; modify CSS, profile.hbs a…
HKMark Mar 26, 2023
dddbf12
Merge pull request #20 from robert1074004/mark/profile-follower-and-f…
MerryHao Mar 26, 2023
6626893
feat: add postTweet feature in tweets.hbs page
MerryHao Mar 26, 2023
f8d8252
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 26, 2023
4ff73a5
add passport admin/signin
KeYunTinG Mar 26, 2023
b3645fc
seeder
KeYunTinG Mar 26, 2023
e5d49c5
Update index.js
KeYunTinG Mar 27, 2023
3ac7ba8
Merge pull request #22 from robert1074004/Quinn_admin_signin
KeYunTinG Mar 27, 2023
937fa7e
feat: add postTweet and postReply
MerryHao Mar 27, 2023
348614b
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 27, 2023
5144b09
feat: delete replyController
MerryHao Mar 27, 2023
1a16853
feat: add replies, like, and unlike router
MerryHao Mar 27, 2023
0acf10a
Merge pull request #23 from robert1074004/view_all_tweets_page
HKMark Mar 27, 2023
4db05fc
feat: fix admin route
MerryHao Mar 27, 2023
fc83538
feat: delete admin route
MerryHao Mar 27, 2023
750e10f
Update index.js
KeYunTinG Mar 27, 2023
7362542
Merge pull request #24 from robert1074004/view_all_tweets_page
MerryHao Mar 27, 2023
c0a53af
feat: merge conflict
MerryHao Mar 27, 2023
0006d26
feat: put variable of user in reply modal
MerryHao Mar 27, 2023
c20b1f6
feat: add like and unlike function
MerryHao Mar 27, 2023
453ce87
feat: fix router
MerryHao Mar 27, 2023
40da9c8
feat: add signup function
robert1074004 Mar 27, 2023
6d537bf
Update app.js
KeYunTinG Mar 27, 2023
aa4e777
Update message.hbs
KeYunTinG Mar 27, 2023
f642dfb
Merge pull request #25 from robert1074004/robert_signup_function
KeYunTinG Mar 27, 2023
868094d
route fix
KeYunTinG Mar 27, 2023
616435d
Merge pull request #26 from robert1074004/Quinn_route_fix
HKMark Mar 27, 2023
5f5fa73
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 28, 2023
65430a6
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 28, 2023
7bb5dc5
Update index.js
KeYunTinG Mar 28, 2023
a8e3b9f
Merge pull request #27 from robert1074004/view_all_tweets_page
KeYunTinG Mar 28, 2023
6453414
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 28, 2023
a81fa57
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 28, 2023
91e0c90
feat: add signin function
robert1074004 Mar 28, 2023
26dc805
Merge pull request #28 from robert1074004/robert_signin_function
HKMark Mar 28, 2023
12c163f
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 28, 2023
8d30093
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 28, 2023
c77b93d
feat: rename column Tweet_id to tweet_id
MerryHao Mar 28, 2023
8ba0e95
Update index.js
KeYunTinG Mar 28, 2023
e534c58
Merge pull request #29 from robert1074004/merry_replies_page
KeYunTinG Mar 28, 2023
fad8883
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 28, 2023
0e8340d
admin-login-test
KeYunTinG Mar 28, 2023
24734c8
feat: add replies seeder
MerryHao Mar 28, 2023
a5ae334
Merge pull request #30 from robert1074004/Quinn_admin_logintest
robert1074004 Mar 28, 2023
14254e9
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 28, 2023
fcc1804
feat: merge conflict
MerryHao Mar 28, 2023
6a4955b
feat: fix route
MerryHao Mar 28, 2023
b85eb1d
feat: AC icon add mt-2
MerryHao Mar 29, 2023
d327150
feat: add likes.hbs, replies.hbs ; modify profile.hbs, user-tabs.hb, …
HKMark Mar 29, 2023
527f4cb
feat: fix postReply, modal link move to reply icon
MerryHao Mar 29, 2023
2e7a8c5
Merge pull request #31 from robert1074004/mark/user-profile
MerryHao Mar 29, 2023
e9b6085
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 29, 2023
36450a3
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 29, 2023
f6007d1
Merge pull request #32 from robert1074004/merry_replies_page
HKMark Mar 29, 2023
241b2f2
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 29, 2023
4748c0e
feat: fix getTweets and postTweet
MerryHao Mar 29, 2023
7573566
feat: add addLike and removeLike
MerryHao Mar 29, 2023
1e30cac
finish admin/request
KeYunTinG Mar 29, 2023
b2e03a0
Merge pull request #33 from robert1074004/Quinn_admin_request
robert1074004 Mar 29, 2023
c3bd652
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 29, 2023
a358346
feat: add flash message after tweet over 140 words
MerryHao Mar 29, 2023
db9f379
feat: fix variable at reply modal
MerryHao Mar 30, 2023
b57573c
add follow function and modify route '/'
robert1074004 Mar 30, 2023
9a11c79
feat: modify post '/signin' route
robert1074004 Mar 30, 2023
db2c0a8
Merge pull request #34 from robert1074004/robert_follow_function
KeYunTinG Mar 30, 2023
8262abc
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 30, 2023
b5afd0e
Merge pull request #35 from robert1074004/merry_tweets_page
robert1074004 Mar 30, 2023
c7376af
feat: init heroku
robert1074004 Mar 30, 2023
07f6518
modify user's account length
robert1074004 Mar 30, 2023
5cfd822
feat: fix the reply model didn't display account
MerryHao Mar 30, 2023
78de402
feat: adjust alert msg and add like judgement in replies page
MerryHao Mar 30, 2023
8f27d21
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 30, 2023
46fef87
Merge pull request #36 from robert1074004/merry_tweets_page
HKMark Mar 30, 2023
9491b28
feat: modify user's account lenght
robert1074004 Mar 30, 2023
6d9d472
feat: modify user's account lenght
robert1074004 Mar 30, 2023
0ba1430
feat: modify routes/index.js
robert1074004 Mar 30, 2023
0c39949
feat: modify user's email length
robert1074004 Mar 30, 2023
3384542
feat: add avatar seeder
MerryHao Mar 30, 2023
479c5aa
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 30, 2023
2c9a98f
feat: add tweet modal in replies page
MerryHao Mar 30, 2023
817612c
feat: add user link on name
MerryHao Mar 30, 2023
9c60f4d
feat: fix reply modal ui and fix user link of each tweet at tweets page
MerryHao Mar 30, 2023
dd9ff13
Merge pull request #37 from robert1074004/merry_tweets_page
robert1074004 Mar 30, 2023
b565ed5
fix user png
KeYunTinG Mar 30, 2023
71a4673
Merge pull request #38 from robert1074004/Quinn_admin_fix_user_png
robert1074004 Mar 30, 2023
9d0d91b
modify profile.hbs, replies.hbs and user-controller.js
HKMark Mar 30, 2023
a8d3b00
Update user-controller.js
HKMark Mar 30, 2023
c068171
Merge pull request #39 from robert1074004/mark/user-profile
robert1074004 Mar 31, 2023
eaf5fff
feat: add setting function and modify signout flash message
robert1074004 Mar 31, 2023
f64b66c
Merge pull request #40 from robert1074004/robert_setting_function
HKMark Mar 31, 2023
ae08fd0
modify replies.hbs; bug fixing
HKMark Mar 31, 2023
23caa8d
Merge pull request #41 from robert1074004/mark/user-profile
robert1074004 Mar 31, 2023
7814f1f
feat: add href on avatar
MerryHao Mar 31, 2023
a9cbafe
feat: add readme file
MerryHao Mar 31, 2023
f461050
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Mar 31, 2023
5331932
feat: remove unused part
MerryHao Mar 31, 2023
7c8ef0f
feat: remove unused model in tweet-controller, user-avatar.hbs, and f…
MerryHao Mar 31, 2023
373cf83
Merge pull request #42 from robert1074004/merry_tweets_page
KeYunTinG Mar 31, 2023
4b2e6a0
feat: fix readme content
MerryHao Mar 31, 2023
21e5228
modify likes.hbs, profile.hbs, replies.hbs and user-controller
HKMark Mar 31, 2023
41f1689
Merge pull request #43 from robert1074004/mark/user-profile
KeYunTinG Mar 31, 2023
3165f1b
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Apr 1, 2023
f72e8ea
feat: add userFollowPage
robert1074004 Apr 1, 2023
5aeb7ed
Merge pull request #44 from robert1074004/robert_userFollowPage
HKMark Apr 1, 2023
41aa0f0
followUser
KeYunTinG Apr 1, 2023
9e8d253
Merge pull request #45 from robert1074004/Quinn_followUser
HKMark Apr 1, 2023
014c81c
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Apr 1, 2023
1418961
Merge pull request #46 from robert1074004/merry_tweets_page
KeYunTinG Apr 1, 2023
59e00ea
feat: adjust logout icon upper
MerryHao Apr 1, 2023
0fc0b2c
feat:typo
MerryHao Apr 1, 2023
9b0b255
feat: add cover.png
MerryHao Apr 1, 2023
9612683
feat: add cover.png in README
MerryHao Apr 1, 2023
0efa522
Merge pull request #49 from robert1074004/merry_tweets_page
robert1074004 Apr 2, 2023
ed2d5f0
feat: modify userFollowPage
robert1074004 Apr 2, 2023
4beec95
Merge pull request #50 from robert1074004/robert_modify_userFollowPage
MerryHao Apr 2, 2023
55d3605
fix followUser
KeYunTinG Apr 2, 2023
937116f
Merge pull request #51 from robert1074004/Quinn_fix_followUser
robert1074004 Apr 2, 2023
cda50e6
Feat: add edit profile function; modify css, models and migrations; u…
HKMark Apr 2, 2023
d6e164d
Merge pull request #52 from robert1074004/mark/user-profile-and-models
robert1074004 Apr 2, 2023
7b37379
feat: reinstall npm
MerryHao Apr 2, 2023
4589186
feat: add cover.png
MerryHao Apr 2, 2023
7b42bb3
feat: modify flash message and delete JWT
robert1074004 Apr 2, 2023
3a10253
Merge pull request #53 from robert1074004/robert_modifyDetail
HKMark Apr 2, 2023
01068d3
Bug fix: user can't tweet on profile, follower, following pages.
HKMark Apr 2, 2023
7c7d9d6
Merge pull request #54 from robert1074004/mark/user-profile-and-models
KeYunTinG Apr 2, 2023
b3d7289
Merge branch 'master' of https://github.com/robert1074004/twitter-ful…
MerryHao Apr 2, 2023
023c817
Merge pull request #55 from robert1074004/merry_tweets_page
HKMark Apr 2, 2023
a5a0e52
feat: update suite
MerryHao Apr 2, 2023
f661d98
Merge pull request #56 from robert1074004/merry_tweets_page
HKMark Apr 2, 2023
5865562
Refined login condition checks: Differentiate between regular users a…
HKMark Apr 2, 2023
2d6c553
models update
HKMark Apr 2, 2023
ea0b1dd
package.json update
HKMark Apr 2, 2023
59d169c
tweet-controller update
HKMark Apr 2, 2023
2323460
app.js update
HKMark Apr 2, 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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CLEARDB_DATABASE_URL = SKIP
IMGUR_CLIENT_ID = SKIP
SESSION_SECRET = SKIP
PORT = SKIP
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 Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: NODE_ENV=production node app.js
128 changes: 128 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Simple Twitter - full stack
使用基於node.js的express.js應用程式框架,全端開發simple twitter專案
![cover1](cover1.png)
![cover2](cover2.png)

## 專案功能
- 所有頁面(除了登入和註冊頁)
- 使用者一定要登入才能使用網站。
- 使用者能在首頁的側邊欄,看見跟隨者 (followers) 數量排列前 10 的推薦跟隨名單
- 何登入使用者都可以瀏覽特定使用者的以下資料
- 推文與回覆
- 跟隨中
- 跟隨者
- 喜歡的內容
- 登入
- 當使用者尚未註冊便試圖登入時,會有錯誤提示。
- 當使用者登入成功會進入首頁,會有登入成功提示。
- 使用者點擊註冊會到註冊頁。
- 使用者點擊後臺登入會到後臺登入頁。
- 註冊
- 使用者可以設定帳號、名稱、email 和密碼
- 當使用者輸入的帳號、email 與他人重複,若有重複會跳出錯誤提示
- 當使用者註冊成功導到首頁,會有註冊成功提示。
- 使用者點擊取消會到首頁。
- 帳戶設定頁
- 使用者可以編輯帳號、名稱、email 和密碼
- 當使用者輸入的帳號、email 與他人重複,若有重複會跳出錯誤提示
- 使用者能編輯自己的名稱、自我介紹、個人頭像與封面
- 推文及回覆頁
- 使用者能在首頁瀏覽所有的推文 (tweet)
- 使用者點擊貼文方塊時,能查看貼文與回覆串
- 使用者能回覆別人的推文
- 使用者無法回覆他人回覆,也無法針對他人的按 Like/Unlike
- 點擊貼文中使用者頭像時,能瀏覽該使用者的個人資料及推文
- 使用者能新增140內的推文
- 使用者可以追蹤/取消追蹤其他使用者 (不能追蹤自己)
- 使用者能對別人的推文按 Like/Unlike
- 個人資料頁
- 使用者能編輯自己的名稱、介紹、大頭照和個人頁橫幅背景
- 後台
- 訪客可以自行註冊成為 user,但 admin 帳號無法自行註冊
- 管理者可從專門的後台登入頁面進入網站後台
- 管理者可以瀏覽全站的 Tweet 清單
- 管理者可以瀏覽站內所有的使用者清單
## 安裝流程

1.將專案clone至本地端並開啟專案
2. .安裝`npm`套件,在終端機輸入:
```
npm install
```
```
npm i
```
3.環境變數設定 請參考.env.example檔案設定環境變數,並將檔名改為.env
```
IMGUR_CLIENT_ID=
PORT=3000
```
4.更改連線至資料庫的username和password:
在config/config.json下,將development的username和password改為自己本地端資料庫的

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 |

# 開發工具
- bcrypt-nodejs: 0.0.3
- bcryptjs: 2.4.3
- body-parser: 1.18.3
- chai: 4.2.0
- connect-flash: 0.1.1
- cross-env: 7.0.3
- dotenv: 10.0.0
- express: 4.16.4
- express-handlebars: 3.0.0
- express-session: 1.15.6
- Bootstrap 5.0.2
- faker: 4.1.0
- imgur: 1.0.2
- jsonwebtoken: 8.5.1
- method-override: 3.0.0
- mocha: 6.0.2
- mysql2: 1.6.4
- passport: 0.4.0
- passport-jwt: 4.0.0
- passport-local: 1.0.0
- sequelize: 6.18.0
- sequelize-cli: 5.5.0
- sinon: 10.0.0
- sinon-chai: 3.3.0

# 共同開發人員

- [Quinn](https://github.com/KeYunTinG)
- [Mark Law](https://github.com/HKMark)
- [莊日嶸](https://github.com/robert1074004)
- [Merry](https://github.com/MerryHao)
31 changes: 28 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
const express = require('express')
const helpers = require('./_helpers');

const session = require('express-session');
const passport = require('./config/passport')
const handlebars = require('express-handlebars')
const routes = require('./routes')
const methodOverride = require('method-override');
const flash = require('connect-flash');
const app = express()
const port = 3000
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const port = process.env.PORT || 3000

// use helpers.getUser(req) to replace req.user
// use helpers.ensureAuthenticated(req) to replace req.isAuthenticated()
app.engine('hbs', handlebars({ extname: '.hbs', helpers: require('./config/handlebars-helper') }))
app.set('view engine', 'hbs')
app.use(methodOverride('_method'));
app.use(express.static('public'))
app.use(session({ secret: 'secret', resave: false, saveUninitialized: true }))
app.use(express.urlencoded({ extended: true }))
app.use(passport.initialize())
app.use(passport.session())
app.use(flash())
app.use((req, res, next) => {
res.locals.user = helpers.getUser(req);
res.locals.isAuthenticated = helpers.ensureAuthenticated(req);
res.locals.successMessage = req.flash('successMessage');
res.locals.errorMessage = req.flash('errorMessage');
next();
});
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
43 changes: 43 additions & 0 deletions components/Util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const cover = [
'https://i.imgur.com/wGkpw1M.jpg',
'https://i.imgur.com/xZ6qKDb.jpg',
'https://i.imgur.com/c4lrfFo.jpg',
'https://i.imgur.com/4Saup98.jpg',
'https://i.imgur.com/yKt1j8t.jpg',
'https://i.imgur.com/Ky64Alo.jpg',
];

const avater = [
'https://i.imgur.com/lX1p1p1.jpg',
'https://imgur.com/PS4yRak.jpg',
'https://i.imgur.com/uRNcL5L.jpg',
'https://i.imgur.com/EkrFu0B.jpg',
'https://i.imgur.com/vDlIZHV.jpg',
'https://imgur.dcard.tw/FTTspcJ.jpg',
];

module.exports = {
randomCover: () => {
let length = cover.length;
let index = Math.floor(Math.random() * length);

return cover[index];
},
randomAvater: () => {
let length = avater.length;
let index = Math.floor(Math.random() * length);

return avater[index];
},
randomNums: (count, scope) => {
let arr = [];
while (arr.length < count) {
let num = parseInt(Math.random() * scope);
if (arr.indexOf(num) == -1) {
arr.push(num);
}
}

return arr;
},
};
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
30 changes: 30 additions & 0 deletions config/handlebars-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const moment = require('moment');

module.exports = {
Equal: (a, b, options) => {
if (a === b) {
return options.fn(this);
}
return options.inverse(this);
},
moment: (a) => {
return moment(a).fromNow(true);
},
nowTime: (a) => {
return moment().format("hA")
},
subText: (content, num) => {
let count = Number(num) ? Number(num) : 50;

if (!content) return '';
if (content.length === 0) return '';
if (content.length < count) {
return content;
}

return content.substring(0, count) + '...';
},
ifCond: function (a, b, options) {
return a === b ? options.fn(this) : options.inverse(this)
}
};
81 changes: 81 additions & 0 deletions config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const passport = require('passport');
const LocalStrategy = require('passport-local');
const bcrypt = require('bcryptjs');
const db = require('../models');
const User = db.User;
const Like = db.Like;
const Tweet = db.Tweet;
const Reply = db.Reply;
const Private = db.Private;

passport.use(
new LocalStrategy(
{ usernameField: 'account', passReqToCallback: true },
(req, account, password, cb) => {
User.findOne({ where: { account } }).then((user) => {
// console.log('@@@@', user)
req.flash('userInput', req.body);
if (!user) {
return cb(
null,
false,
req.flash('errorMessage', '帳號/密碼輸入錯誤!'),
);
}
if (req.url === "/admin/signin" && user.dataValues.role !== 'admin') {
return cb(
null,
false,
req.flash('errorMessage', '帳號/密碼輸入錯誤!'),
);
}
if (req.url === "/signin" && user.dataValues.role === 'admin') {
return cb(
null,
false,
req.flash('errorMessage', '帳號/密碼輸入錯誤!'),
);
}
if (!bcrypt.compareSync(password, user.password)) {
return cb(
null,
false,
req.flash('errorMessage', '帳號/密碼輸入錯誤!'),
);
}
return cb(null, user);
});
},
),
);


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

passport.deserializeUser((id, cb) => {
User.findByPk(id, {
include: [
Like,
{ model: Tweet, include: Reply },
{ model: User, as: 'Followers' },
{ model: User, as: 'Followings' },
],
}).then((user) => {
if (!user) return
Private.findAll({
where: {
ReceiveId: user.dataValues.id,
isLooked: false,
}
})
.then(data => {
user.dataValues.noSeeMsg = data.length
return cb(null, user.toJSON());
})
});
});


module.exports = passport;
Loading