summaryrefslogtreecommitdiff
path: root/indra/newview/llpanellogin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llpanellogin.cpp')
-rw-r--r--indra/newview/llpanellogin.cpp426
1 files changed, 342 insertions, 84 deletions
diff --git a/indra/newview/llpanellogin.cpp b/indra/newview/llpanellogin.cpp
index e253557797..d7c189271e 100644
--- a/indra/newview/llpanellogin.cpp
+++ b/indra/newview/llpanellogin.cpp
@@ -77,6 +77,60 @@ LLPanelLogin *LLPanelLogin::sInstance = NULL;
BOOL LLPanelLogin::sCapslockDidNotification = FALSE;
BOOL LLPanelLogin::sCredentialSet = FALSE;
+// Helper functions
+
+LLPointer<LLCredential> load_user_credentials(std::string &user_key)
+{
+ if (gSecAPIHandler->hasCredentialMap("login_list", LLGridManager::getInstance()->getGrid()))
+ {
+ // user_key should be of "name Resident" format
+ return gSecAPIHandler->loadFromCredentialMap("login_list", LLGridManager::getInstance()->getGrid(), user_key);
+ }
+ else
+ {
+ // legacy (or legacy^2, since it also tries to load from settings)
+ return gSecAPIHandler->loadCredential(LLGridManager::getInstance()->getGrid());
+ }
+}
+
+// keys are lower case to be case insensitive so they are not always
+// identical to names which retain user input, like:
+// "AwEsOmE Resident" -> "awesome_resident"
+std::string get_user_key_from_name(const std::string &username)
+{
+ std::string key = username;
+ LLStringUtil::trim(key);
+ LLStringUtil::toLower(key);
+ if (!LLGridManager::getInstance()->isSystemGrid())
+ {
+ size_t separator_index = username.find_first_of(" ");
+ if (separator_index == username.npos)
+ {
+ // CRED_IDENTIFIER_TYPE_ACCOUNT
+ return key;
+ }
+ }
+ // CRED_IDENTIFIER_TYPE_AGENT
+ size_t separator_index = username.find_first_of(" ._");
+ std::string first = username.substr(0, separator_index);
+ std::string last;
+ if (separator_index != username.npos)
+ {
+ last = username.substr(separator_index + 1, username.npos);
+ LLStringUtil::trim(last);
+ }
+ else
+ {
+ // ...on Linden grids, single username users as considered to have
+ // last name "Resident"
+ // *TODO: Make login.cgi support "account_name" like above
+ last = "resident";
+ }
+
+ key = first + "_" + last;
+ return key;
+}
+
class LLLoginLocationAutoHandler : public LLCommandHandler
{
public:
@@ -168,6 +222,7 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect,
mCallback(callback),
mCallbackData(cb_data),
mListener(new LLPanelLoginListener(this)),
+ mFirstLoginThisInstall(gSavedSettings.getBOOL("FirstLoginThisInstall")),
mUsernameLength(0),
mPasswordLength(0),
mLocationLength(0),
@@ -186,7 +241,7 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect,
login_holder->addChild(this);
}
- if (gSavedSettings.getBOOL("FirstLoginThisInstall"))
+ if (mFirstLoginThisInstall)
{
buildFromFile( "panel_login_first.xml");
}
@@ -206,35 +261,39 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect,
sendChildToBack(getChildView("forgot_password_text"));
sendChildToBack(getChildView("sign_up_text"));
- LLComboBox* favorites_combo = getChild<LLComboBox>("start_location_combo");
- updateLocationSelectorsVisibility(); // separate so that it can be called from preferences
- favorites_combo->setReturnCallback(boost::bind(&LLPanelLogin::onClickConnect, this));
- favorites_combo->setFocusLostCallback(boost::bind(&LLPanelLogin::onLocationSLURL, this));
-
- LLComboBox* server_choice_combo = getChild<LLComboBox>("server_combo");
- server_choice_combo->setCommitCallback(boost::bind(&LLPanelLogin::onSelectServer, this));
-
- // Load all of the grids, sorted, and then add a bar and the current grid at the top
- server_choice_combo->removeall();
-
- std::string current_grid = LLGridManager::getInstance()->getGrid();
- std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();
- for (std::map<std::string, std::string>::iterator grid_choice = known_grids.begin();
- grid_choice != known_grids.end();
- grid_choice++)
- {
- if (!grid_choice->first.empty() && current_grid != grid_choice->first)
- {
- LL_DEBUGS("AppInit")<<"adding "<<grid_choice->first<<LL_ENDL;
- server_choice_combo->add(grid_choice->second, grid_choice->first);
- }
- }
- server_choice_combo->sortByName();
- LL_DEBUGS("AppInit")<<"adding current "<<current_grid<<LL_ENDL;
- server_choice_combo->add(LLGridManager::getInstance()->getGridLabel(),
- current_grid,
- ADD_TOP);
- server_choice_combo->selectFirstItem();
+ std::string current_grid = LLGridManager::getInstance()->getGrid();
+ if (!mFirstLoginThisInstall)
+ {
+ LLComboBox* favorites_combo = getChild<LLComboBox>("start_location_combo");
+ updateLocationSelectorsVisibility(); // separate so that it can be called from preferences
+ favorites_combo->setReturnCallback(boost::bind(&LLPanelLogin::onClickConnect, this));
+ favorites_combo->setFocusLostCallback(boost::bind(&LLPanelLogin::onLocationSLURL, this));
+
+ LLComboBox* server_choice_combo = getChild<LLComboBox>("server_combo");
+ server_choice_combo->setCommitCallback(boost::bind(&LLPanelLogin::onSelectServer, this));
+
+ // Load all of the grids, sorted, and then add a bar and the current grid at the top
+ server_choice_combo->removeall();
+
+ std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();
+ for (std::map<std::string, std::string>::iterator grid_choice = known_grids.begin();
+ grid_choice != known_grids.end();
+ grid_choice++)
+ {
+ if (!grid_choice->first.empty() && current_grid != grid_choice->first)
+ {
+ LL_DEBUGS("AppInit") << "adding " << grid_choice->first << LL_ENDL;
+ server_choice_combo->add(grid_choice->second, grid_choice->first);
+ }
+ }
+ server_choice_combo->sortByName();
+
+ LL_DEBUGS("AppInit") << "adding current " << current_grid << LL_ENDL;
+ server_choice_combo->add(LLGridManager::getInstance()->getGridLabel(),
+ current_grid,
+ ADD_TOP);
+ server_choice_combo->selectFirstItem();
+ }
LLSLURL start_slurl(LLStartUp::getStartSLURL());
// The StartSLURL might have been set either by an explicit command-line
@@ -297,14 +356,30 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect,
loadLoginPage();
LLComboBox* username_combo(getChild<LLComboBox>("username_combo"));
- username_combo->setTextChangedCallback(boost::bind(&LLPanelLogin::addFavoritesToStartLocation, this));
+ username_combo->setTextChangedCallback(boost::bind(&LLPanelLogin::onUserNameTextEnty, this));
// STEAM-14: When user presses Enter with this field in focus, initiate login
- username_combo->setCommitCallback(boost::bind(&LLPanelLogin::onClickConnect, this));
+ username_combo->setCommitCallback(boost::bind(&LLPanelLogin::onUserListCommit, this));
+ username_combo->setReturnCallback(boost::bind(&LLPanelLogin::onClickConnect, this));
username_combo->setKeystrokeOnEsc(TRUE);
+
+ if (!mFirstLoginThisInstall)
+ {
+ LLCheckBoxCtrl* remember_name = getChild<LLCheckBoxCtrl>("remember_name");
+ remember_name->setCommitCallback(boost::bind(&LLPanelLogin::onRememberUserCheck, this));
+ }
}
void LLPanelLogin::addFavoritesToStartLocation()
{
+ if (mFirstLoginThisInstall)
+ {
+ // first login panel has no favorites, just update name length and buttons
+ std::string user_defined_name = getChild<LLComboBox>("username_combo")->getSimple();
+ mUsernameLength = user_defined_name.length();
+ updateLoginButtons();
+ return;
+ }
+
// Clear the combo.
LLComboBox* combo = getChild<LLComboBox>("start_location_combo");
if (!combo) return;
@@ -316,14 +391,14 @@ void LLPanelLogin::addFavoritesToStartLocation()
// Load favorites into the combo.
std::string user_defined_name = getChild<LLComboBox>("username_combo")->getSimple();
+ LLStringUtil::trim(user_defined_name);
LLStringUtil::toLower(user_defined_name);
- std::replace(user_defined_name.begin(), user_defined_name.end(), '.', ' ');
std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "stored_favorites_" + LLGridManager::getInstance()->getGrid() + ".xml");
std::string old_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "stored_favorites.xml");
mUsernameLength = user_defined_name.length();
updateLoginButtons();
- std::string::size_type index = user_defined_name.find(' ');
+ std::string::size_type index = user_defined_name.find_first_of(" ._");
if (index != std::string::npos)
{
std::string username = user_defined_name.substr(0, index);
@@ -332,6 +407,10 @@ void LLPanelLogin::addFavoritesToStartLocation()
{
user_defined_name = username;
}
+ else
+ {
+ user_defined_name = username + " " + lastname;
+ }
}
LLSD fav_llsd;
@@ -443,24 +522,6 @@ void LLPanelLogin::giveFocus()
}
// static
-void LLPanelLogin::showLoginWidgets()
-{
- if (sInstance)
- {
- // *NOTE: Mani - This may or may not be obselete code.
- // It seems to be part of the defunct? reg-in-client project.
- sInstance->getChildView("login_widgets")->setVisible( true);
- LLMediaCtrl* web_browser = sInstance->getChild<LLMediaCtrl>("login_html");
-
- // *TODO: Append all the usual login parameters, like first_login=Y etc.
- std::string splash_screen_url = LLGridManager::getInstance()->getLoginPage();
- web_browser->navigateTo( splash_screen_url, "text/html" );
- LLUICtrl* username_combo = sInstance->getChild<LLUICtrl>("username_combo");
- username_combo->setFocus(TRUE);
- }
-}
-
-// static
void LLPanelLogin::show(const LLRect &rect,
void (*callback)(S32 option, void* user_data),
void* callback_data)
@@ -480,9 +541,55 @@ void LLPanelLogin::show(const LLRect &rect,
gFocusMgr.setDefaultKeyboardFocus(sInstance);
}
+//static
+void LLPanelLogin::populateFields(LLPointer<LLCredential> credential, bool remember_user, bool remember_psswrd)
+{
+ if (!sInstance)
+ {
+ LL_WARNS() << "Attempted fillFields with no login view shown" << LL_ENDL;
+ return;
+ }
+ LLUICtrl* remember_check = sInstance->getChild<LLUICtrl>("remember_check");
+ remember_check->setValue(remember_psswrd);
+ if (sInstance->mFirstLoginThisInstall)
+ {
+ // no list to populate
+ setFields(credential, remember_psswrd);
+ }
+ else
+ {
+ sInstance->getChild<LLUICtrl>("remember_name")->setValue(remember_user);
+ sInstance->populateUserList(credential, remember_psswrd);
+ remember_check->setEnabled(remember_user);
+ }
+}
+
+//static
+void LLPanelLogin::resetFields()
+{
+ if (!sInstance)
+ {
+ // class not existing at this point might happen since this
+ // function is used to reset list in case of changes by external sources
+ return;
+ }
+ if (sInstance->mFirstLoginThisInstall)
+ {
+ // no list to populate
+ LL_WARNS() << "Shouldn't happen, user should have no ability to modify list on first install" << LL_ENDL;
+ }
+ else
+ {
+ LLUICtrl* remember_check = sInstance->getChild<LLUICtrl>("remember_check");
+ bool remember_psswrd = remember_check->getValue();
+ LLPointer<LLCredential> cred = gSecAPIHandler->loadCredential(LLGridManager::getInstance()->getGrid());
+ sInstance->populateUserList(cred, remember_psswrd);
+ }
+}
+
// static
void LLPanelLogin::setFields(LLPointer<LLCredential> credential,
- BOOL remember)
+ bool remember_psswrd)
{
if (!sInstance)
{
@@ -492,13 +599,15 @@ void LLPanelLogin::setFields(LLPointer<LLCredential> credential,
sCredentialSet = TRUE;
LL_INFOS("Credentials") << "Setting login fields to " << *credential << LL_ENDL;
- LLSD identifier = credential->getIdentifier();
- if((std::string)identifier["type"] == "agent")
+ LLSD identifier = credential.notNull() ? credential->getIdentifier() : LLSD();
+
+ if(identifier.has("type") && (std::string)identifier["type"] == "agent")
{
+ // not nessesary for panel_login.xml, needed for panel_login_first.xml
std::string firstname = identifier["first_name"].asString();
std::string lastname = identifier["last_name"].asString();
std::string login_id = firstname;
- if (!lastname.empty() && lastname != "Resident")
+ if (!lastname.empty() && lastname != "Resident" && lastname != "resident")
{
// support traditional First Last name SLURLs
login_id += " ";
@@ -506,22 +615,23 @@ void LLPanelLogin::setFields(LLPointer<LLCredential> credential,
}
sInstance->getChild<LLComboBox>("username_combo")->setLabel(login_id);
}
- else if((std::string)identifier["type"] == "account")
+ else if(identifier.has("type") && (std::string)identifier["type"] == "account")
{
sInstance->getChild<LLComboBox>("username_combo")->setLabel((std::string)identifier["account_name"]);
}
else
{
- sInstance->getChild<LLComboBox>("username_combo")->setLabel(std::string());
+ sInstance->getChild<LLComboBox>("username_combo")->setLabel(std::string());
}
+
sInstance->addFavoritesToStartLocation();
// if the password exists in the credential, set the password field with
// a filler to get some stars
- LLSD authenticator = credential->getAuthenticator();
+ LLSD authenticator = credential.notNull() ? credential->getAuthenticator() : LLSD();
LL_INFOS("Credentials") << "Setting authenticator field " << authenticator["type"].asString() << LL_ENDL;
if(authenticator.isMap() &&
authenticator.has("secret") &&
- (authenticator["secret"].asString().size() > 0) && remember)
+ (authenticator["secret"].asString().size() > 0) && remember_psswrd)
{
// This is a MD5 hex digest of a password.
@@ -537,36 +647,25 @@ void LLPanelLogin::setFields(LLPointer<LLCredential> credential,
{
sInstance->getChild<LLUICtrl>("password_edit")->setValue(std::string());
}
- sInstance->getChild<LLUICtrl>("remember_check")->setValue(remember);
}
-
// static
void LLPanelLogin::getFields(LLPointer<LLCredential>& credential,
- BOOL& remember)
+ bool& remember_user,
+ bool& remember_psswrd)
{
if (!sInstance)
{
LL_WARNS() << "Attempted getFields with no login view shown" << LL_ENDL;
return;
}
-
- // load the credential so we can pass back the stored password or hash if the user did
- // not modify the password field.
-
- credential = gSecAPIHandler->loadCredential(LLGridManager::getInstance()->getGrid());
LLSD identifier = LLSD::emptyMap();
LLSD authenticator = LLSD::emptyMap();
-
- if(credential.notNull())
- {
- authenticator = credential->getAuthenticator();
- }
- std::string username = sInstance->getChild<LLUICtrl>("username_combo")->getValue().asString();
- LLStringUtil::trim(username);
+ std::string username = sInstance->getChild<LLComboBox>("username_combo")->getValue().asString();
std::string password = sInstance->getChild<LLUICtrl>("password_edit")->getValue().asString();
+ LLStringUtil::trim(username);
LL_INFOS("Credentials", "Authentication") << "retrieving username:" << username << LL_ENDL;
// determine if the username is a first/last form or not.
@@ -586,6 +685,14 @@ void LLPanelLogin::getFields(LLPointer<LLCredential>& credential,
authenticator["type"] = CRED_AUTHENTICATOR_TYPE_CLEAR;
authenticator["secret"] = password;
}
+ else
+ {
+ credential = load_user_credentials(username);
+ if (credential.notNull())
+ {
+ authenticator = credential->getAuthenticator();
+ }
+ }
}
else
{
@@ -597,7 +704,7 @@ void LLPanelLogin::getFields(LLPointer<LLCredential>& credential,
if (separator_index != username.npos)
{
last = username.substr(separator_index+1, username.npos);
- LLStringUtil::trim(last);
+ LLStringUtil::trim(last);
}
else
{
@@ -625,10 +732,28 @@ void LLPanelLogin::getFields(LLPointer<LLCredential>& credential,
pass.hex_digest(md5pass);
authenticator["secret"] = md5pass;
}
+ else
+ {
+ std::string key = first + "_" + last;
+ LLStringUtil::toLower(key);
+ credential = load_user_credentials(key);
+ if (credential.notNull())
+ {
+ authenticator = credential->getAuthenticator();
+ }
+ }
}
}
credential = gSecAPIHandler->createCredential(LLGridManager::getInstance()->getGrid(), identifier, authenticator);
- remember = sInstance->getChild<LLUICtrl>("remember_check")->getValue();
+ remember_psswrd = sInstance->getChild<LLUICtrl>("remember_check")->getValue();
+ if (!sInstance->mFirstLoginThisInstall)
+ {
+ remember_user = sInstance->getChild<LLUICtrl>("remember_name")->getValue();
+ }
+ else
+ {
+ remember_user = true;
+ }
}
@@ -898,8 +1023,8 @@ void LLPanelLogin::onClickConnect(void *)
{
sCredentialSet = FALSE;
LLPointer<LLCredential> cred;
- BOOL remember;
- getFields(cred, remember);
+ bool remember_1, remember_2;
+ getFields(cred, remember_1, remember_2);
std::string identifier_type;
cred->identifierType(identifier_type);
LLSD allowed_credential_types;
@@ -953,6 +1078,57 @@ void LLPanelLogin::onClickSignUp(void*)
}
// static
+void LLPanelLogin::onUserNameTextEnty(void*)
+{
+ sInstance->mPasswordModified = true;
+ sInstance->getChild<LLUICtrl>("password_edit")->setValue(std::string());
+ sInstance->addFavoritesToStartLocation(); //will call updateLoginButtons()
+}
+
+// static
+void LLPanelLogin::onUserListCommit(void*)
+{
+ if (sInstance)
+ {
+ LLComboBox* username_combo(sInstance->getChild<LLComboBox>("username_combo"));
+ static S32 ind = -1;
+ if (ind != username_combo->getCurrentIndex())
+ {
+ std::string user_key = username_combo->getSelectedValue();
+ LLPointer<LLCredential> cred = gSecAPIHandler->loadFromCredentialMap("login_list", LLGridManager::getInstance()->getGrid(), user_key);
+ bool remember_psswrd = sInstance->getChild<LLUICtrl>("remember_check")->getValue();
+ setFields(cred, remember_psswrd);
+ sInstance->mPasswordModified = false;
+ }
+ else
+ {
+ std::string pass = sInstance->getChild<LLUICtrl>("password_edit")->getValue().asString();
+ if (pass.empty())
+ {
+ sInstance->giveFocus();
+ }
+ else
+ {
+ onClickConnect(NULL);
+ }
+ }
+ }
+}
+
+// static
+void LLPanelLogin::onRememberUserCheck(void*)
+{
+ if (sInstance)
+ {
+ LLCheckBoxCtrl* remember_name(sInstance->getChild<LLCheckBoxCtrl>("remember_name"));
+ LLCheckBoxCtrl* remember_psswrd(sInstance->getChild<LLCheckBoxCtrl>("remember_check"));
+
+ bool remember = remember_name->getValue().asBoolean();
+ remember_psswrd->setEnabled(remember);
+ }
+}
+
+// static
void LLPanelLogin::onPassKey(LLLineEditor* caller, void* user_data)
{
LLPanelLogin *self = (LLPanelLogin *)user_data;
@@ -979,9 +1155,11 @@ void LLPanelLogin::updateServer()
// for that grid and set them to the UI.
if(!sInstance->areCredentialFieldsDirty())
{
- LLPointer<LLCredential> credential = gSecAPIHandler->loadCredential(LLGridManager::getInstance()->getGrid());
- bool remember = sInstance->getChild<LLUICtrl>("remember_check")->getValue();
- sInstance->setFields(credential, remember);
+ // populate dropbox and setFields
+ bool remember_psswrd = sInstance->getChild<LLUICtrl>("remember_check")->getValue();
+ // Note: following call is related to initializeLoginInfo()
+ LLPointer<LLCredential> credential = gSecAPIHandler->loadCredential(LLGridManager::getInstance()->getGrid());
+ sInstance->populateUserList(credential, remember_psswrd);
}
// update the login panel links
@@ -1011,14 +1189,63 @@ void LLPanelLogin::updateLoginButtons()
LLButton* login_btn = getChild<LLButton>("connect_btn");
login_btn->setEnabled(mUsernameLength != 0 && mPasswordLength != 0);
+
+ if (!mFirstLoginThisInstall)
+ {
+ LLComboBox* user_combo = getChild<LLComboBox>("username_combo");
+ LLCheckBoxCtrl* remember_name = getChild<LLCheckBoxCtrl>("remember_name");
+ remember_name->setEnabled(user_combo->getCurrentIndex() == -1);
+ }
+}
+
+void LLPanelLogin::populateUserList(LLPointer<LLCredential> credential, bool remember_psswrd)
+{
+ LLComboBox* user_combo = getChild<LLComboBox>("username_combo");
+ user_combo->removeall();
+ user_combo->clear();
+
+ if (gSecAPIHandler->hasCredentialMap("login_list", LLGridManager::getInstance()->getGrid()))
+ {
+ LLSecAPIHandler::credential_map_t credencials;
+ gSecAPIHandler->loadCredentialMap("login_list", LLGridManager::getInstance()->getGrid(), credencials);
+
+ LLSecAPIHandler::credential_map_t::iterator cr_iter = credencials.begin();
+ LLSecAPIHandler::credential_map_t::iterator cr_end = credencials.end();
+ while (cr_iter != cr_end)
+ {
+ if (cr_iter->second.notNull()) // basic safety in case of future changes
+ {
+ // cr_iter->first == user_id , to be able to be find it in case we select it
+ user_combo->add(LLPanelLogin::getUserName(cr_iter->second), cr_iter->first, ADD_BOTTOM, TRUE);
+ }
+ cr_iter++;
+ }
+
+ if (credential.isNull() || !user_combo->setSelectedByValue(LLSD(credential->userID()), true))
+ {
+ // selection failed, just deselect whatever might be selected
+ user_combo->setValue(std::string());
+ }
+ else
+ {
+ setFields(credential, remember_psswrd);
+ }
+ }
+ else
+ {
+ if (credential.notNull())
+ {
+ user_combo->add(LLPanelLogin::getUserName(credential), credential->userID(), ADD_BOTTOM, TRUE);
+ setFields(credential, remember_psswrd);
+ }
+ }
}
+
void LLPanelLogin::onSelectServer()
{
// The user twiddled with the grid choice ui.
// apply the selection to the grid setting.
- LLPointer<LLCredential> credential;
-
LLComboBox* server_combo = getChild<LLComboBox>("server_combo");
LLSD server_combo_val = server_combo->getSelectedValue();
LL_INFOS("AppInit") << "grid "<<server_combo_val.asString()<< LL_ENDL;
@@ -1077,3 +1304,34 @@ bool LLPanelLogin::getShowFavorites()
{
return gSavedPerAccountSettings.getBOOL("ShowFavoritesOnLogin");
}
+
+// static
+std::string LLPanelLogin::getUserName(LLPointer<LLCredential> &cred)
+{
+ if (cred.isNull())
+ {
+ return "unknown";
+ }
+ const LLSD &ident = cred->getIdentifier();
+
+ if (!ident.isMap())
+ {
+ return "unknown";
+ }
+ else if ((std::string)ident["type"] == "agent")
+ {
+ std::string second_name = ident["last_name"];
+ if (second_name == "resident" || second_name == "Resident")
+ {
+ return (std::string)ident["first_name"];
+ }
+ return (std::string)ident["first_name"] + " " + (std::string)ident["last_name"];
+ }
+ else if ((std::string)ident["type"] == "account")
+ {
+ return LLCacheName::cleanFullName((std::string)ident["account_name"]);
+ }
+
+ return "unknown";
+}
+