diff options
author | Tess Chu <tess@lindenlab.com> | 2007-11-20 02:53:43 +0000 |
---|---|---|
committer | Tess Chu <tess@lindenlab.com> | 2007-11-20 02:53:43 +0000 |
commit | 2f6c7606241acdf800a2c079b359e7a1db360954 (patch) | |
tree | adb6e6e34f9c3df1e2252b2f763ae20970c0e2d4 /indra/newview/llpanellogin.cpp | |
parent | 813b140d0767146b17acf4ad2fb96fbd5a347c34 (diff) |
svn merge -r 73926:74098 svn+ssh://svn/svn/linden/branches/viewer-auth-7
Diffstat (limited to 'indra/newview/llpanellogin.cpp')
-rw-r--r-- | indra/newview/llpanellogin.cpp | 622 |
1 files changed, 241 insertions, 381 deletions
diff --git a/indra/newview/llpanellogin.cpp b/indra/newview/llpanellogin.cpp index fe07175529..8ebdb14e15 100644 --- a/indra/newview/llpanellogin.cpp +++ b/indra/newview/llpanellogin.cpp @@ -44,13 +44,16 @@ #include "llbutton.h" #include "llcheckboxctrl.h" +#include "llcommandhandler.h" #include "llcombobox.h" +#include "llcurl.h" #include "llviewercontrol.h" #include "llfloaterabout.h" #include "llfloatertest.h" #include "llfloaterpreference.h" #include "llfocusmgr.h" #include "lllineeditor.h" +#include "llstartup.h" #include "lltextbox.h" #include "llui.h" #include "lluiconstants.h" @@ -74,11 +77,145 @@ #include "llglheaders.h" +LLString load_password_from_disk(void); +void save_password_to_disk(const char* hashed_password); + const S32 BLACK_BORDER_HEIGHT = 160; const S32 MAX_PASSWORD = 16; LLPanelLogin *LLPanelLogin::sInstance = NULL; -BOOL LLPanelLogin::sCapslockDidNotification = FALSE; + + +//parses the input url and returns true if afterwards +//a web-login-key, firstname and lastname is set +bool LLLoginHandler::parseDirectLogin(std::string url) +{ + LLURI uri(url); + parse(uri.queryMap()); + + if (mWebLoginKey.isNull() || + mFirstName.empty() || + mLastName.empty()) + { + return false; + } + else + { + return true; + } +} + + +void LLLoginHandler::parse(const LLSD& queryMap) +{ + mWebLoginKey = queryMap["web_login_key"].asUUID(); + mFirstName = queryMap["first_name"].asString(); + mLastName = queryMap["last_name"].asString(); + + if (queryMap["grid"].asString() == "aditi") + { + gGridChoice = GRID_INFO_ADITI; + } + else if (queryMap["grid"].asString() == "agni") + { + gGridChoice = GRID_INFO_AGNI; + } + else if (queryMap["grid"].asString() == "siva") + { + gGridChoice = GRID_INFO_SIVA; + } + else if (queryMap["grid"].asString() == "durga") + { + gGridChoice = GRID_INFO_DURGA; + } + else if (queryMap["grid"].asString() == "shakti") + { + gGridChoice = GRID_INFO_SHAKTI; + } + else if (queryMap["grid"].asString() == "soma") + { + gGridChoice = GRID_INFO_SOMA; + } + else if (queryMap["grid"].asString() == "ganga") + { + gGridChoice = GRID_INFO_GANGA; + } + else if (queryMap["grid"].asString() == "vaak") + { + gGridChoice = GRID_INFO_VAAK; + } + else if (queryMap["grid"].asString() == "uma") + { + gGridChoice = GRID_INFO_UMA; + } + + snprintf(gGridName, MAX_STRING, "%s", gGridInfo[gGridChoice].mName); /* Flawfinder: ignore */ + LLAppViewer::instance()->resetURIs(); + + LLString startLocation = queryMap["location"].asString(); + + if (startLocation == "specify") + { + LLURLSimString::setString(queryMap["region"].asString()); + } + else if (startLocation == "home") + { + gSavedSettings.setBOOL("LoginLastLocation", FALSE); + LLURLSimString::setString(""); + } + else if (startLocation == "last") + { + gSavedSettings.setBOOL("LoginLastLocation", TRUE); + LLURLSimString::setString(""); + } +} + +bool LLLoginHandler::handle(const LLSD& tokens, + const LLSD& queryMap) +{ + parse(queryMap); + + //if we haven't initialized stuff yet, this is + //coming in from the GURL handler, just parse + if (STATE_FIRST == LLStartUp::getStartupState()) + { + return true; + } + + LLString password = queryMap["password"].asString(); + + if (!password.empty()) + { + gSavedSettings.setBOOL("RememberPassword", TRUE); + + if (password.substr(0,3) != "$1$") + { + LLMD5 pass((unsigned char*)password.c_str()); + char md5pass[33]; /* Flawfinder: ignore */ + pass.hex_digest(md5pass); + password = md5pass; + save_password_to_disk(password.c_str()); + } + } + else + { + save_password_to_disk(NULL); + gSavedSettings.setBOOL("RememberPassword", FALSE); + } + + + if (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP) //on splash page + { + if (mWebLoginKey.isNull()) { + LLPanelLogin::loadLoginPage(); + } else { + LLStartUp::setStartupState( STATE_LOGIN_CLEANUP ); + } + } + return true; +} + +LLLoginHandler gLoginHandler; // helper class that trys to download a URL from a web site and calls a method // on parent class indicating if the web server is working or not @@ -157,92 +294,11 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect, mLogoImage = gImageList.getImage("startup_logo.tga", LLUUID::null, MIPMAP_FALSE, TRUE); gUICtrlFactory->buildPanel(this, "panel_login.xml"); - //setRect(rect); + + //leave room for the login menu bar + setRect(LLRect(0, rect.getHeight()-18, rect.getWidth(), 0)); reshape(rect.getWidth(), rect.getHeight()); - - childSetPrevalidate("first_name_edit", LLLineEditor::prevalidatePrintableNoSpace); - childSetPrevalidate("last_name_edit", LLLineEditor::prevalidatePrintableNoSpace); - - childSetCommitCallback("password_edit", mungePassword); - childSetKeystrokeCallback("password_edit", onPassKey, this); - childSetUserData("password_edit", this); - - LLLineEditor* edit = LLUICtrlFactory::getLineEditorByName(this, "password_edit"); - if (edit) edit->setDrawAsterixes(TRUE); - - LLComboBox* combo = LLUICtrlFactory::getComboBoxByName(this, "start_location_combo"); - if (combo) - { - combo->setAllowTextEntry(TRUE, 128, FALSE); - - // The XML file loads the combo with the following labels: - // 0 - "My Home" - // 1 - "My Last Location" - // 2 - "<Type region name>" - - BOOL login_last = gSavedSettings.getBOOL("LoginLastLocation"); - LLString sim_string = LLURLSimString::sInstance.mSimString; - if (!sim_string.empty()) - { - // Replace "<Type region name>" with this region name - combo->remove(2); - combo->add( sim_string ); - combo->setTextEntry(sim_string); - combo->setCurrentByIndex( 2 ); - } - else if (login_last) - { - combo->setCurrentByIndex( 1 ); - } - else - { - combo->setCurrentByIndex( 0 ); - } - - combo->setCommitCallback( &LLPanelGeneral::set_start_location ); - } - // Specific servers added later. - childSetVisible("server_combo", show_server); - - childSetAction("new_account_btn", onClickNewAccount, this); - childSetVisible("new_account_btn", !gHideLinks); - - childSetAction("connect_btn", onClickConnect, this); - - setDefaultBtn("connect_btn"); - - childSetAction("preferences_btn", LLFloaterPreference::show, this); - - childSetAction("quit_btn", onClickQuit, this); - - LLTextBox* version_text = LLUICtrlFactory::getTextBoxByName(this, "version_text"); - if (version_text) - { - LLString version = llformat("%d.%d.%d (%d)", - LL_VERSION_MAJOR, - LL_VERSION_MINOR, - LL_VERSION_PATCH, - LL_VIEWER_BUILD ); - version_text->setText(version); - version_text->setClickedCallback(onClickVersion); - version_text->setCallbackUserData(this); - } - - LLTextBox* channel_text = LLUICtrlFactory::getTextBoxByName(this, "channel_text"); - if (channel_text) - { - channel_text->setText(gChannelName); - channel_text->setClickedCallback(onClickVersion); - channel_text->setCallbackUserData(this); - } - - LLTextBox* forgot_password_text = LLUICtrlFactory::getTextBoxByName(this, "forgot_password_text"); - if (forgot_password_text) - { - forgot_password_text->setClickedCallback(onClickForgotPassword); - } - // get the web browser control #if LL_LIBXUL_ENABLED LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(this, "login_html"); @@ -266,11 +322,11 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect, // force the size to be correct (XML doesn't seem to be sufficient to do this) (with some padding so the other login screen doesn't show through) LLRect htmlRect = mRect; - htmlRect.setCenterAndSize( mRect.getCenterX() - 2, mRect.getCenterY() + 40, mRect.getWidth() + 6, mRect.getHeight() - 78 ); + htmlRect.setCenterAndSize( mRect.getCenterX() - 2, mRect.getCenterY(), mRect.getWidth() + 6, mRect.getHeight()); web_browser->setRect( htmlRect ); web_browser->reshape( htmlRect.getWidth(), htmlRect.getHeight(), TRUE ); - reshape( mRect.getWidth(), mRect.getHeight(), 1 ); - + reshape( mRect.getWidth(), mRect.getHeight(), 1 ); + // kick off a request to grab the url manually gResponsePtr = LLIamHereLogin::build( this ); LLHTTPClient::get( childGetValue( "real_url" ).asString(), gResponsePtr ); @@ -280,7 +336,6 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect, #endif // Initialize visibility (and don't force visibility - use prefs) - refreshLocation( false ); } void LLPanelLogin::setSiteIsAlive( bool alive ) @@ -292,9 +347,8 @@ void LLPanelLogin::setSiteIsAlive( bool alive ) { if ( web_browser ) { - // navigate to the "real" page - web_browser->navigateTo( childGetValue( "real_url" ).asString() ); - + loadLoginPage(); + // mark as available mHtmlAvailable = TRUE; }; @@ -316,21 +370,6 @@ void LLPanelLogin::setSiteIsAlive( bool alive ) #endif } -void LLPanelLogin::mungePassword(LLUICtrl* caller, void* user_data) -{ - LLPanelLogin* self = (LLPanelLogin*)user_data; - LLLineEditor* editor = (LLLineEditor*)caller; - std::string password = editor->getText(); - - // Re-md5 if we've changed at all - if (password != self->mIncomingPassword) - { - LLMD5 pass((unsigned char *)password.c_str()); - char munged_password[MD5HEX_STR_SIZE]; - pass.hex_digest(munged_password); - self->mMungedPassword = munged_password; - } -} LLPanelLogin::~LLPanelLogin() { @@ -366,13 +405,6 @@ void LLPanelLogin::draw() glTranslatef(-0.5f * (image_aspect / view_aspect - 1.f) * mRect.getWidth(), 0.f, 0.f); glScalef(image_aspect / view_aspect, 1.f, 1.f); } - // Don't maintain aspect ratio if screen wider than image. This results in the - // hand being partially cut off. JC - //else - //{ - // glTranslatef(0.f, -0.5f * (view_aspect / image_aspect - 1.f) * (F32)BLACK_BORDER_HEIGHT, 0.f); - // glScalef(1.f, view_aspect / image_aspect, 1.f); - //} S32 width = mRect.getWidth(); S32 height = mRect.getHeight(); @@ -381,9 +413,6 @@ void LLPanelLogin::draw() { // draw a background box in black gl_rect_2d( 0, height - 264, width, 264, LLColor4( 0.0f, 0.0f, 0.0f, 1.f ) ); - - // draw the bottom part of the background image - just the blue background to the native client UI - gl_draw_scaled_image(0, -264, width + 8, mLogoImage->getHeight(), mLogoImage); } else { @@ -451,54 +480,14 @@ BOOL LLPanelLogin::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) return LLPanel::handleKeyHere(key, mask, called_from_parent); } - -// virtual -void LLPanelLogin::setFocus(BOOL b) -{ - if(b != hasFocus()) - { - if(b) - { - LLPanelLogin::giveFocus(); - } - else - { - LLPanel::setFocus(b); - } - } -} + // static void LLPanelLogin::giveFocus() { - if( sInstance ) - { - // Grab focus and move cursor to first blank input field - std::string first = sInstance->childGetText("first_name_edit"); - std::string pass = sInstance->childGetText("password_edit"); - - BOOL have_first = !first.empty(); - BOOL have_pass = !pass.empty(); - - LLLineEditor* edit = NULL; - if (have_first && !have_pass) - { - // User saved his name but not his password. Move - // focus to password field. - edit = LLUICtrlFactory::getLineEditorByName(sInstance, "password_edit"); - } - else - { - // User doesn't have a name, so start there. - edit = LLUICtrlFactory::getLineEditorByName(sInstance, "first_name_edit"); - } - if (edit) - { - edit->setFocus(TRUE); - edit->selectAll(); - } - } + if (sInstance) + sInstance->setFocus(TRUE); } @@ -510,266 +499,156 @@ void LLPanelLogin::show(const LLRect &rect, { new LLPanelLogin(rect, show_server, callback, callback_data); + LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(sInstance, "login_html"); + + if (!web_browser) return; + if( !gFocusMgr.getKeyboardFocus() ) { // Grab focus and move cursor to first enabled control - sInstance->setFocus(TRUE); + web_browser->setFocus(TRUE); } // Make sure that focus always goes here (and use the latest sInstance that was just created) - gFocusMgr.setDefaultKeyboardFocus(sInstance); + gFocusMgr.setDefaultKeyboardFocus(web_browser); } + // static -void LLPanelLogin::setFields(const std::string& firstname, const std::string& lastname, const std::string& password, - BOOL remember) +void LLPanelLogin::close() { - if (!sInstance) + if (sInstance) { - llwarns << "Attempted fillFields with no login view shown" << llendl; - return; - } - - sInstance->childSetText("first_name_edit", firstname); - sInstance->childSetText("last_name_edit", lastname); + gViewerWindow->getRootView()->removeChild( LLPanelLogin::sInstance ); + + gFocusMgr.setDefaultKeyboardFocus(NULL); - // Max "actual" password length is 16 characters. - // Hex digests are always 32 characters. - if (password.length() == 32) - { - // This is a MD5 hex digest of a password. - // We don't actually use the password input field, - // fill it with MAX_PASSWORD characters so we get a - // nice row of asterixes. - const std::string filler("123456789!123456"); - sInstance->childSetText("password_edit", filler); - sInstance->mIncomingPassword = filler; - sInstance->mMungedPassword = password; - } - else - { - // this is a normal text password - sInstance->childSetText("password_edit", password); - sInstance->mIncomingPassword = password; - LLMD5 pass((unsigned char *)password.c_str()); - char munged_password[MD5HEX_STR_SIZE]; - pass.hex_digest(munged_password); - sInstance->mMungedPassword = munged_password; + delete sInstance; + sInstance = NULL; } - - sInstance->childSetValue("remember_check", remember); } - // static -void LLPanelLogin::addServer(const char *server, S32 domain_name) +void LLPanelLogin::setAlwaysRefresh(bool refresh) { - if (!sInstance) - { - llwarns << "Attempted addServer with no login view shown" << llendl; - return; - } + if (LLStartUp::getStartupState() >= STATE_LOGIN_CLEANUP) return; - LLComboBox* combo = LLUICtrlFactory::getComboBoxByName(sInstance, "server_combo"); - if (combo) + LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(sInstance, "login_html"); + + if (web_browser) { - combo->add(server, LLSD(domain_name) ); - combo->setCurrentByIndex(0); + web_browser->setAlwaysRefresh(refresh); } } -// static -void LLPanelLogin::getFields(LLString &firstname, LLString &lastname, LLString &password, - BOOL &remember) -{ - if (!sInstance) - { - llwarns << "Attempted getFields with no login view shown" << llendl; - return; - } - firstname = sInstance->childGetText("first_name_edit"); - LLString::trim(firstname); - lastname = sInstance->childGetText("last_name_edit"); - LLString::trim(lastname); +void LLPanelLogin::loadLoginPage() +{ + if (!sInstance) return; - password = sInstance->mMungedPassword; - remember = sInstance->childGetValue("remember_check"); -} + LLURLSimString::sInstance.parse(); + LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(sInstance, "login_html"); -// static. Return TRUE if user made a choice from the popup -BOOL LLPanelLogin::getServer(LLString &server, S32 &domain_name) -{ - BOOL user_picked = FALSE; - if (!sInstance) + std::ostringstream oStr; + + LLString location; + LLString region; + LLString password; + + if (LLURLSimString::parse()) { - llwarns << "Attempted getServer with no login view shown" << llendl; + std::ostringstream oRegionStr; + location = "specify"; + oRegionStr << LLURLSimString::sInstance.mSimName << "/" << LLURLSimString::sInstance.mX << "/" + << LLURLSimString::sInstance.mY << "/" + << LLURLSimString::sInstance.mZ; + region = oRegionStr.str(); } else { - LLComboBox* combo = LLUICtrlFactory::getComboBoxByName(sInstance, "server_combo"); - if (combo) + if (gSavedSettings.getBOOL("LoginLastLocation")) { - LLSD combo_val = combo->getValue(); - if (LLSD::TypeInteger == combo_val.type()) - { - domain_name = combo->getValue().asInteger(); - - if ((S32)GRID_INFO_OTHER == domain_name) - { - server = gGridName; - } - } - else - { - // no valid selection, return other - domain_name = (S32)GRID_INFO_OTHER; - server = combo_val.asString(); - } - user_picked = combo->isDirty(); + location = "last"; + } + else + { + location = "home"; } } - - return user_picked; -} - -// static -void LLPanelLogin::getLocation(LLString &location) -{ - if (!sInstance) + + LLString firstname, lastname; + + if (gCmdLineFirstName.empty()) { - llwarns << "Attempted getLocation with no login view shown" << llendl; - return; + firstname = gSavedSettings.getString("FirstName"); } - - LLComboBox* combo = LLUICtrlFactory::getComboBoxByName(sInstance, "start_location_combo"); - if (combo) + else { - location = combo->getValue().asString(); + firstname = gCmdLineFirstName; } -} - -// static -void LLPanelLogin::refreshLocation( bool force_visible ) -{ - if (!sInstance) return; - - LLComboBox* combo = LLUICtrlFactory::getComboBoxByName(sInstance, "start_location_combo"); - if (!combo) return; - - LLString sim_string = LLURLSimString::sInstance.mSimString; - if (!sim_string.empty()) + + if (gCmdLineLastName.empty()) { - combo->setCurrentByIndex( 3 ); // BUG? Maybe 2? - combo->setTextEntry(sim_string); + lastname = gSavedSettings.getString("LastName"); } else { - BOOL login_last = gSavedSettings.getBOOL("LoginLastLocation"); - combo->setCurrentByIndex( login_last ? 1 : 0 ); + lastname = gCmdLineLastName; } + + LLString version = llformat("%d.%d.%d (%d)", + LL_VERSION_MAJOR, LL_VERSION_MINOR, LL_VERSION_PATCH, LL_VIEWER_BUILD); - BOOL show_start = TRUE; - - if ( ! force_visible ) - show_start = gSavedSettings.getBOOL("ShowStartLocation"); - - sInstance->childSetVisible("start_location_combo", show_start); - sInstance->childSetVisible("start_location_text", show_start); -} - -// static -void LLPanelLogin::close() -{ - if (sInstance) - { - gViewerWindow->getRootView()->removeChild( LLPanelLogin::sInstance ); - - gFocusMgr.setDefaultKeyboardFocus(NULL); - - delete sInstance; - sInstance = NULL; - } -} + char* curl_region = curl_escape(region.c_str(), 0); + char* curl_channel = curl_escape(gChannelName.c_str(), 0); + char* curl_version = curl_escape(version.c_str(), 0); + + oStr << sInstance->childGetValue( "real_url" ).asString() << "&firstname=" << firstname << + "&lastname=" << lastname << "&location=" << location << "®ion=" << curl_region << + "&grid=" << gGridInfo[gGridChoice].mLabel << "&channel=" << curl_channel << + "&version=" << curl_version; -//--------------------------------------------------------------------------- -// Protected methods -//--------------------------------------------------------------------------- + + curl_free(curl_region); + curl_free(curl_channel); + curl_free(curl_version); -// static -void LLPanelLogin::onClickConnect(void *) -{ - if (sInstance && sInstance->mCallback) + if (!gCmdLinePassword.empty()) { - // tell the responder we're not here anymore - if ( gResponsePtr ) - gResponsePtr->setParent( 0 ); - - // JC - Make sure the fields all get committed. - sInstance->setFocus(FALSE); - - LLString first = sInstance->childGetText("first_name_edit"); - LLString last = sInstance->childGetText("last_name_edit"); - if (!first.empty() && !last.empty()) - { - // has both first and last name typed - - // store off custom server entry, if currently selected - LLComboBox* combo = LLUICtrlFactory::getComboBoxByName(sInstance, "server_combo"); - if (combo) - { - S32 selected_server = combo->getValue(); - if (selected_server == GRID_INFO_NONE) - { - LLString custom_server = combo->getValue().asString(); - gSavedSettings.setString("CustomServer", custom_server); - } - } - sInstance->mCallback(0, sInstance->mCallbackData); - } - else - { - // empty first or last name - // same as clicking new account - onClickNewAccount(NULL); - } + oStr << "&password=" << gCmdLinePassword; } -} - - -// static -void LLPanelLogin::newAccountAlertCallback(S32 option, void*) -{ - if (0 == option) + else if (!(password = load_password_from_disk()).empty()) { - llinfos << "Going to account creation URL" << llendl; - LLWeb::loadURL( CREATE_ACCOUNT_URL ); + oStr << "&password=$1$" << password; } - else + if (gAutoLogin) { - sInstance->setFocus(TRUE); + oStr << "&auto_login=TRUE"; } -} - - -// static -void LLPanelLogin::onClickNewAccount(void*) -{ - if (gHideLinks) + if (gSavedSettings.getBOOL("ShowStartLocation")) { - gViewerWindow->alertXml("MustHaveAccountToLogInNoLinks"); - } - else + oStr << "&show_start_location=TRUE"; + } + if (gSavedSettings.getBOOL("RememberPassword")) { - gViewerWindow->alertXml("MustHaveAccountToLogIn", - LLPanelLogin::newAccountAlertCallback); - } + oStr << "&remember_password=TRUE"; + } +#ifndef LL_RELEASE_FOR_DOWNLOAD + oStr << "&show_grid=TRUE"; +#endif + + // navigate to the "real" page + web_browser->navigateTo( oStr.str() ); } +//--------------------------------------------------------------------------- +// Protected methods +//--------------------------------------------------------------------------- + // static void LLPanelLogin::onClickQuit(void*) { @@ -789,22 +668,3 @@ void LLPanelLogin::onClickVersion(void*) { LLFloaterAbout::show(NULL); } - -void LLPanelLogin::onClickForgotPassword(void*) -{ - if (sInstance ) - { - LLWeb::loadURL(sInstance->childGetValue( "forgot_password_url" ).asString()); - } -} - - -// static -void LLPanelLogin::onPassKey(LLLineEditor* caller, void* user_data) -{ - if (gKeyboard->getKeyDown(KEY_CAPSLOCK) && sCapslockDidNotification == FALSE) - { - LLNotifyBox::showXml("CapsKeyOn"); - sCapslockDidNotification = TRUE; - } -} |