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
|
// error signal handlers
|
||||||
signal(SIGSEGV, safe_exit);
|
signal(SIGSEGV, safe_exit);
|
||||||
|
|
||||||
// main_menu();
|
|
||||||
// bakaapi::is_logged_in();
|
|
||||||
/*
|
|
||||||
std::cout << "enter school bakalari url:\n";
|
std::cout << "enter school bakalari url:\n";
|
||||||
while (true) {
|
while (true) {
|
||||||
std::cout << "(or q to quit )";
|
std::cout << "(or q to quit )";
|
||||||
@ -46,7 +43,7 @@ int main(int argc, char **argv) {
|
|||||||
if (baka_api_url.back() != '/') {
|
if (baka_api_url.back() != '/') {
|
||||||
baka_api_url.append("/");
|
baka_api_url.append("/");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
{
|
{
|
||||||
std::string username;
|
std::string username;
|
||||||
std::cout << "enter username: ";
|
std::cout << "enter username: ";
|
||||||
@ -59,6 +56,8 @@ int main(int argc, char **argv) {
|
|||||||
// std::cin >> password;
|
// std::cin >> password;
|
||||||
|
|
||||||
bakaapi::login(username, password);
|
bakaapi::login(username, password);
|
||||||
|
|
||||||
|
main_menu();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -57,10 +57,7 @@ void main_menu() {
|
|||||||
/* Print a border around the main window and print a title */
|
/* Print a border around the main window and print a title */
|
||||||
box(my_menu_win, 0, 0);
|
box(my_menu_win, 0, 0);
|
||||||
|
|
||||||
char title_text[40] = "Main Menu - login status: ";
|
print_in_middle(my_menu_win, 1, 0, 40, "Main Menu", COLOR_PAIR(1));
|
||||||
// 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));
|
|
||||||
mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
|
mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
|
||||||
mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
|
mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
|
||||||
mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
|
mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
|
||||||
|
26
src/net.cpp
26
src/net.cpp
@ -28,8 +28,9 @@ size_t WriteCallback(void *contents, size_t size, size_t nmemb,
|
|||||||
return totalSize;
|
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 req_data) {
|
std::string type,
|
||||||
|
std::string req_data) {
|
||||||
std::string response;
|
std::string response;
|
||||||
std::string url = baka_api_url + endpoint;
|
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
|
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
|
curl_easy_cleanup(curl); // Cleanup
|
||||||
|
|
||||||
return response;
|
return {response, http_code};
|
||||||
}
|
}
|
||||||
namespace bakaapi {
|
namespace bakaapi {
|
||||||
|
|
||||||
@ -76,7 +80,12 @@ void login(std::string username, std::string password) {
|
|||||||
std::format("client_id=ANDR&grant_type=password&username={}&password={}",
|
std::format("client_id=ANDR&grant_type=password&username={}&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");
|
std::string savedir_path = std::getenv("HOME");
|
||||||
savedir_path.append("/.local/share/bakatui");
|
savedir_path.append("/.local/share/bakatui");
|
||||||
@ -124,7 +133,12 @@ void refresh_access_token() {
|
|||||||
"token&refresh_token={}",
|
"token&refresh_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;
|
std::ofstream authfile_out;
|
||||||
@ -137,4 +151,6 @@ void refresh_access_token() {
|
|||||||
|
|
||||||
access_token = resp_parsed["access_token"];
|
access_token = resp_parsed["access_token"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_logged_in() {}
|
||||||
} // namespace bakaapi
|
} // namespace bakaapi
|
Loading…
x
Reference in New Issue
Block a user