Skip to content

Commit b675ddf

Browse files
author
Pachakutiq
committed
feat: authentication
1 parent 1236e58 commit b675ddf

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/components/Config.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<p>The URL of your canvas.</p>
1212
<a-input v-model:value="url" placeholder="Url" />
1313
<a-typography-title :level="3">Access Token</a-typography-title>
14-
<p>Access Token of your canvas account. (<a href="https://community.canvaslms.com/t5/Admin-Guide/How-do-I-manage-API-access-tokens-as-an-admin/ta-p/89" target="_blank">Tutorial for getting an access token</a>)</p>
14+
<p>Access Token of your canvas account. (<a
15+
href="https://community.canvaslms.com/t5/Admin-Guide/How-do-I-manage-API-access-tokens-as-an-admin/ta-p/89"
16+
target="_blank">Tutorial for getting an access token</a>)</p>
1517
<a-input v-model:value="token" placeholder="Access Token" />
1618
<a-typography-title :level="3">Semester <a-badge count="v 2.0" :number-style="{ backgroundColor: '#52c41a' }" />
1719
</a-typography-title>
@@ -138,7 +140,7 @@ export default defineComponent({
138140
}
139141
if (change.file.status == 'removed') {
140142
// Remove file
141-
const res = await del(`/file?name=${change.file.name}`);
143+
const res = await del(`/file?name=${change.file.name}`, { withCredentials: true });
142144
if (res && res.status == 200) {
143145
message.success('Remove success');
144146
} else {
@@ -156,7 +158,7 @@ export default defineComponent({
156158
message.success('Deleted user data');
157159
},
158160
async remove_attribute(key: string) {
159-
const res = await del(`/config/key/${key}`);
161+
const res = await del(`/config/key/${key}`, { withCredentials: true });
160162
return res && res.status == 200;
161163
},
162164
async set_attribute(key: string, value: number | string) {
@@ -168,15 +170,15 @@ export default defineComponent({
168170
if (typeof value === 'string') {
169171
value = '"' + value + '"';
170172
}
171-
const res = await put(`/config/key/${key}`, value);
173+
const res = await put(`/config/key/${key}`, value, { withCredentials: true });
172174
if (!res || res.status != 200) {
173175
message.error('Failed to set attribute: ' + key);
174176
this.has_err = true;
175177
}
176178
},
177179
async reload_files() {
178180
this.background_filelist = [];
179-
const all_files = await get('/file');
181+
const all_files = await get('/file', { withCredentials: true });
180182
if (all_files && all_files.status === 200) {
181183
for (const filename of all_files.data["files"]) {
182184
this.background_filelist.push({
@@ -190,7 +192,7 @@ export default defineComponent({
190192
},
191193
async reload() {
192194
// Reload configuration
193-
const res = await get('/config');
195+
const res = await get('/config', { withCredentials: true });
194196
if (res && res.status === 200) {
195197
// Got configuration
196198
const conf = res.data;
@@ -218,7 +220,7 @@ export default defineComponent({
218220
async verify() {
219221
// Verify the configuration
220222
this.verify_loading = true;
221-
const res = await get('/config/verify');
223+
const res = await get('/config/verify', { withCredentials: true });
222224
if (res && res.status === 200) {
223225
message.success('Configuration verified');
224226
} else {
@@ -229,7 +231,7 @@ export default defineComponent({
229231
async force_reload() {
230232
// Force Reload
231233
this.reload_loading = true;
232-
const res = await get('/config/refresh');
234+
const res = await get('/config/refresh', { withCredentials: true });
233235
if (res && res.status === 200) {
234236
message.success('Configuration reloaded');
235237
} else {

src/components/Courses.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export default defineComponent({
250250
maxshow: this.current_add_course.maxshow,
251251
order: this.current_add_course.order,
252252
msg: this.current_add_course.msg,
253-
});
253+
}, { withCredentials: true });
254254
if (res && res.status === 200) {
255255
message.success("Add course successfully");
256256
this.add_visible = false;
@@ -286,7 +286,7 @@ export default defineComponent({
286286
maxshow: this.current_edit_course.maxshow,
287287
order: this.current_edit_course.order,
288288
msg: this.current_edit_course.msg,
289-
});
289+
}, { withCredentials: true });
290290
if (response && response.status === 200) {
291291
message.success("Update course successfully");
292292
} else {
@@ -301,7 +301,7 @@ export default defineComponent({
301301
async refresh() {
302302
// Get courses
303303
this.loading_course_table = true;
304-
const response = await get("/courses");
304+
const response = await get("/courses", { withCredentials: true });
305305
if (response && response.status === 200) {
306306
const data = response.data;
307307
this.data = data.map((item: any, index: number) => {
@@ -319,7 +319,7 @@ export default defineComponent({
319319
message.error("Failed to get course info:" + response?.data.message);
320320
}
321321
322-
const canvascourses = await get("/courses/canvas");
322+
const canvascourses = await get("/courses/canvas", { withCredentials: true });
323323
this.canvas_courses = [];
324324
if (canvascourses && canvascourses.status === 200) {
325325
for (const course of canvascourses.data) {
@@ -344,7 +344,7 @@ export default defineComponent({
344344
for (const key of this.selectedRowKeys) {
345345
const response = await del(
346346
`/courses/${this.data[key].id}/${this.data[key].type}`
347-
);
347+
, { withCredentials: true });
348348
if (!response || response.status != 200) {
349349
hasError = true;
350350
message.error("Failed to delete course:" + response?.data.message);
@@ -370,7 +370,7 @@ export default defineComponent({
370370
maxshow: item.maxshow,
371371
order: item.order,
372372
msg: item.msg,
373-
});
373+
}, { withCredentials: true });
374374
if (response && response.status === 200) {
375375
message.success("Duplicate course successfully");
376376
} else {
@@ -380,7 +380,7 @@ export default defineComponent({
380380
await this.refresh();
381381
},
382382
async verify_config() {
383-
const response = await get("/config/verify");
383+
const response = await get("/config/verify", { withCredentials: true });
384384
return response && response.status === 200;
385385
}
386386
},

src/tools/requests.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { AxiosError } from 'axios'
33

44
export const Base_url = localStorage.getItem("serverURL") || 'http://localhost:9283';
55

6-
export async function get(path: string) {
6+
export async function get(path: string, config = {}) {
77
try {
8-
const response = await axios.get(Base_url + path)
8+
const response = await axios.get(Base_url + path, config)
99
return response
1010
}
1111
catch (error) {
@@ -17,9 +17,9 @@ export async function get(path: string) {
1717
}
1818
}
1919

20-
export async function put(path: string, data: any) {
20+
export async function put(path: string, data: any, config = {}) {
2121
try {
22-
const response = await axios.put(Base_url + path, data)
22+
const response = await axios.put(Base_url + path, data, config)
2323
return response
2424
}
2525
catch (error) {
@@ -31,9 +31,9 @@ export async function put(path: string, data: any) {
3131
}
3232
}
3333

34-
export async function post(path: string, data: any) {
34+
export async function post(path: string, data: any, config = {}) {
3535
try {
36-
const response = await axios.post(Base_url + path, data)
36+
const response = await axios.post(Base_url + path, data, config)
3737
return response
3838
}
3939
catch (error) {
@@ -45,9 +45,9 @@ export async function post(path: string, data: any) {
4545
}
4646
}
4747

48-
export async function del(path: string) {
48+
export async function del(path: string, config = {}) {
4949
try {
50-
const response = await axios.delete(Base_url + path)
50+
const response = await axios.delete(Base_url + path, config)
5151
return response
5252
}
5353
catch (error) {

0 commit comments

Comments
 (0)