aplus/main.go

68 lines
1.5 KiB
Go
Raw Normal View History

2023-10-27 19:02:38 -04:00
package main
import (
"fmt"
"io"
"net/http"
)
var base_link string
var token string
2023-10-27 19:02:38 -04:00
func main() {
client := http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
fmt.Println("Redirected to:", req.URL)
return nil
},
}
2023-10-27 19:02:38 -04:00
initialize()
2023-11-04 01:55:30 -04:00
// select_course()
2023-10-30 17:58:38 -04:00
2023-10-27 19:02:38 -04:00
aplus_link := fmt.Sprintf("%s/courses/%d/external_tools/sessionless_launch?id=913&access_token=%s", base_link, 7329, token) // 7329 always works
2023-11-04 01:55:30 -04:00
aplus := get_aplus(token, aplus_link, client)
2023-10-27 19:02:38 -04:00
fmt.Println(aplus)
resp, err := client.Get(aplus)
2023-10-27 19:02:38 -04:00
if err != nil {
2023-11-04 01:55:30 -04:00
fmt.Println("Error while performing GET request to aplus auth link.")
2023-10-27 19:02:38 -04:00
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
form_str := get_form_from_request_body(body)
fmt.Println(form_str)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
form_values := parse_form(form_str)
2023-10-31 02:06:01 -04:00
fmt.Println("Form Values:")
for key, values := range form_values {
fmt.Printf("%s: %s\n", key, values)
}
2023-10-31 02:30:30 -04:00
req, err := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
if err != nil {
fmt.Println("Error posting form to Aplus Attendance.")
2023-10-30 17:58:38 -04:00
}
2023-11-04 01:55:30 -04:00
body, err = io.ReadAll(req.Body)
2023-10-30 17:58:38 -04:00
if err != nil {
2023-11-04 01:55:30 -04:00
fmt.Println("Error reading body of post form response from aplus attendance.")
2023-10-30 17:58:38 -04:00
}
2023-11-04 01:55:30 -04:00
fmt.Println(string(body))
fmt.Println(req)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
// we need to submit the above post request correctly in order to submit this request.
//resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=true")
//body, _ = io.ReadAll(resp.Body)
2023-10-30 17:58:38 -04:00
2023-11-04 01:55:30 -04:00
//fmt.Println(string(body))
//fmt.Println(req)
}