I need sleep
This commit is contained in:
parent
a84b70991d
commit
723e955299
@ -3,11 +3,11 @@
|
||||
#include <dirent.h>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#include "net.h"
|
||||
|
||||
void safe_exit(int code) {
|
||||
switch (code) {
|
||||
@ -33,6 +33,8 @@ void safe_exit(int code) {
|
||||
break;
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
exit(code);
|
||||
}
|
||||
|
||||
@ -73,4 +75,17 @@ std::string SoRAuthFile(bool save, std::string data){
|
||||
}
|
||||
}
|
||||
|
||||
void get_input_and_login() {
|
||||
std::string username;
|
||||
std::cout << "enter username: ";
|
||||
std::cin >> username;
|
||||
std::string password;
|
||||
|
||||
password = getpass("enter password: ");
|
||||
// DEBUG
|
||||
// std::cout << "\nenter password: ";
|
||||
// std::cin >> password;
|
||||
|
||||
bakaapi::login(username, password);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <string>
|
||||
void safe_exit(int code);
|
||||
std::string bool_to_string(bool bool_in);
|
||||
std::string SoRAuthFile(bool save, std::string data);
|
||||
std::string SoRAuthFile(bool save, std::string data);
|
||||
void get_input_and_login();
|
17
src/main.cpp
17
src/main.cpp
@ -3,6 +3,7 @@
|
||||
#include "helper_funcs.h"
|
||||
#include "main_menu.h"
|
||||
#include "net.h"
|
||||
#include "helper_funcs.h"
|
||||
#include <csignal>
|
||||
#include <curl/curl.h>
|
||||
#include <curses.h>
|
||||
@ -57,21 +58,7 @@ int main(int argc, char **argv) {
|
||||
baka_api_url.append("/");
|
||||
}
|
||||
|
||||
{
|
||||
std::string username;
|
||||
std::cout << "enter username: ";
|
||||
std::cin >> username;
|
||||
std::string password;
|
||||
|
||||
password = getpass("enter password: ");
|
||||
// DEBUG
|
||||
// std::cout << "\nenter password: ";
|
||||
// std::cin >> password;
|
||||
|
||||
bakaapi::login(username, password);
|
||||
}
|
||||
} else {
|
||||
bakaapi::is_logged_in();
|
||||
get_input_and_login();
|
||||
}
|
||||
main_menu();
|
||||
|
||||
|
13
src/net.cpp
13
src/net.cpp
@ -7,9 +7,8 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <curl/curl.h>
|
||||
#include <curses.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@ -79,8 +78,8 @@ void login(std::string username, std::string password) {
|
||||
|
||||
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";
|
||||
std::cerr << RED "[ERROR] " << RESET << "login failed " << http_code
|
||||
<< " is non 200 response\n";
|
||||
safe_exit(55);
|
||||
}
|
||||
|
||||
@ -120,7 +119,7 @@ void refresh_access_token() {
|
||||
if (http_code != 200) {
|
||||
std::cerr << RED "[ERROR] " << RESET << http_code
|
||||
<< "is non 200 response\n";
|
||||
safe_exit(55);
|
||||
get_input_and_login();
|
||||
}
|
||||
|
||||
SoRAuthFile(true, response);
|
||||
@ -141,7 +140,9 @@ json get_grades() {
|
||||
|
||||
auto [response, http_code] = send_curl_request("api/3/marks", "GET", req_data);
|
||||
|
||||
|
||||
if(http_code != 200) {
|
||||
refresh_access_token();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user