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

Week17 #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Week17 #18

wants to merge 2 commits into from

Conversation

boll84011336
Copy link
Collaborator

十七週作業完成
餐廳官網:
https://young-sierra-55856.herokuapp.com/
管理者帳號密碼:admin

BLOG:
https://murmuring-river-65134.herokuapp.com/

Comment on lines +6 to +16
homePage: async(req, res) => {
const articles = await Articles.findAll({
order: [['id', 'DESC']],
include: User
})
res.render('index', {
articles
})
},
add: (req, res) => {
const {userId} = req.session //這從登入帳號存在session的帳號 ,用解構語法拿出來的
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

縮排不一致
我在猜可能是 tab 和 space 的差別,
你可能需要調整一下你的編輯器或者 IDE。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cwc329 想請教助教,如果這時候用VSCODE自動排版快捷鍵,SHIFT ALT F 讓它自動排是好的縮排嗎?
因為排版問題其實有先調過了,但每次在寫新的一頁的時候又會跑掉,我都是按tab去寫,但有時候我的編輯器會跳2格為單位,有時候是四格,沒特別注意就會沒發現到又跳掉了。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我現在用的 IDE 不是 vscode,所以不太知道要怎麼用。
不過想要一致的話,JS 可以考慮用 eslint。
這樣只要規則一樣然後讓 eslint 自己 format 就可以保證一致了。
而且主流的編輯器以及 IDE 幾乎都有 eslint 的 plugin 可以用。

title,
content,
UserId: userId
}).then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以改用 async/await

},

articlePage: async(req, res) => {
// id 本來就是 URL 的一部分,所以不用特地檢查
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

任何使用者傳進來的資訊都要檢查。


Articles.findOne({
where: {
id: req.params.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面已經解構了這邊可以直接用變數。



app.use(session({
secret: 'keyboard cat',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secret 不要用 hard code,
使用環境變數。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cwc329 抱歉助教,這邊的寫法是直接抄網路的方式,所以有點看不懂您提醒的意思,想請問不要用hard code是什麼意思。

Copy link
Contributor

@cwc329 cwc329 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://lidemy.com/courses/390625/lectures/24510405
環境變數可以參考這個影片。

簡單說你只要看到 secret, key 等關鍵字,所使用的值通常都是敏感資訊,
這種時候如果直接寫在 code 上傳到公開的 repository 是資安大漏洞,
所以這些變數就會用環境變數的方式引入,
使用起來會像這樣。

app.use(session({
  secret: process.env.SECRET
});

},

//抽獎新增
handleAddAdmin: async(req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名稱有點怪,
這邊看起來是增加獎項但是韓式名稱是增加管理員。

@@ -0,0 +1,24 @@
./node_modules/.bin/sequelize model:generate --name User --attributes username:string,password:string,nickname:string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這些內容可以寫在 README.md 或者 docs 裡面,
讓之後的開發者可以知道這個專案的一些資訊。
不用隨便用 a.txt 這樣沒有識別性的檔案名稱。

}
req.session.username = user.username
req.session.userId = user.id
console.log("USER 是誰",user)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log("USER 是誰",user)




function checkIsAdmin(req, res, next) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這個 function 不要放在 index.js 裡面宣告,
讀起來比較乾淨。

Comment on lines +65 to +68
app.post('/backstage', prizeController.handleAddAdmin) //後台新增
app.get('/update-lottery/:id', prizeController.updatePage) //後台更新
app.post('/update-lottery/:id', prizeController.handleUpdate)
app.get('/delete-lottery/:id', prizeController.delete)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要做權限管理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants