i am so stupid
This commit is contained in:
parent
2d35ee060c
commit
763ffcfaa6
@ -23,9 +23,6 @@ int main(int argc, char **argv) {
|
||||
// error signal handlers
|
||||
signal(SIGSEGV, safe_exit);
|
||||
|
||||
// main_menu();
|
||||
// bakaapi::is_logged_in();
|
||||
/*
|
||||
std::cout << "enter school bakalari url:\n";
|
||||
while (true) {
|
||||
std::cout << "(or q to quit )";
|
||||
@ -46,7 +43,7 @@ int main(int argc, char **argv) {
|
||||
if (baka_api_url.back() != '/') {
|
||||
baka_api_url.append("/");
|
||||
}
|
||||
*/
|
||||
|
||||
{
|
||||
std::string username;
|
||||
std::cout << "enter username: ";
|
||||
@ -59,6 +56,8 @@ int main(int argc, char **argv) {
|
||||
// std::cin >> password;
|
||||
|
||||
bakaapi::login(username, password);
|
||||
|
||||
main_menu();
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -57,10 +57,7 @@ void main_menu() {
|
||||
/* Print a border around the main window and print a title */
|
||||
box(my_menu_win, 0, 0);
|
||||
|
||||
char title_text[40] = "Main Menu - login status: ";
|
||||
// strcat(title_text, bool_to_string(bakaapi::is_logged_in()).c_str());
|
||||
|
||||
print_in_middle(my_menu_win, 1, 0, 40, title_text, COLOR_PAIR(1));
|
||||
print_in_middle(my_menu_win, 1, 0, 40, "Main Menu", COLOR_PAIR(1));
|
||||
mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
|
||||
mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
|
||||
mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
|
||||
|
24
src/net.cpp
24
src/net.cpp
@ -28,7 +28,8 @@ size_t WriteCallback(void *contents, size_t size, size_t nmemb,
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
std::string send_curl_request(std::string endpoint, std::string type,
|
||||
std::tuple<std::string, int> send_curl_request(std::string endpoint,
|
||||
std::string type,
|
||||
std::string req_data) {
|
||||
std::string response;
|
||||
std::string url = baka_api_url + endpoint;
|
||||
@ -62,9 +63,12 @@ std::string send_curl_request(std::string endpoint, std::string type,
|
||||
}
|
||||
curl_easy_perform(curl); // Perform the request
|
||||
|
||||
int http_code = 0;
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
|
||||
curl_easy_cleanup(curl); // Cleanup
|
||||
|
||||
return response;
|
||||
return {response, http_code};
|
||||
}
|
||||
namespace bakaapi {
|
||||
|
||||
@ -76,7 +80,12 @@ void login(std::string username, std::string password) {
|
||||
std::format("client_id=ANDR&grant_type=password&username={}&password={}",
|
||||
username, password);
|
||||
|
||||
std::string response = send_curl_request("api/login", "POST", req_data);
|
||||
auto [response, http_code] = send_curl_request("api/login", "POST", req_data);
|
||||
if (http_code != 200) {
|
||||
std::cerr << RED "[ERROR] " << RESET << http_code
|
||||
<< "is non 200 response\n";
|
||||
safe_exit(55);
|
||||
}
|
||||
|
||||
std::string savedir_path = std::getenv("HOME");
|
||||
savedir_path.append("/.local/share/bakatui");
|
||||
@ -124,7 +133,12 @@ void refresh_access_token() {
|
||||
"token&refresh_token={}",
|
||||
refresh_token);
|
||||
|
||||
std::string response = send_curl_request("api/login", "POST", req_data);
|
||||
auto [response, http_code] = send_curl_request("api/login", "POST", req_data);
|
||||
if (http_code != 200) {
|
||||
std::cerr << RED "[ERROR] " << RESET << http_code
|
||||
<< "is non 200 response\n";
|
||||
safe_exit(55);
|
||||
}
|
||||
|
||||
{
|
||||
std::ofstream authfile_out;
|
||||
@ -137,4 +151,6 @@ void refresh_access_token() {
|
||||
|
||||
access_token = resp_parsed["access_token"];
|
||||
}
|
||||
|
||||
bool is_logged_in() {}
|
||||
} // namespace bakaapi
|
Loading…
x
Reference in New Issue
Block a user