Skip to content

Commit 4d98905

Browse files
committed
fix:auth bug
1 parent a26f5ca commit 4d98905

12 files changed

Lines changed: 38 additions & 19 deletions

File tree

build/server

3.73 KB
Binary file not shown.

build/static/asset-manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"files": {
33
"main.css": "/static/css/main.d802e3cd.css",
4-
"main.js": "/static/js/main.4a33c7d9.js",
4+
"main.js": "/static/js/main.20b2f18c.js",
55
"index.html": "/index.html",
66
"main.d802e3cd.css.map": "/static/css/main.d802e3cd.css.map",
7-
"main.4a33c7d9.js.map": "/static/js/main.4a33c7d9.js.map"
7+
"main.20b2f18c.js.map": "/static/js/main.20b2f18c.js.map"
88
},
99
"entrypoints": [
1010
"static/css/main.d802e3cd.css",
11-
"static/js/main.4a33c7d9.js"
11+
"static/js/main.20b2f18c.js"
1212
]
1313
}

build/static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Academic Support System"/><title>Academic Support System</title><script defer="defer" src="/static/js/main.4a33c7d9.js"></script><link href="/static/css/main.d802e3cd.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Academic Support System"/><title>Academic Support System</title><script defer="defer" src="/static/js/main.20b2f18c.js"></script><link href="/static/css/main.d802e3cd.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

build/static/static/js/main.4a33c7d9.js.map renamed to build/static/static/js/main.20b2f18c.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/api/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export const BASE_URL = 'https://learnpal.hdu.edu.cn/api';
1+
// export const BASE_URL = 'https://learnpal.hdu.edu.cn/api';
2+
export const BASE_URL = 'http://localhost:9001';

frontend/src/api/subjects.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ axios.interceptors.response.use(
1414
);
1515

1616
export const getSubjectLink = (staffId) => {
17-
return axios.get(`/subject/get/links/${staffId}`);
17+
const token = localStorage.getItem('token');
18+
return axios.get(`/subject/get/links/${staffId}`, {
19+
headers: { Authorization: `Bearer ${token}` }
20+
});
1821
};

internal/app/managers/handler/v1/managers.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ func HandleImportStudentSubjectsExcel(c flamego.Context, r flamego.Render) {
181181
}
182182

183183
// HandleAddManager 添加管理员
184-
func HandleAddManager(r flamego.Render, c flamego.Context, req dto.AddManagerRequest, errs binding.Errors) {
184+
func HandleAddManager(r flamego.Render, c flamego.Context, req dto.AddManagerRequest, errs binding.Errors, authInfo auth.Info) {
185185
if errs != nil {
186186
response.InValidParam(r, errs)
187187
return
188188
}
189+
if authInfo.Uid != req.StaffId {
190+
response.HTTPFail(r, 403001, "不能添加自己")
191+
return
192+
}
189193

190194
// 检查用户名是否已存在
191195
existing, err := dao.Managers.GetManagerByStaffID(req.StaffId)
@@ -257,7 +261,11 @@ func HandleDeleteManager(r flamego.Render, c flamego.Context, req dto.DeleteMana
257261
}
258262

259263
// HandleGetManagerList 获取管理员列表
260-
func HandleGetManagerList(r flamego.Render, c flamego.Context) {
264+
func HandleGetManagerList(r flamego.Render, c flamego.Context, authInfo auth.Info) {
265+
if authInfo.Uid == "" {
266+
response.HTTPFail(r, 403002, "permission denied")
267+
return
268+
}
261269
managers, total, err := dao.Managers.GetAllManagers()
262270
if err != nil {
263271
logx.SystemLogger.CtxError(c.Request().Context(), err)

internal/app/managers/router/managers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ func AppManagersInit(e *flamego.Flame) {
2424

2525
e.Group("/managers", func() {
2626
// 管理员管理相关接口(需要登录)
27-
e.Get("/list", handler.HandleGetManagerList, web.Authorization)
28-
e.Post("/add", binding.JSON(dto.AddManagerRequest{}), handler.HandleAddManager, web.Authorization)
29-
e.Post("/delete", binding.JSON(dto.DeleteManagerRequest{}), handler.HandleDeleteManager, web.Authorization)
27+
e.Get("/list", handler.HandleGetManagerList)
28+
e.Post("/add", binding.JSON(dto.AddManagerRequest{}), handler.HandleAddManager)
29+
e.Post("/delete", binding.JSON(dto.DeleteManagerRequest{}), handler.HandleDeleteManager)
3030

3131
// 学生科目导入接口(Excel上传)
32-
e.Post("/import/students", handler.HandleImportStudentSubjectsExcel, web.Authorization)
32+
e.Post("/import/students", handler.HandleImportStudentSubjectsExcel)
3333

3434
// 下载导入模板
3535
e.Get("/import/template", handler.HandleDownloadTemplate)
36-
})
36+
}, web.Authorization)
3737

3838
}
3939

0 commit comments

Comments
 (0)