I need sleep

This commit is contained in:
PoliEcho 2024-11-27 17:16:48 +01:00
parent a84b70991d
commit 723e955299
5 changed files with 28 additions and 23 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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();

View File

@ -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();
}
}

View File

@ -1,5 +1,6 @@
#include <curl/curl.h>
#include <string>
extern CURL *curl;
namespace bakaapi {
void login(std::string username, std::string password);
void refresh_access_token();