loginView added
parent
ef842c94f1
commit
0408821e46
|
@ -57,6 +57,7 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp
|
|||
${CMAKE_SOURCE_DIR}/src/util/item.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/listView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/listViewEntry.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/loginView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/util/util.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/util/log.cpp
|
||||
|
||||
|
|
|
@ -13,33 +13,44 @@
|
|||
#include "item.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
EventHandler * EventHandler::eventHandlerStatic;
|
||||
using std::string;
|
||||
|
||||
EventHandler *EventHandler::_eventHandlerStatic;
|
||||
|
||||
EventHandler::EventHandler()
|
||||
{
|
||||
//create a event to create handlers
|
||||
eventHandlerStatic = this;
|
||||
_eventHandlerStatic = this;
|
||||
|
||||
menu = new MenuHandler("Nextcloud");
|
||||
_menu = new MenuHandler("nextcloud");
|
||||
_nextcloud = new Nextcloud();
|
||||
_loginView = nullptr;
|
||||
_listView = nullptr;
|
||||
|
||||
nextcloud = new Nextcloud();
|
||||
//TODO SET USER, PASSWORD
|
||||
nextcloud->login("USER", "PASSWORD");
|
||||
|
||||
listView = new ListView(menu->getContentRect(),nextcloud->getItems());
|
||||
if (iv_access(NEXTCLOUD_CONFIG_PATH.c_str(), W_OK) == 0)
|
||||
{
|
||||
if (_nextcloud->login())
|
||||
{
|
||||
_listView = new ListView(_menu->getContentRect(), _nextcloud->getItems());
|
||||
FullUpdate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_loginView = new LoginView(_menu->getContentRect());
|
||||
_loginView->drawLoginView();
|
||||
FullUpdate();
|
||||
}
|
||||
|
||||
EventHandler::~EventHandler()
|
||||
{
|
||||
delete nextcloud;
|
||||
delete menu;
|
||||
delete listView;
|
||||
delete _nextcloud;
|
||||
delete _listView;
|
||||
delete _menu;
|
||||
}
|
||||
|
||||
int EventHandler::eventDistributor(int type, int par1, int par2)
|
||||
int EventHandler::eventDistributor(const int type, const int par1, const int par2)
|
||||
{
|
||||
if (ISPOINTEREVENT(type))
|
||||
return EventHandler::pointerHandler(type, par1, par2);
|
||||
|
@ -47,17 +58,26 @@ int EventHandler::eventDistributor(int type, int par1, int par2)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void EventHandler::mainMenuHandlerStatic(int index)
|
||||
void EventHandler::mainMenuHandlerStatic(const int index)
|
||||
{
|
||||
eventHandlerStatic->mainMenuHandler(index);
|
||||
_eventHandlerStatic->mainMenuHandler(index);
|
||||
}
|
||||
|
||||
void EventHandler::mainMenuHandler(int index)
|
||||
void EventHandler::mainMenuHandler(const int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
//Exit
|
||||
//Logout
|
||||
case 101:
|
||||
_nextcloud->logout();
|
||||
delete _listView;
|
||||
_listView = nullptr;
|
||||
_loginView = new LoginView(_menu->getContentRect());
|
||||
_loginView->drawLoginView();
|
||||
FullUpdate();
|
||||
break;
|
||||
//Exit
|
||||
case 102:
|
||||
CloseApp();
|
||||
break;
|
||||
default:
|
||||
|
@ -65,33 +85,45 @@ void EventHandler::mainMenuHandler(int index)
|
|||
}
|
||||
}
|
||||
|
||||
int EventHandler::pointerHandler(int type, int par1, int par2)
|
||||
int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
||||
{
|
||||
|
||||
if (type == EVT_POINTERDOWN)
|
||||
{
|
||||
if(IsInRect(par1,par2,menu->getMenuButtonRect())==1)
|
||||
if (IsInRect(par1, par2, _menu->getMenuButtonRect()) == 1)
|
||||
{
|
||||
return menu->createMenu(true,EventHandler::mainMenuHandlerStatic);
|
||||
return _menu->createMenu(_nextcloud->isLoggedIn(), EventHandler::mainMenuHandlerStatic);
|
||||
}
|
||||
else if(listView!= NULL)
|
||||
else if (_listView != nullptr)
|
||||
{
|
||||
int itemID = listView->listClicked(par1,par2);
|
||||
int itemID = _listView->listClicked(par1, par2);
|
||||
if (itemID != -1)
|
||||
{
|
||||
string tempPath = nextcloud->getItems()[itemID].isClicked();
|
||||
string tempPath = _nextcloud->getItems()[itemID].isClicked();
|
||||
|
||||
if (!tempPath.empty())
|
||||
nextcloud->getDataStructure(tempPath);
|
||||
_nextcloud->getDataStructure(tempPath);
|
||||
|
||||
delete listView;
|
||||
listView = new ListView(menu->getContentRect(),nextcloud->getItems());
|
||||
listView->drawHeader(tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
|
||||
delete _listView;
|
||||
_listView = new ListView(_menu->getContentRect(), _nextcloud->getItems());
|
||||
_listView->drawHeader(tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
|
||||
}
|
||||
|
||||
PartialUpdate(menu->getContentRect()->x,menu->getContentRect()->y,menu->getContentRect()->w,menu->getContentRect()->h);
|
||||
PartialUpdate(_menu->getContentRect()->x, _menu->getContentRect()->y, _menu->getContentRect()->w, _menu->getContentRect()->h);
|
||||
return 1;
|
||||
}
|
||||
else if (_loginView != nullptr)
|
||||
{
|
||||
if (_loginView->logginClicked(par1, par2) == 2)
|
||||
{
|
||||
if (_nextcloud->login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword()))
|
||||
{
|
||||
_listView = new ListView(_menu->getContentRect(), _nextcloud->getItems());
|
||||
delete _loginView;
|
||||
FullUpdate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
#include "menuHandler.h"
|
||||
#include "nextcloud.h"
|
||||
#include "listView.h"
|
||||
#include "loginView.h"
|
||||
|
||||
const string CONFIG_PATH = "/mnt/ext1/system/config/nextcloud";
|
||||
|
||||
class EventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Defines fonds, sets global Event Handler and starts new content
|
||||
*/
|
||||
|
@ -37,14 +37,15 @@ class EventHandler
|
|||
* @param par2 second argument of the event
|
||||
* @return int returns if the event was handled
|
||||
*/
|
||||
int eventDistributor(int type, int par1, int par2);
|
||||
int eventDistributor(const int type, const int par1, const int par2);
|
||||
|
||||
private:
|
||||
static EventHandler *_eventHandlerStatic;
|
||||
MenuHandler *_menu;
|
||||
Nextcloud *_nextcloud;
|
||||
ListView *_listView;
|
||||
LoginView *_loginView;
|
||||
|
||||
static EventHandler *eventHandlerStatic;
|
||||
MenuHandler *menu;
|
||||
Nextcloud *nextcloud;
|
||||
ListView* listView;
|
||||
|
||||
/**
|
||||
* Functions needed to call C function, redirects to real function
|
||||
|
@ -54,7 +55,7 @@ class EventHandler
|
|||
* @param par2 second argument of the event
|
||||
* @return int returns if the event was handled
|
||||
*/
|
||||
static void mainMenuHandlerStatic(int index);
|
||||
static void mainMenuHandlerStatic(const int index);
|
||||
/**
|
||||
* Handles menu events and redirects them
|
||||
*
|
||||
|
@ -63,7 +64,7 @@ class EventHandler
|
|||
* @param par2 second argument of the event
|
||||
* @return int returns if the event was handled
|
||||
*/
|
||||
void mainMenuHandler(int index);
|
||||
void mainMenuHandler(const int index);
|
||||
|
||||
/**
|
||||
* Handles pointer Events
|
||||
|
@ -73,6 +74,6 @@ class EventHandler
|
|||
* @param par2 second argument of the event
|
||||
* @return int returns if the event was handled
|
||||
*/
|
||||
int pointerHandler(int type, int par1, int par2);
|
||||
int pointerHandler(const int type, const int par1, const int par2);
|
||||
};
|
||||
#endif
|
|
@ -52,13 +52,15 @@ int MenuHandler::createMenu(bool loggedIn, iv_menuhandler handler)
|
|||
imenu mainMenu[] =
|
||||
{
|
||||
{ITEM_HEADER, 0, "Menu", NULL},
|
||||
//show logged in
|
||||
{loggedIn ? ITEM_ACTIVE : ITEM_HIDDEN, 101, "Logout", NULL},
|
||||
//show always
|
||||
{ITEM_ACTIVE, 101, "Exit"},
|
||||
{ITEM_ACTIVE, 102, "Exit"},
|
||||
{0, 0, NULL, NULL}};
|
||||
|
||||
if (loggedIn)
|
||||
{
|
||||
mainMenu[1].type = ITEM_ACTIVE;
|
||||
mainMenu[2].type = ITEM_ACTIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
//------------------------------------------------------------------
|
||||
// loginView.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 26.08.2020
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "inkview.h"
|
||||
#include "loginView.h"
|
||||
#include "eventHandler.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
LoginView *LoginView::_loginViewStatic;
|
||||
|
||||
LoginView::LoginView(irect *contentRect) : _contentRect(contentRect)
|
||||
{
|
||||
_loginViewStatic = this;
|
||||
_loginFont = OpenFont("LiberationMono", 40, 1);
|
||||
}
|
||||
|
||||
LoginView::~LoginView()
|
||||
{
|
||||
CloseFont(_loginFont);
|
||||
}
|
||||
|
||||
void LoginView::drawLoginView()
|
||||
{
|
||||
FillAreaRect(_contentRect, WHITE);
|
||||
|
||||
_urlButton = iRect(50, 200, (ScreenWidth() - 50), 75, ALIGN_CENTER);
|
||||
DrawLine(20, 275, (ScreenWidth() - 20), 275, BLACK);
|
||||
SetFont(_loginFont, BLACK);
|
||||
DrawTextRect2(&_urlButton, "Url");
|
||||
|
||||
_usernameButton = iRect(50, 400, ScreenWidth() - 50, 75, ALIGN_CENTER);
|
||||
DrawLine(20, 475, (ScreenWidth() - 20), 475, BLACK);
|
||||
SetFont(_loginFont, BLACK);
|
||||
DrawTextRect2(&_usernameButton, "Username");
|
||||
|
||||
_passwordButton = iRect(50, 600, (ScreenWidth() - 50), 75, ALIGN_CENTER);
|
||||
DrawLine(20, 675, (ScreenWidth() - 20), 675, BLACK);
|
||||
SetFont(_loginFont, BLACK);
|
||||
DrawTextRect2(&_passwordButton, "Password");
|
||||
|
||||
_loginButton = iRect(ScreenWidth() / 2 - (200 / 2), 700, 200, 50, ALIGN_CENTER);
|
||||
|
||||
FillAreaRect(&_loginButton, BLACK);
|
||||
SetFont(_loginFont, WHITE);
|
||||
DrawTextRect2(&_loginButton, "Login");
|
||||
}
|
||||
|
||||
void LoginView::keyboardHandlerStatic(char *text)
|
||||
{
|
||||
_loginViewStatic->keyboardHandler(text);
|
||||
}
|
||||
|
||||
void LoginView::keyboardHandler(char *text)
|
||||
{
|
||||
if (!text)
|
||||
return;
|
||||
|
||||
string s(text);
|
||||
if (s.empty())
|
||||
return;
|
||||
|
||||
if (_test == 1)
|
||||
{
|
||||
_url = s.c_str();
|
||||
FillAreaRect(&_urlButton, WHITE);
|
||||
DrawTextRect2(&_urlButton, s.c_str());
|
||||
}
|
||||
else if (_test == 2)
|
||||
{
|
||||
_username = s.c_str();
|
||||
FillAreaRect(&_usernameButton, WHITE);
|
||||
DrawTextRect2(&_usernameButton, s.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_password = s.c_str();
|
||||
FillAreaRect(&_passwordButton, WHITE);
|
||||
|
||||
string pass;
|
||||
for (auto i = 0; i < s.length(); i++)
|
||||
{
|
||||
pass += "*";
|
||||
}
|
||||
|
||||
DrawTextRect2(&_passwordButton, pass.c_str());
|
||||
}
|
||||
|
||||
_charBuffer = NULL;
|
||||
}
|
||||
|
||||
int LoginView::logginClicked(int x, int y)
|
||||
{
|
||||
_charBuffer = new char[4 * MAX_CHAR_BUFF_LENGHT + 1];
|
||||
|
||||
if (IsInRect(x, y, &_urlButton))
|
||||
{
|
||||
_test = 1;
|
||||
OpenKeyboard("Url", _charBuffer, MAX_CHAR_BUFF_LENGHT - 1, KBD_NORMAL, &keyboardHandlerStatic);
|
||||
return 1;
|
||||
}
|
||||
|
||||
else if (IsInRect(x, y, &_usernameButton))
|
||||
{
|
||||
_test = 2;
|
||||
OpenKeyboard("Username", _charBuffer, MAX_CHAR_BUFF_LENGHT - 1, KBD_NORMAL, &keyboardHandlerStatic);
|
||||
return 1;
|
||||
}
|
||||
else if (IsInRect(x, y, &_passwordButton))
|
||||
{
|
||||
_test = 3;
|
||||
OpenKeyboard("Password", _charBuffer, MAX_CHAR_BUFF_LENGHT - 1, KBD_PASSWORD, &keyboardHandlerStatic);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (IsInRect(x, y, &_loginButton))
|
||||
{
|
||||
if (_username.empty() || _password.empty() || _url.empty())
|
||||
{
|
||||
Message(ICON_ERROR, "Error", "Please set url, username and password.", 600);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
//------------------------------------------------------------------
|
||||
// loginView.h
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 26.08.2020
|
||||
// Description:
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#ifndef LOGIN_SCREEN
|
||||
#define LOGIN_SCREEN
|
||||
|
||||
#include "inkview.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
const int MAX_CHAR_BUFF_LENGHT = 256;
|
||||
|
||||
class LoginView
|
||||
{
|
||||
public:
|
||||
LoginView(irect *contentRect);
|
||||
~LoginView();
|
||||
|
||||
void drawLoginView();
|
||||
int logginClicked(int x, int y);
|
||||
|
||||
string getUsername() { return _username; };
|
||||
string getPassword() { return _password; };
|
||||
string getURL() { return _url; };
|
||||
|
||||
private:
|
||||
static LoginView *_loginViewStatic;
|
||||
ifont *_loginFont;
|
||||
irect *_contentRect;
|
||||
irect _urlButton;
|
||||
irect _loginButton;
|
||||
irect _usernameButton;
|
||||
irect _passwordButton;
|
||||
int _test;
|
||||
string _username;
|
||||
string _password;
|
||||
string _url;
|
||||
char *_charBuffer;
|
||||
|
||||
/**
|
||||
* Functions needed to call C function, handles the panel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static void keyboardHandlerStatic(char *text);
|
||||
|
||||
void keyboardHandler(char *text);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -14,11 +14,11 @@
|
|||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
|
||||
using namespace std;
|
||||
using std::string;
|
||||
|
||||
Nextcloud::Nextcloud()
|
||||
{
|
||||
loggedIn = false;
|
||||
_loggedIn = false;
|
||||
|
||||
if (iv_access(NEXTCLOUD_PATH.c_str(), W_OK) != 0)
|
||||
iv_mkdir(NEXTCLOUD_PATH.c_str(), 0777);
|
||||
|
@ -27,6 +27,14 @@ Nextcloud::Nextcloud()
|
|||
iv_mkdir(NEXTCLOUD_FILE_PATH.c_str(), 0777);
|
||||
}
|
||||
|
||||
void Nextcloud::setURL(const string &Url)
|
||||
{
|
||||
iconfigedit *temp = nullptr;
|
||||
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
|
||||
WriteString(nextcloudConfig, "url", Url.c_str());
|
||||
CloseConfig(nextcloudConfig);
|
||||
}
|
||||
|
||||
void Nextcloud::setUsername(const string &Username)
|
||||
{
|
||||
iconfigedit *temp = nullptr;
|
||||
|
@ -43,56 +51,60 @@ void Nextcloud::setPassword(const string& Pass)
|
|||
CloseConfig(nextcloudConfig);
|
||||
}
|
||||
|
||||
string Nextcloud::getUsername()
|
||||
bool Nextcloud::login()
|
||||
{
|
||||
iconfigedit *temp = nullptr;
|
||||
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(),temp);
|
||||
string user = ReadString(nextcloudConfig,"username","");
|
||||
CloseConfigNoSave(nextcloudConfig);
|
||||
return user;
|
||||
if (getDataStructure(NEXTCLOUD_ROOT_PATH + this->getUsername() + "/", this->getUsername(), this->getPassword()))
|
||||
{
|
||||
_loggedIn = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
string Nextcloud::getPassword()
|
||||
{
|
||||
iconfigedit *temp = nullptr;
|
||||
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(),temp);
|
||||
string pass = ReadSecret(nextcloudConfig,"password","");
|
||||
CloseConfigNoSave(nextcloudConfig);
|
||||
return pass;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Nextcloud::login(const string& Username, const string& Pass)
|
||||
bool Nextcloud::login(const string &Url, const string &Username, const string &Pass)
|
||||
{
|
||||
_url = Url;
|
||||
if (getDataStructure(NEXTCLOUD_ROOT_PATH + Username + "/", Username, Pass))
|
||||
{
|
||||
if (iv_access(NEXTCLOUD_CONFIG_PATH.c_str(), W_OK) != 0)
|
||||
iv_buildpath(NEXTCLOUD_CONFIG_PATH.c_str());
|
||||
this->setUsername(Username);
|
||||
this->setPassword(Pass);
|
||||
loggedIn = true;
|
||||
this->setURL(_url);
|
||||
_loggedIn = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Nextcloud::logout()
|
||||
{
|
||||
remove(NEXTCLOUD_CONFIG_PATH.c_str());
|
||||
_url.clear();
|
||||
_loggedIn = false;
|
||||
}
|
||||
|
||||
bool Nextcloud::getDataStructure(string &pathUrl)
|
||||
{
|
||||
return getDataStructure(pathUrl, this->getUsername(), this->getPassword());
|
||||
}
|
||||
|
||||
|
||||
bool Nextcloud::getDataStructure(const string &pathUrl, const string &Username, const string &Pass)
|
||||
{
|
||||
if (!Util::connectToNetwork())
|
||||
return false;
|
||||
|
||||
if (_url.empty())
|
||||
_url = this->getUrl();
|
||||
|
||||
if (Username.empty() || Pass.empty())
|
||||
{
|
||||
Message(ICON_ERROR, "Error", "Username/password not set.", 1200);
|
||||
return false;
|
||||
}
|
||||
|
||||
items.clear();
|
||||
_items.clear();
|
||||
string readBuffer;
|
||||
CURLcode res;
|
||||
CURL *curl = curl_easy_init();
|
||||
|
@ -103,7 +115,7 @@ bool Nextcloud::getDataStructure(const string& pathUrl, const string& Username,
|
|||
|
||||
struct curl_slist *headers = NULL;
|
||||
headers = curl_slist_append(headers, "Depth: 1");
|
||||
curl_easy_setopt(curl, CURLOPT_URL, (NEXTCLOUD_URL + pathUrl).c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_URL, (_url + pathUrl).c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_USERPWD, post.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PROPFIND");
|
||||
|
@ -133,24 +145,24 @@ bool Nextcloud::getDataStructure(const string& pathUrl, const string& Username,
|
|||
{
|
||||
end = readBuffer.find(endItem);
|
||||
|
||||
this->items.push_back(Item(readBuffer.substr(begin,end)));
|
||||
this->_items.push_back(Item(readBuffer.substr(begin, end)));
|
||||
|
||||
readBuffer = readBuffer.substr(end + endItem.length());
|
||||
|
||||
begin = readBuffer.find(beginItem);
|
||||
}
|
||||
|
||||
if(items.size() < 1)
|
||||
if (_items.size() < 1)
|
||||
return false;
|
||||
|
||||
string tes = items[0].getPath();
|
||||
string tes = _items[0].getPath();
|
||||
tes = tes.substr(0, tes.find_last_of("/"));
|
||||
tes = tes.substr(0, tes.find_last_of("/") + 1);
|
||||
items[0].setPath(tes);
|
||||
items[0].setTitle("...");
|
||||
_items[0].setPath(tes);
|
||||
_items[0].setTitle("...");
|
||||
|
||||
if(items[0].getPath().compare(NEXTCLOUD_ROOT_PATH) == 0)
|
||||
items.erase(items.begin());
|
||||
if (_items[0].getPath().compare(NEXTCLOUD_ROOT_PATH) == 0)
|
||||
_items.erase(_items.begin());
|
||||
|
||||
return true;
|
||||
break;
|
||||
|
@ -166,3 +178,30 @@ bool Nextcloud::getDataStructure(const string& pathUrl, const string& Username,
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
string Nextcloud::getUrl()
|
||||
{
|
||||
iconfigedit *temp = nullptr;
|
||||
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
|
||||
string url = ReadString(nextcloudConfig, "url", "");
|
||||
CloseConfigNoSave(nextcloudConfig);
|
||||
return url;
|
||||
}
|
||||
|
||||
string Nextcloud::getUsername()
|
||||
{
|
||||
iconfigedit *temp = nullptr;
|
||||
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
|
||||
string user = ReadString(nextcloudConfig, "username", "");
|
||||
CloseConfigNoSave(nextcloudConfig);
|
||||
return user;
|
||||
}
|
||||
|
||||
string Nextcloud::getPassword()
|
||||
{
|
||||
iconfigedit *temp = nullptr;
|
||||
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
|
||||
string pass = ReadSecret(nextcloudConfig, "password", "");
|
||||
CloseConfigNoSave(nextcloudConfig);
|
||||
return pass;
|
||||
}
|
|
@ -16,25 +16,19 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
const string NEXTCLOUD_PATH = "/mnt/ext1/system/config/nextcloud";
|
||||
const string NEXTCLOUD_CONFIG_PATH = NEXTCLOUD_PATH + "/nextcloud.cfg";
|
||||
const string NEXTCLOUD_FILE_PATH = "/mnt/ext1/nextcloud/";
|
||||
const string NEXTCLOUD_URL = "https://cloud.jjohannssen.de";
|
||||
const string NEXTCLOUD_ROOT_PATH = "/remote.php/dav/files/";
|
||||
|
||||
class Nextcloud {
|
||||
class Nextcloud
|
||||
{
|
||||
public:
|
||||
|
||||
explicit Nextcloud();
|
||||
|
||||
void setUsername(const string& Username);
|
||||
void setPassword(const string& Pass);
|
||||
|
||||
vector<Item> &getItems(){return items;};
|
||||
bool isLoggedIn(){return loggedIn;};
|
||||
|
||||
/**
|
||||
* Handles first login to nextcloud, if sucessfull saves userdata
|
||||
*
|
||||
|
@ -42,7 +36,11 @@ class Nextcloud {
|
|||
* @param Pass the pass of the Nextcloud instance
|
||||
* @return true - sucessfull login, false - failed login
|
||||
*/
|
||||
bool login(const string& Username, const string& Pass);
|
||||
bool login(const string &Url, const string &Username, const string &Pass);
|
||||
|
||||
bool login();
|
||||
|
||||
void logout();
|
||||
|
||||
/**
|
||||
* gets the dataStructure of the given URL and writes its WEBDAV items to the items vector, reads Userdata from configfile
|
||||
|
@ -52,6 +50,19 @@ class Nextcloud {
|
|||
*/
|
||||
bool getDataStructure(string &pathUrl);
|
||||
|
||||
void setURL(const string &Url);
|
||||
void setUsername(const string &Username);
|
||||
void setPassword(const string &Pass);
|
||||
|
||||
vector<Item> getItems() { return _items; };
|
||||
bool isLoggedIn() { return _loggedIn; };
|
||||
|
||||
private:
|
||||
vector<Item> _items;
|
||||
bool _loggedIn;
|
||||
string _url;
|
||||
//make username and password local variables or get each time? --> it cant change during login??
|
||||
|
||||
/**
|
||||
* gets the dataStructure of the given URL and writes its WEBDAV items to the items vector
|
||||
*
|
||||
|
@ -62,14 +73,9 @@ class Nextcloud {
|
|||
*/
|
||||
bool getDataStructure(const string &pathUrl, const string &Username, const string &Pass);
|
||||
|
||||
private:
|
||||
vector<Item> items;
|
||||
bool loggedIn;
|
||||
|
||||
string getUsername();
|
||||
string getPassword();
|
||||
string getUrl();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue