improved the login in the interaction between terminal api client and main

This commit is contained in:
csoler 2017-07-08 17:38:09 +02:00
parent 7ee527ecbd
commit decbd3514d
5 changed files with 148 additions and 92 deletions

View file

@ -150,24 +150,29 @@ void RsControlModule::run()
}
// skip account selection if autologin is available
if(initResult != RS_INIT_HAVE_ACCOUNT)
setRunState(WAITING_ACCOUNT_SELECT);
bool wait_for_account_select = (initResult != RS_INIT_HAVE_ACCOUNT);
// wait for login request
bool auto_login = false;
bool wait_for_account_select = (initResult != RS_INIT_HAVE_ACCOUNT);
if(wait_for_account_select)
setRunState(WAITING_ACCOUNT_SELECT);
while(wait_for_account_select && !processShouldExit())
{
usleep(5*1000);
usleep(500*1000);
RsStackMutex stack(mDataMtx); // ********** LOCKED **********
wait_for_account_select = mLoadPeerId.isNull();
if(!mLoadPeerId.isNull())
wait_for_account_select = wait_for_account_select && !RsAccounts::SelectAccount(mLoadPeerId);
auto_login = mAutoLoginNextTime;
if(!wait_for_account_select)
{
wait_for_account_select = !RsAccounts::SelectAccount(mLoadPeerId);
if(wait_for_account_select)
setRunState(WAITING_ACCOUNT_SELECT);
}
//if(!wait_for_account_select)
//{
// if(wait_for_account_select)
// setRunState(WAITING_ACCOUNT_SELECT);
//}
}
if(processShouldExit())

View file

@ -23,6 +23,8 @@ class ApiServer;
class RsControlModule: public ResourceRouter, NotifyClient, private RsSingleJobThread
{
public:
enum RunState { WAITING_INIT, FATAL_ERROR, WAITING_ACCOUNT_SELECT, WAITING_STARTUP, RUNNING_OK, RUNNING_OK_NO_FULL_CONTROL};
// ApiServer will be called once RS is started, to load additional api modules
// full_control: set to true if this module should handle rsinit and login
// set to false if rsinit is handled by the Qt gui
@ -32,6 +34,9 @@ public:
// returns true if the process should terminate
bool processShouldExit();
// returns the current state of the software booting process
RunState runState() const { return mRunState ; }
// from NotifyClient
virtual bool askForPassword(const std::string &title, const std::string& key_details, bool prev_is_bad , std::string& password,bool& canceled) override;
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason = "") override;
@ -42,7 +47,6 @@ protected:
virtual void run();
private:
enum RunState { WAITING_INIT, FATAL_ERROR, WAITING_ACCOUNT_SELECT, WAITING_STARTUP, RUNNING_OK, RUNNING_OK_NO_FULL_CONTROL};
void handleRunState(Request& req, Response& resp);
void handleIdentities(Request& req, Response& resp);
void handleLocations(Request& req, Response& resp);