Skip to content

Commit

Permalink
Add csrf token for assignment submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
robertying committed Sep 19, 2021
1 parent a6a455f commit edc11b3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 254 deletions.
6 changes: 4 additions & 2 deletions src/data/source.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Learn2018Helper} from 'thu-learn-lib-no-native';
import {Learn2018Helper, addCSRFTokenToUrl} from 'thu-learn-lib-no-native';
import mime from 'mime-types';
import axios from 'axios';

Expand Down Expand Up @@ -47,7 +47,9 @@ const submitAssignment = async (
} catch {}

try {
const res = await axios.post(submitAssignmentUrl, body, {
const csrfToken = dataSource.getCSRFToken();
const url = addCSRFTokenToUrl(submitAssignmentUrl, csrfToken);
const res = await axios.post(url, body, {
onUploadProgress: e => onProgress?.(e.loaded / e.total),
});

Expand Down
Loading

0 comments on commit edc11b3

Please sign in to comment.