summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJuan Roig <jaroig@outlook.com>2023-11-13 02:08:03 -0500
committerJuan Roig <jaroig@outlook.com>2023-11-13 02:08:03 -0500
commite46ca43d4cd6e44972123856bbe047eb0517768e (patch)
treea3542a6c165525fd1665aebf12a8ef73c0f6ae16 /main.go
parent78fd5e4e1f084b1f031c80c964f795e225f0d25a (diff)
Move aplus requests to new launch_aplus function
Diffstat (limited to 'main.go')
-rw-r--r--main.go75
1 files changed, 4 insertions, 71 deletions
diff --git a/main.go b/main.go
index 473b027..8f669e1 100644
--- a/main.go
+++ b/main.go
@@ -1,86 +1,19 @@
1package main 1package main
2 2
3import ( 3import (
4 "fmt"
5 "io"
6 "net/http" 4 "net/http"
7 "net/http/cookiejar"
8 "strings"
9
10 "golang.org/x/net/publicsuffix"
11) 5)
12 6
13var base_link string 7var base_link string
14var token string 8var token string
9var client http.Client
15 10
16func main() { 11func main() {
17
18 jar, _ := cookiejar.New(&cookiejar.Options{
19 PublicSuffixList: publicsuffix.List,
20 })
21
22 client := http.Client{
23 CheckRedirect: func(req *http.Request, via []*http.Request) error {
24 fmt.Println("Redirected to:", req.URL)
25 fmt.Println(req.Cookies())
26 return nil
27 },
28 Jar: jar,
29 }
30
31 initialize() 12 initialize()
32 13
33 // select_course() 14 // select_course()
15 course_code := 7329
16 launch_aplus(course_code)
34 17
35 aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works 18 // enter_code()
36 aplus := get_aplus(token, aplus_link, client)
37 fmt.Println(aplus)
38 resp, err := client.Get(aplus)
39
40 if err != nil {
41 fmt.Println("Error while performing GET request to aplus auth link.")
42 }
43
44 defer resp.Body.Close()
45 body, _ := io.ReadAll(resp.Body)
46
47 form_str := get_form_from_request_body(body)
48 fmt.Println(form_str)
49
50 form_values := parse_form(form_str)
51
52 fmt.Println("Form Values:")
53 for key, values := range form_values {
54 fmt.Printf("%s: %s\n", key, values)
55 }
56
57 //req, _ := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
58 req, _ := http.NewRequest(http.MethodPost, "https://floridapoly.aplusattendance.com/canvas", strings.NewReader(form_values.Encode()))
59 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
60 req.Header.Set("Access-Control-Allow-Origin", "*")
61 req.Header.Set("Access-Control-Allow-Credentials", "true")
62 req.Header.Set("Access-Control-Allow-Headers", "Content-Type,access-control-allow-origin, access-control-allow-headers,access-control-allow-credentials")
63
64 resp, err = client.Do(req)
65
66 if err != nil {
67 fmt.Println("Error posting form to Aplus Attendance.")
68 }
69
70 body, err = io.ReadAll(resp.Body)
71
72 if err != nil {
73 fmt.Println("Error reading body of post form response from aplus attendance.")
74 }
75
76 fmt.Println(string(body))
77 //fmt.Println(resp)
78 fmt.Println(resp.Header)
79 fmt.Println(resp.Cookies())
80 // we need to submit the above post request correctly in order to submit this request.
81 //resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&amp;doStudentAuth=truee")
82 //body, _ = io.ReadAll(resp.Body)
83
84 //fmt.Println(string(body))
85 //fmt.Println(req)
86} 19}