Better saved logins, with grid

Please, someone throw away the oodles of dead, confusing and redundant code -.-
This commit is contained in:
Siana Gearz
2011-06-15 15:14:55 +02:00
parent 9d57163479
commit c82cf613a6
4 changed files with 56 additions and 24 deletions

View File

@@ -126,6 +126,17 @@ static std::string nameJoin(const std::string& first,const std::string& last) {
} }
} }
static std::string getDisplayString(const std::string& first, const std::string& last, const std::string& grid) {
if(grid == gHippoGridManager->getDefaultGridNick())
return nameJoin(first, last);
else
return nameJoin(first, last) + " (" + grid + ")";
}
static std::string getDisplayString(const LLSavedLoginEntry& entry) {
return getDisplayString(entry.getFirstName(), entry.getLastName(), entry.getGrid());
}
class LLLoginRefreshHandler : public LLCommandHandler class LLLoginRefreshHandler : public LLCommandHandler
{ {
public: public:
@@ -477,8 +488,8 @@ void LLPanelLogin::setLoginHistory(LLSavedLogins const& login_history)
i != saved_login_entries.rend(); ++i) i != saved_login_entries.rend(); ++i)
{ {
LLSD e = i->asLLSD(); LLSD e = i->asLLSD();
if (e.isMap()) if (e.isMap() && gHippoGridManager->getGrid(i->getGrid()))
login_combo->add(nameJoin(i->getFirstName(), i->getLastName()), e); login_combo->add(getDisplayString(*i), e);
} }
} }
@@ -701,6 +712,12 @@ void LLPanelLogin::setFields(const LLSavedLoginEntry& entry, bool takeFocus)
LLComboBox* login_combo = sInstance->getChild<LLComboBox>("name_combo"); LLComboBox* login_combo = sInstance->getChild<LLComboBox>("name_combo");
login_combo->setLabel(fullname); login_combo->setLabel(fullname);
sInstance->childSetText("name_combo", fullname); sInstance->childSetText("name_combo", fullname);
std::string grid = entry.getGrid();
if(!grid.empty() && gHippoGridManager->getGrid(grid)) {
gHippoGridManager->setCurrentGrid(grid);
LLPanelLogin::refreshLoginPage();
}
if (entry.getPassword().empty()) if (entry.getPassword().empty())
{ {

View File

@@ -34,6 +34,7 @@
#include "llsavedlogins.h" #include "llsavedlogins.h"
#include "llxorcipher.h" #include "llxorcipher.h"
#include "llsdserialize.h" #include "llsdserialize.h"
#include "hippogridmanager.h"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// LLSavedLoginEntry methods // LLSavedLoginEntry methods
@@ -57,6 +58,10 @@ LLSavedLoginEntry::LLSavedLoginEntry(const LLSD& entry_data)
{ {
throw std::invalid_argument("Missing password key."); throw std::invalid_argument("Missing password key.");
} }
if (!entry_data.has("grid"))
{
throw std::invalid_argument("Missing grid key.");
}
if (!entry_data.get("firstname").isString()) if (!entry_data.get("firstname").isString())
{ {
throw std::invalid_argument("firstname key is not string."); throw std::invalid_argument("firstname key is not string.");
@@ -69,16 +74,22 @@ LLSavedLoginEntry::LLSavedLoginEntry(const LLSD& entry_data)
{ {
throw std::invalid_argument("password key is neither blank nor binary."); throw std::invalid_argument("password key is neither blank nor binary.");
} }
if (!entry_data.get("grid").isString())
{
throw std::invalid_argument("grid key is not string.");
}
mEntry = entry_data; mEntry = entry_data;
} }
LLSavedLoginEntry::LLSavedLoginEntry(const std::string& firstname, LLSavedLoginEntry::LLSavedLoginEntry(const std::string& firstname,
const std::string& lastname, const std::string& lastname,
const std::string& password) const std::string& password,
const std::string& grid)
{ {
mEntry.clear(); mEntry.clear();
mEntry.insert("firstname", LLSD(firstname)); mEntry.insert("firstname", LLSD(firstname));
mEntry.insert("lastname", LLSD(lastname)); mEntry.insert("lastname", LLSD(lastname));
mEntry.insert("grid", LLSD(grid));
setPassword(password); setPassword(password);
} }
@@ -87,13 +98,6 @@ LLSD LLSavedLoginEntry::asLLSD() const
return mEntry; return mEntry;
} }
const std::string LLSavedLoginEntry::getDisplayString() const
{
std::ostringstream etitle;
etitle << getFirstName() << " " << getLastName();
return etitle.str();
}
const std::string LLSavedLoginEntry::getPassword() const const std::string LLSavedLoginEntry::getPassword() const
{ {
return (mEntry.has("password") ? decryptPassword(mEntry.get("password")) : std::string()); return (mEntry.has("password") ? decryptPassword(mEntry.get("password")) : std::string());
@@ -177,13 +181,14 @@ void LLSavedLogins::addEntry(const LLSavedLoginEntry& entry)
} }
void LLSavedLogins::deleteEntry(const std::string& firstname, void LLSavedLogins::deleteEntry(const std::string& firstname,
const std::string& lastname) const std::string& lastname, const std::string& grid)
{ {
for (LLSavedLoginsList::iterator i = mEntries.begin(); for (LLSavedLoginsList::iterator i = mEntries.begin();
i != mEntries.end();) i != mEntries.end();)
{ {
if (i->getFirstName() == firstname && if (i->getFirstName() == firstname &&
i->getLastName() == lastname) i->getLastName() == lastname &&
i->getGrid() == grid)
{ {
i = mEntries.erase(i); i = mEntries.erase(i);
} }

View File

@@ -56,7 +56,9 @@ public:
* @param password Munged password of PASSWORD_HASH_LENGTH. * @param password Munged password of PASSWORD_HASH_LENGTH.
*/ */
LLSavedLoginEntry(const std::string& firstname, LLSavedLoginEntry(const std::string& firstname,
const std::string& lastname, const std::string& password); const std::string& lastname,
const std::string& password,
const std::string& grid);
/** /**
* @brief Returns the first name associated with this login entry. * @brief Returns the first name associated with this login entry.
* @return First name as string. * @return First name as string.
@@ -108,12 +110,18 @@ public:
* @brief Returns the login entry as an LLSD for serialization. * @brief Returns the login entry as an LLSD for serialization.
* *return LLSD containing login entry details. * *return LLSD containing login entry details.
*/ */
const std::string getGrid() const
{
return (mEntry.has("grid") ? mEntry.get("grid").asString() : std::string());
}
void setGrid(const std::string& value){
mEntry.insert("grid", LLSD(value));
}
LLSD asLLSD() const; LLSD asLLSD() const;
/**
* @brief Provides a string containing the username and grid for display.
* @return Formatted string with login details.
*/
const std::string getDisplayString() const;
static const size_t PASSWORD_HASH_LENGTH = 32; static const size_t PASSWORD_HASH_LENGTH = 32;
private: private:
static const std::string decryptPassword(const LLSD& pwdata); static const std::string decryptPassword(const LLSD& pwdata);
@@ -148,8 +156,9 @@ public:
* @brief Deletes a login history entry by looking up its name and grid. * @brief Deletes a login history entry by looking up its name and grid.
* @param firstname First name to find and delete. * @param firstname First name to find and delete.
* @param lastname Last name to find and delete. * @param lastname Last name to find and delete.
* @param grid grif nickname to find and delete.
*/ */
void deleteEntry(const std::string& firstname, const std::string& lastname); void deleteEntry(const std::string& firstname, const std::string& lastname, const std::string& grid);
/** /**
* @brief Access internal vector of login entries from the history. * @brief Access internal vector of login entries from the history.
* @return Const reference to internal login history storage. * @return Const reference to internal login history storage.

View File

@@ -846,7 +846,7 @@ bool idle_startup()
gViewerWindow->setShowProgress(FALSE); gViewerWindow->setShowProgress(FALSE);
// Load login history // Load login history
std::string login_hist_filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "saved_logins_sg1.xml"); std::string login_hist_filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "saved_logins_sg2.xml");
LLSavedLogins login_history = LLSavedLogins::loadFile(login_hist_filepath); LLSavedLogins login_history = LLSavedLogins::loadFile(login_hist_filepath);
// Show the login dialog. // Show the login dialog.
@@ -1547,7 +1547,7 @@ bool idle_startup()
text = LLUserAuth::getInstance()->getResponse("secure_session_id"); text = LLUserAuth::getInstance()->getResponse("secure_session_id");
if(!text.empty()) gAgent.mSecureSessionID.set(text); if(!text.empty()) gAgent.mSecureSessionID.set(text);
text = LLUserAuth::getInstance()->getResponse("first_name"); text = LLUserAuth::getInstance()->getResponse("firsst_name");
if(!text.empty()) if(!text.empty())
{ {
// Remove quotes from string. Login.cgi sends these to force // Remove quotes from string. Login.cgi sends these to force
@@ -1579,13 +1579,14 @@ bool idle_startup()
{ {
// Save the login history data to disk // Save the login history data to disk
std::string history_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "saved_logins_sg1.xml"); std::string history_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "saved_logins_sg2.xml");
LLSavedLogins history_data = LLSavedLogins::loadFile(history_file); LLSavedLogins history_data = LLSavedLogins::loadFile(history_file);
history_data.deleteEntry(firstname, lastname); std::string grid_nick = gHippoGridManager->getConnectedGrid()->getGridNick();
history_data.deleteEntry(firstname, lastname, grid_nick);
if (gSavedSettings.getBOOL("RememberLogin")) if (gSavedSettings.getBOOL("RememberLogin"))
{ {
LLSavedLoginEntry login_entry(firstname, lastname, password); LLSavedLoginEntry login_entry(firstname, lastname, password, grid_nick);
history_data.addEntry(login_entry); history_data.addEntry(login_entry);
} }
else else