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