Fixed: Re-selecting accounts via RsControlModule;

Added: Sending feedback about incorrect password
This commit is contained in:
Konrad 2017-04-10 22:58:23 +02:00
parent 4067c95761
commit e1350a0b34
2 changed files with 29 additions and 10 deletions

View File

@ -24,7 +24,9 @@ RsControlModule::RsControlModule(int argc, char **argv, StateTokenServer* sts, A
mDataMtx("RsControlModule::mDataMtx"),
mRunState(WAITING_INIT),
mAutoLoginNextTime(false),
mWantPassword(false)
mWantPassword(false),
mPassword(""),
mPrevIsBad(false)
{
mStateToken = sts->getNewToken();
this->argc = argc;
@ -56,11 +58,14 @@ bool RsControlModule::processShouldExit()
return mProcessShouldExit;
}
bool RsControlModule::askForPassword(const std::string &title, const std::string &key_details, bool /* prev_is_bad */, std::string &password, bool& cancelled)
bool RsControlModule::askForPassword(const std::string &title, const std::string &key_details, bool prev_is_bad, std::string &password, bool& cancelled)
{
cancelled = false ;
{
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
mPrevIsBad = prev_is_bad;
if(mFixedPassword != "")
{
password = mFixedPassword;
@ -70,18 +75,25 @@ bool RsControlModule::askForPassword(const std::string &title, const std::string
mWantPassword = true;
mTitle = title;
mKeyName = key_details;
if(mPassword != "")
{
password = mPassword;
mWantPassword = false;
mPassword = "";
return true;
}
mStateTokenServer->replaceToken(mStateToken);
}
bool wait = true;
while(wait)
int i = 0;
while(i<100)
{
usleep(5*1000);
RS_STACK_MUTEX(mDataMtx); // ********** LOCKED **********
wait = mWantPassword;
if(!wait && mPassword != "")
if(mPassword != "")
{
password = mPassword;
mPassword = "";
@ -89,6 +101,7 @@ bool RsControlModule::askForPassword(const std::string &title, const std::string
mStateTokenServer->replaceToken(mStateToken);
return true;
}
i++;
}
return false;
}
@ -175,8 +188,13 @@ void RsControlModule::run()
std::cerr << "RsControlModule::run() LockAndLoadCertificates failed. Unexpected switch value: " << retVal << std::endl;
break;
}
mLoadPeerId.clear();
mPassword = "";
}
mFixedPassword = mPassword;
setRunState(WAITING_STARTUP);
std::cerr << "RsControlModule: login ok, starting Retroshare worker threads..." << std::endl;
@ -302,12 +320,12 @@ void RsControlModule::handlePassword(Request &req, Response &resp)
mPassword = passwd;
mWantPassword = false;
mStateTokenServer->replaceToken(mStateToken);
mFixedPassword = passwd;
}
resp.mDataStream
<< makeKeyValueReference("want_password", mWantPassword)
<< makeKeyValueReference("key_name", mKeyName);
<< makeKeyValueReference("key_name", mKeyName)
<< makeKeyValueReference("prev_is_bad", mPrevIsBad);
resp.mStateToken = mStateToken;
resp.setOk();
}

View File

@ -77,6 +77,7 @@ private:
// to notify that a password callback is waiting
// to answer the request, clear the flag and set the password
bool mWantPassword;
bool mPrevIsBad;
std::string mTitle;
std::string mKeyName;
std::string mPassword;