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

View File

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