llpanellogin.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llpanellogin.h"
00035 #include "llpanelgeneral.h"
00036 
00037 #include "indra_constants.h"            // for key and mask constants
00038 #include "llfontgl.h"
00039 #include "llmd5.h"
00040 #include "llsecondlifeurls.h"
00041 #include "llversionviewer.h"
00042 #include "v4color.h"
00043 
00044 #include "llbutton.h"
00045 #include "llcheckboxctrl.h"
00046 #include "llcommandhandler.h"
00047 #include "llcombobox.h"
00048 #include "llcurl.h"
00049 #include "llviewercontrol.h"
00050 #include "llfloaterabout.h"
00051 #include "llfloatertest.h"
00052 #include "llfloaterpreference.h"
00053 #include "llfocusmgr.h"
00054 #include "lllineeditor.h"
00055 #include "llstartup.h"
00056 #include "lltextbox.h"
00057 #include "llui.h"
00058 #include "lluiconstants.h"
00059 #include "llurlsimstring.h"
00060 #include "llviewerbuild.h"
00061 #include "llviewerimagelist.h"
00062 #include "llviewermenu.h"                       // for handle_preferences()
00063 #include "llviewernetwork.h"
00064 #include "llviewerwindow.h"                     // to link into child list
00065 #include "llnotify.h"
00066 #include "llappviewer.h"                                        // for gHideLinks
00067 #include "llurlsimstring.h"
00068 #include "lluictrlfactory.h"
00069 #include "llhttpclient.h"
00070 #include "llweb.h"
00071 #include "llwebbrowserctrl.h"
00072 
00073 #include "llfloaterhtml.h"
00074 
00075 #include "llfloaterhtmlhelp.h"
00076 #include "llfloatertos.h"
00077 
00078 #include "llglheaders.h"
00079 
00080 #define USE_VIEWER_AUTH 0
00081 
00082 LLString load_password_from_disk(void);
00083 void save_password_to_disk(const char* hashed_password);
00084 
00085 const S32 BLACK_BORDER_HEIGHT = 160;
00086 const S32 MAX_PASSWORD = 16;
00087 
00088 LLPanelLogin *LLPanelLogin::sInstance = NULL;
00089 BOOL LLPanelLogin::sCapslockDidNotification = FALSE;
00090 
00091 
00092 class LLLoginRefreshHandler : public LLCommandHandler
00093 {
00094 public:
00095         // don't allow from external browsers
00096         LLLoginRefreshHandler() : LLCommandHandler("login_refresh", false) { }
00097         bool handle(const LLSD& tokens, const LLSD& queryMap)
00098         {       
00099                 if (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP)
00100                 {
00101                         LLPanelLogin::loadLoginPage();
00102                 }       
00103                 return true;
00104         }
00105 };
00106 
00107 LLLoginRefreshHandler gLoginRefreshHandler;
00108 
00109 
00110 //parses the input url and returns true if afterwards
00111 //a web-login-key, firstname and lastname  is set
00112 bool LLLoginHandler::parseDirectLogin(std::string url)
00113 {
00114         LLURI uri(url);
00115         parse(uri.queryMap());
00116 
00117         if (mWebLoginKey.isNull() ||
00118                 mFirstName.empty() ||
00119                 mLastName.empty())
00120         {
00121                 return false;
00122         }
00123         else
00124         {
00125                 return true;
00126         }
00127 }
00128 
00129 
00130 void LLLoginHandler::parse(const LLSD& queryMap)
00131 {
00132         mWebLoginKey = queryMap["web_login_key"].asUUID();
00133         mFirstName = queryMap["first_name"].asString();
00134         mLastName = queryMap["last_name"].asString();
00135         
00136         if (queryMap["grid"].asString() == "aditi")
00137         {
00138                 gGridChoice = GRID_INFO_ADITI;
00139         }
00140         else if (queryMap["grid"].asString() == "agni")
00141         {
00142                 gGridChoice = GRID_INFO_AGNI;
00143         }
00144         else if (queryMap["grid"].asString() == "siva")
00145         {
00146                 gGridChoice = GRID_INFO_SIVA;
00147         }
00148         else if (queryMap["grid"].asString() == "durga")
00149         {
00150                 gGridChoice = GRID_INFO_DURGA;
00151         }
00152         else if (queryMap["grid"].asString() == "shakti")
00153         {
00154                 gGridChoice = GRID_INFO_SHAKTI;
00155         }
00156         else if (queryMap["grid"].asString() == "soma")
00157         {
00158                 gGridChoice = GRID_INFO_SOMA;
00159         }
00160         else if (queryMap["grid"].asString() == "ganga")
00161         {
00162                 gGridChoice = GRID_INFO_GANGA;
00163         }
00164         else if (queryMap["grid"].asString() == "vaak")
00165         {
00166                 gGridChoice = GRID_INFO_VAAK;
00167         }
00168         else if (queryMap["grid"].asString() == "uma")
00169         {
00170                 gGridChoice = GRID_INFO_UMA;
00171         }
00172         else if (queryMap["grid"].asString() == "mohini")
00173         {
00174                 gGridChoice = GRID_INFO_MOHINI;
00175         }
00176         else if (queryMap["grid"].asString() == "yami")
00177         {
00178                 gGridChoice = GRID_INFO_YAMI;
00179         }
00180         else if (queryMap["grid"].asString() == "nandi")
00181         {
00182                 gGridChoice = GRID_INFO_NANDI;
00183         }
00184         else if (queryMap["grid"].asString() == "mitra")
00185         {
00186                 gGridChoice = GRID_INFO_MITRA;
00187         }
00188         else if (queryMap["grid"].asString() == "radha")
00189         {
00190                 gGridChoice = GRID_INFO_RADHA;
00191         }
00192         else if (queryMap["grid"].asString() == "ravi")
00193         {
00194                 gGridChoice = GRID_INFO_RAVI;
00195         }
00196         else if (queryMap["grid"].asString() == "aruna")
00197         {
00198                 gGridChoice = GRID_INFO_ARUNA;
00199         }
00200 #if !LL_RELEASE_FOR_DOWNLOAD
00201         if (gGridChoice > GRID_INFO_NONE && gGridChoice < GRID_INFO_LOCAL)
00202         {
00203                 gSavedSettings.setS32("ServerChoice", gGridChoice);
00204         }
00205 #endif
00206         
00207         if (LLAppViewer::instance()->getLoginURIs().size() == 0)
00208         {
00209                 gGridName = gGridInfo[gGridChoice].mName;               /* Flawfinder: ignore */
00210             LLAppViewer::instance()->resetURIs();
00211         }           
00212         
00213         LLString startLocation = queryMap["location"].asString();
00214 
00215         if (startLocation == "specify")
00216         {
00217                 LLURLSimString::setString(queryMap["region"].asString());
00218         }
00219         else if (startLocation == "home")
00220         {
00221                 gSavedSettings.setBOOL("LoginLastLocation", FALSE);
00222                 LLURLSimString::setString("");
00223         }
00224         else if (startLocation == "last")
00225         {
00226                 gSavedSettings.setBOOL("LoginLastLocation", TRUE);
00227                 LLURLSimString::setString("");
00228         }
00229 }
00230 
00231 bool LLLoginHandler::handle(const LLSD& tokens,
00232                                                   const LLSD& queryMap)
00233 {       
00234         parse(queryMap);
00235         
00236         //if we haven't initialized stuff yet, this is 
00237         //coming in from the GURL handler, just parse
00238         if (STATE_FIRST == LLStartUp::getStartupState())
00239         {
00240                 return true;
00241         }
00242         
00243         LLString password = queryMap["password"].asString();
00244 
00245         if (!password.empty())
00246         {
00247                 gSavedSettings.setBOOL("RememberPassword", TRUE);
00248 
00249                 if (password.substr(0,3) != "$1$")
00250                 {
00251                         LLMD5 pass((unsigned char*)password.c_str());
00252                         char md5pass[33];               /* Flawfinder: ignore */
00253                         pass.hex_digest(md5pass);
00254                         password = md5pass;
00255                         save_password_to_disk(password.c_str());
00256                 }
00257         }
00258         else
00259         {
00260                 save_password_to_disk(NULL);
00261                 gSavedSettings.setBOOL("RememberPassword", FALSE);
00262         }
00263                         
00264 
00265         if  (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP)  //on splash page
00266         {
00267                 if (mWebLoginKey.isNull()) {
00268                         LLPanelLogin::loadLoginPage();
00269                 } else {
00270                         LLStartUp::setStartupState( STATE_LOGIN_CLEANUP );
00271                 }
00272         }
00273         return true;
00274 }
00275 
00276 LLLoginHandler gLoginHandler;
00277 
00278 // helper class that trys to download a URL from a web site and calls a method 
00279 // on parent class indicating if the web server is working or not
00280 class LLIamHereLogin : public LLHTTPClient::Responder
00281 {
00282         private:
00283                 LLIamHereLogin( LLPanelLogin* parent ) :
00284                    mParent( parent )
00285                 {}
00286 
00287                 LLPanelLogin* mParent;
00288 
00289         public:
00290                 static boost::intrusive_ptr< LLIamHereLogin > build( LLPanelLogin* parent )
00291                 {
00292                         return boost::intrusive_ptr< LLIamHereLogin >( new LLIamHereLogin( parent ) );
00293                 };
00294 
00295                 virtual void  setParent( LLPanelLogin* parentIn )
00296                 {
00297                         mParent = parentIn;
00298                 };
00299                 
00300                 virtual void result( const LLSD& content )
00301                 {
00302                         if ( mParent )
00303                                 mParent->setSiteIsAlive( true );
00304                 };
00305 
00306                 virtual void error( U32 status, const std::string& reason )
00307                 {
00308                         if ( mParent )
00309                                 mParent->setSiteIsAlive( false );
00310                 };
00311 };
00312 
00313 // this is global and not a class member to keep crud out of the header file
00314 namespace {
00315         boost::intrusive_ptr< LLIamHereLogin > gResponsePtr = 0;
00316 };
00317 
00318 //---------------------------------------------------------------------------
00319 // Public methods
00320 //---------------------------------------------------------------------------
00321 LLPanelLogin::LLPanelLogin(const LLRect &rect,
00322                                                  BOOL show_server,
00323                                                  void (*callback)(S32 option, void* user_data),
00324                                                  void *cb_data)
00325 :       LLPanel("panel_login", LLRect(0,600,800,0), FALSE),             // not bordered
00326         mLogoImage(),
00327         mCallback(callback),
00328         mCallbackData(cb_data),
00329         mHtmlAvailable( TRUE )
00330 {
00331         setFocusRoot(TRUE);
00332 
00333         setBackgroundVisible(FALSE);
00334         setBackgroundOpaque(TRUE);
00335 
00336         // instance management
00337         if (LLPanelLogin::sInstance)
00338         {
00339                 llwarns << "Duplicate instance of login view deleted" << llendl;
00340                 delete LLPanelLogin::sInstance;
00341 
00342                 // Don't leave bad pointer in gFocusMgr
00343                 gFocusMgr.setDefaultKeyboardFocus(NULL);
00344         }
00345 
00346         LLPanelLogin::sInstance = this;
00347 
00348         // add to front so we are the bottom-most child
00349         gViewerWindow->getRootView()->addChildAtEnd(this);
00350 
00351         // Logo
00352         mLogoImage = LLUI::getUIImage("startup_logo.j2c");
00353 
00354         LLUICtrlFactory::getInstance()->buildPanel(this, "panel_login.xml");
00355         
00356 #if USE_VIEWER_AUTH
00357         //leave room for the login menu bar
00358         setRect(LLRect(0, rect.getHeight()-18, rect.getWidth(), 0)); 
00359 #endif
00360         reshape(rect.getWidth(), rect.getHeight());
00361 
00362 #if !USE_VIEWER_AUTH
00363         childSetPrevalidate("first_name_edit", LLLineEditor::prevalidatePrintableNoSpace);
00364         childSetPrevalidate("last_name_edit", LLLineEditor::prevalidatePrintableNoSpace);
00365 
00366         childSetCommitCallback("password_edit", mungePassword);
00367         childSetKeystrokeCallback("password_edit", onPassKey, this);
00368         childSetUserData("password_edit", this);
00369 
00370         // change z sort of clickable text to be behind buttons
00371         sendChildToBack(getChildView("channel_text"));
00372         sendChildToBack(getChildView("version_text"));
00373         sendChildToBack(getChildView("forgot_password_text"));
00374 
00375         LLLineEditor* edit = getChild<LLLineEditor>("password_edit");
00376         if (edit) edit->setDrawAsterixes(TRUE);
00377 
00378         LLComboBox* combo = getChild<LLComboBox>("start_location_combo");
00379         combo->setAllowTextEntry(TRUE, 128, FALSE);
00380 
00381         // The XML file loads the combo with the following labels:
00382         // 0 - "My Home"
00383         // 1 - "My Last Location"
00384         // 2 - "<Type region name>"
00385 
00386         BOOL login_last = gSavedSettings.getBOOL("LoginLastLocation");
00387         LLString sim_string = LLURLSimString::sInstance.mSimString;
00388         if (!sim_string.empty())
00389         {
00390                 // Replace "<Type region name>" with this region name
00391                 combo->remove(2);
00392                 combo->add( sim_string );
00393                 combo->setTextEntry(sim_string);
00394                 combo->setCurrentByIndex( 2 );
00395         }
00396         else if (login_last)
00397         {
00398                 combo->setCurrentByIndex( 1 );
00399         }
00400         else
00401         {
00402                 combo->setCurrentByIndex( 0 );
00403         }
00404 
00405         combo->setCommitCallback( &LLPanelGeneral::set_start_location );
00406 
00407         childSetCommitCallback("server_combo", onSelectServer, this);
00408 
00409         childSetAction("connect_btn", onClickConnect, this);
00410 
00411         setDefaultBtn("connect_btn");
00412 
00413         childSetAction("quit_btn", onClickQuit, this);
00414 
00415         LLTextBox* version_text = getChild<LLTextBox>("version_text");
00416         LLString version = llformat("%d.%d.%d (%d)",
00417                 LL_VERSION_MAJOR,
00418                 LL_VERSION_MINOR,
00419                 LL_VERSION_PATCH,
00420                 LL_VIEWER_BUILD );
00421         version_text->setText(version);
00422         version_text->setClickedCallback(onClickVersion);
00423         version_text->setCallbackUserData(this);
00424 
00425         LLTextBox* channel_text = getChild<LLTextBox>("channel_text");
00426         channel_text->setText(gSavedSettings.getString("VersionChannelName"));
00427         channel_text->setClickedCallback(onClickVersion);
00428         channel_text->setCallbackUserData(this);
00429         
00430         LLTextBox* forgot_password_text = getChild<LLTextBox>("forgot_password_text");
00431         forgot_password_text->setClickedCallback(onClickForgotPassword);
00432 #endif    
00433         
00434         // get the web browser control
00435         LLWebBrowserCtrl* web_browser = getChild<LLWebBrowserCtrl>("login_html");
00436         // Need to handle login secondlife:///app/ URLs
00437         web_browser->setOpenAppSLURLs( true );
00438 
00439         // observe browser events
00440         web_browser->addObserver( this );
00441 
00442         // don't make it a tab stop until SL-27594 is fixed
00443         web_browser->setTabStop(FALSE);
00444         web_browser->navigateToLocalPage( "loading", "loading.html" );
00445 
00446         // make links open in external browser
00447         web_browser->setOpenInExternalBrowser( true );
00448 
00449         // 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)
00450         LLRect htmlRect = getRect();
00451 #if USE_VIEWER_AUTH
00452         htmlRect.setCenterAndSize( getRect().getCenterX() - 2, getRect().getCenterY(), getRect().getWidth() + 6, getRect().getHeight());
00453 #else
00454         htmlRect.setCenterAndSize( getRect().getCenterX() - 2, getRect().getCenterY() + 40, getRect().getWidth() + 6, getRect().getHeight() - 78 );
00455 #endif
00456         web_browser->setRect( htmlRect );
00457         web_browser->reshape( htmlRect.getWidth(), htmlRect.getHeight(), TRUE );
00458         reshape( getRect().getWidth(), getRect().getHeight(), 1 );
00459 
00460         // kick off a request to grab the url manually
00461         gResponsePtr = LLIamHereLogin::build( this );
00462         std::string login_page = gSavedSettings.getString("LoginPage");
00463         if (login_page.empty())
00464         {
00465                 login_page = getString( "real_url" );
00466         }
00467         LLHTTPClient::head( login_page, gResponsePtr );
00468 
00469 #if !USE_VIEWER_AUTH
00470         // Initialize visibility (and don't force visibility - use prefs)
00471         refreshLocation( false );
00472 #endif
00473 
00474 }
00475 
00476 void LLPanelLogin::setSiteIsAlive( bool alive )
00477 {
00478         LLWebBrowserCtrl* web_browser = getChild<LLWebBrowserCtrl>("login_html");
00479         // if the contents of the site was retrieved
00480         if ( alive )
00481         {
00482                 if ( web_browser )
00483                 {
00484                         loadLoginPage();
00485                         
00486                         // mark as available
00487                         mHtmlAvailable = TRUE;
00488                 }
00489         }
00490         else
00491         // the site is not available (missing page, server down, other badness)
00492         {
00493 #if !USE_VIEWER_AUTH
00494                 if ( web_browser )
00495                 {
00496                         // hide browser control (revealing default one)
00497                         web_browser->setVisible( FALSE );
00498 
00499                         // mark as unavailable
00500                         mHtmlAvailable = FALSE;
00501                 }
00502 #else
00503 
00504                 if ( web_browser )
00505                 {       
00506                         web_browser->navigateToLocalPage( "loading-error" , "index.html" );
00507 
00508                         // mark as available
00509                         mHtmlAvailable = TRUE;
00510                 }
00511 #endif
00512         }
00513 }
00514 
00515 void LLPanelLogin::mungePassword(LLUICtrl* caller, void* user_data)
00516 {
00517         LLPanelLogin* self = (LLPanelLogin*)user_data;
00518         LLLineEditor* editor = (LLLineEditor*)caller;
00519         std::string password = editor->getText();
00520 
00521         // Re-md5 if we've changed at all
00522         if (password != self->mIncomingPassword)
00523         {
00524                 LLMD5 pass((unsigned char *)password.c_str());
00525                 char munged_password[MD5HEX_STR_SIZE];
00526                 pass.hex_digest(munged_password);
00527                 self->mMungedPassword = munged_password;
00528         }
00529 }
00530 
00531 LLPanelLogin::~LLPanelLogin()
00532 {
00533         LLPanelLogin::sInstance = NULL;
00534 
00535         // tell the responder we're not here anymore
00536         if ( gResponsePtr )
00537                 gResponsePtr->setParent( 0 );
00538 
00540         //gImageList.deleteImage( mLogoImage );
00541 }
00542 
00543 // virtual
00544 void LLPanelLogin::draw()
00545 {
00546         glPushMatrix();
00547         {
00548                 F32 image_aspect = 1.333333f;
00549                 F32 view_aspect = (F32)getRect().getWidth() / (F32)getRect().getHeight();
00550                 // stretch image to maintain aspect ratio
00551                 if (image_aspect > view_aspect)
00552                 {
00553                         glTranslatef(-0.5f * (image_aspect / view_aspect - 1.f) * getRect().getWidth(), 0.f, 0.f);
00554                         glScalef(image_aspect / view_aspect, 1.f, 1.f);
00555                 }
00556 
00557                 S32 width = getRect().getWidth();
00558                 S32 height = getRect().getHeight();
00559 
00560                 if ( mHtmlAvailable )
00561                 {
00562 #if !USE_VIEWER_AUTH
00563                         // draw a background box in black
00564                         gl_rect_2d( 0, height - 264, width, 264, LLColor4( 0.0f, 0.0f, 0.0f, 1.f ) );
00565                         // draw the bottom part of the background image - just the blue background to the native client UI
00566                         mLogoImage->draw(0, -264, width + 8, mLogoImage->getHeight());
00567 #endif
00568                 }
00569                 else
00570                 {
00571                         // the HTML login page is not available so default to the original screen
00572                         S32 offscreen_part = height / 3;
00573                         mLogoImage->draw(0, -offscreen_part, width, height+offscreen_part);
00574                 };
00575         }
00576         glPopMatrix();
00577 
00578         LLPanel::draw();
00579 }
00580 
00581 // virtual
00582 BOOL LLPanelLogin::handleKeyHere(KEY key, MASK mask)
00583 {
00584         if (( KEY_RETURN == key ) && (MASK_ALT == mask))
00585         {
00586                 gViewerWindow->toggleFullscreen(FALSE);
00587                 return TRUE;
00588         }
00589 
00590         if (('P' == key) && (MASK_CONTROL == mask))
00591         {
00592                 LLFloaterPreference::show(NULL);
00593                 return TRUE;
00594         }
00595 
00596         if (('T' == key) && (MASK_CONTROL == mask))
00597         {
00598                 new LLFloaterSimple("floater_test.xml");
00599                 return TRUE;
00600         }
00601         
00602         if ( KEY_F1 == key )
00603         {
00604                 llinfos << "Spawning HTML help window" << llendl;
00605                 gViewerHtmlHelp.show();
00606                 return TRUE;
00607         }
00608 
00609 # if !LL_RELEASE_FOR_DOWNLOAD
00610         if ( KEY_F2 == key )
00611         {
00612                 llinfos << "Spawning floater TOS window" << llendl;
00613                 LLFloaterTOS* tos_dialog = LLFloaterTOS::show(LLFloaterTOS::TOS_TOS,"");
00614                 tos_dialog->startModal();
00615                 return TRUE;
00616         }
00617 #endif
00618 
00619         if (KEY_RETURN == key && MASK_NONE == mask)
00620         {
00621                 // let the panel handle UICtrl processing: calls onClickConnect()
00622                 return LLPanel::handleKeyHere(key, mask);
00623         }
00624 
00625         return LLPanel::handleKeyHere(key, mask);
00626 }
00627 
00628 // virtual 
00629 void LLPanelLogin::setFocus(BOOL b)
00630 {
00631         if(b != hasFocus())
00632         {
00633                 if(b)
00634                 {
00635                         LLPanelLogin::giveFocus();
00636                 }
00637                 else
00638                 {
00639                         LLPanel::setFocus(b);
00640                 }
00641         }
00642 }
00643 
00644 // static
00645 void LLPanelLogin::giveFocus()
00646 {
00647 #if USE_VIEWER_AUTH
00648         if (sInstance)
00649         {
00650                 sInstance->setFocus(TRUE);
00651         }
00652 #else
00653         if( sInstance )
00654         {
00655                 // Grab focus and move cursor to first blank input field
00656                 std::string first = sInstance->childGetText("first_name_edit");
00657                 std::string pass = sInstance->childGetText("password_edit");
00658 
00659                 BOOL have_first = !first.empty();
00660                 BOOL have_pass = !pass.empty();
00661 
00662                 LLLineEditor* edit = NULL;
00663                 if (have_first && !have_pass)
00664                 {
00665                         // User saved his name but not his password.  Move
00666                         // focus to password field.
00667                         edit = sInstance->getChild<LLLineEditor>("password_edit");
00668                 }
00669                 else
00670                 {
00671                         // User doesn't have a name, so start there.
00672                         edit = sInstance->getChild<LLLineEditor>("first_name_edit");
00673                 }
00674 
00675                 if (edit)
00676                 {
00677                         edit->setFocus(TRUE);
00678                         edit->selectAll();
00679                 }
00680         }
00681 #endif
00682 }
00683 
00684 
00685 // static
00686 void LLPanelLogin::show(const LLRect &rect,
00687                                                 BOOL show_server,
00688                                                 void (*callback)(S32 option, void* user_data),
00689                                                 void* callback_data)
00690 {
00691         new LLPanelLogin(rect, show_server, callback, callback_data);
00692 
00693         if( !gFocusMgr.getKeyboardFocus() )
00694         {
00695                 // Grab focus and move cursor to first enabled control
00696                 sInstance->setFocus(TRUE);
00697         }
00698 
00699         // Make sure that focus always goes here (and use the latest sInstance that was just created)
00700         gFocusMgr.setDefaultKeyboardFocus(sInstance);
00701 }
00702 
00703 // static
00704 void LLPanelLogin::setFields(const std::string& firstname, const std::string& lastname, const std::string& password,
00705                                                          BOOL remember)
00706 {
00707         if (!sInstance)
00708         {
00709                 llwarns << "Attempted fillFields with no login view shown" << llendl;
00710                 return;
00711         }
00712 
00713         sInstance->childSetText("first_name_edit", firstname);
00714         sInstance->childSetText("last_name_edit", lastname);
00715 
00716         // Max "actual" password length is 16 characters.
00717         // Hex digests are always 32 characters.
00718         if (password.length() == 32)
00719         {
00720                 // This is a MD5 hex digest of a password.
00721                 // We don't actually use the password input field, 
00722                 // fill it with MAX_PASSWORD characters so we get a 
00723                 // nice row of asterixes.
00724                 const std::string filler("123456789!123456");
00725                 sInstance->childSetText("password_edit", filler);
00726                 sInstance->mIncomingPassword = filler;
00727                 sInstance->mMungedPassword = password;
00728         }
00729         else
00730         {
00731                 // this is a normal text password
00732                 sInstance->childSetText("password_edit", password);
00733                 sInstance->mIncomingPassword = password;
00734                 LLMD5 pass((unsigned char *)password.c_str());
00735                 char munged_password[MD5HEX_STR_SIZE];
00736                 pass.hex_digest(munged_password);
00737                 sInstance->mMungedPassword = munged_password;
00738         }
00739 
00740         sInstance->childSetValue("remember_check", remember);
00741 }
00742 
00743 
00744 // static
00745 void LLPanelLogin::addServer(const char *server, S32 domain_name)
00746 {
00747         if (!sInstance)
00748         {
00749                 llwarns << "Attempted addServer with no login view shown" << llendl;
00750                 return;
00751         }
00752 
00753         LLComboBox* combo = sInstance->getChild<LLComboBox>("server_combo");
00754         combo->add(server, LLSD(domain_name) );
00755         combo->setCurrentByIndex(0);
00756 }
00757 
00758 // static
00759 void LLPanelLogin::getFields(LLString &firstname, LLString &lastname, LLString &password,
00760                                                         BOOL &remember)
00761 {
00762         if (!sInstance)
00763         {
00764                 llwarns << "Attempted getFields with no login view shown" << llendl;
00765                 return;
00766         }
00767 
00768         firstname = sInstance->childGetText("first_name_edit");
00769         LLString::trim(firstname);
00770 
00771         lastname = sInstance->childGetText("last_name_edit");
00772         LLString::trim(lastname);
00773 
00774         password = sInstance->mMungedPassword;
00775         remember = sInstance->childGetValue("remember_check");
00776 }
00777 
00778 
00779 // static.  Return TRUE if user made a choice from the popup
00780 BOOL LLPanelLogin::getServer(LLString &server, S32 &domain_name)
00781 {
00782         BOOL user_picked = FALSE;
00783         if (!sInstance)
00784         {
00785                 llwarns << "Attempted getServer with no login view shown" << llendl;
00786         }
00787         else
00788         {
00789                 LLComboBox* combo = sInstance->getChild<LLComboBox>("server_combo");
00790                 LLSD combo_val = combo->getValue();
00791                 if (LLSD::TypeInteger == combo_val.type())
00792                 {
00793                         domain_name = combo->getValue().asInteger();
00794 
00795                         if ((S32)GRID_INFO_OTHER == domain_name)
00796                         {
00797                                 server = gGridName;
00798                         }
00799                 }
00800                 else
00801                 {
00802                         // no valid selection, return other
00803                         domain_name = (S32)GRID_INFO_OTHER;
00804                         server = combo_val.asString();
00805                 }
00806                 user_picked = combo->isDirty();
00807         }
00808 
00809         return user_picked;
00810 }
00811 
00812 // static
00813 void LLPanelLogin::getLocation(LLString &location)
00814 {
00815         if (!sInstance)
00816         {
00817                 llwarns << "Attempted getLocation with no login view shown" << llendl;
00818                 return;
00819         }
00820         
00821         LLComboBox* combo = sInstance->getChild<LLComboBox>("start_location_combo");
00822         location = combo->getValue().asString();
00823 }
00824 
00825 // static
00826 void LLPanelLogin::refreshLocation( bool force_visible )
00827 {
00828         if (!sInstance) return;
00829 
00830 #if USE_VIEWER_AUTH
00831         loadLoginPage();
00832 #else
00833         LLComboBox* combo = sInstance->getChild<LLComboBox>("start_location_combo");
00834 
00835         if (LLURLSimString::parse())
00836         {
00837                 combo->setCurrentByIndex( 3 );          // BUG?  Maybe 2?
00838                 combo->setTextEntry(LLURLSimString::sInstance.mSimString);
00839         }
00840         else
00841         {
00842                 BOOL login_last = gSavedSettings.getBOOL("LoginLastLocation");
00843                 combo->setCurrentByIndex( login_last ? 1 : 0 );
00844         }
00845 
00846         BOOL show_start = TRUE;
00847 
00848         if ( ! force_visible )
00849                 show_start = gSavedSettings.getBOOL("ShowStartLocation");
00850 
00851         sInstance->childSetVisible("start_location_combo", show_start);
00852         sInstance->childSetVisible("start_location_text", show_start);
00853 
00854 #if LL_RELEASE_FOR_DOWNLOAD
00855         BOOL show_server = gSavedSettings.getBOOL("ForceShowGrid");
00856         sInstance->childSetVisible("server_combo", show_server);
00857 #else
00858         sInstance->childSetVisible("server_combo", TRUE);
00859 #endif
00860 
00861 #endif
00862 }
00863 
00864 // static
00865 void LLPanelLogin::close()
00866 {
00867         if (sInstance)
00868         {
00869                 gViewerWindow->getRootView()->removeChild( LLPanelLogin::sInstance );
00870                 
00871                 gFocusMgr.setDefaultKeyboardFocus(NULL);
00872 
00873                 delete sInstance;
00874                 sInstance = NULL;
00875         }
00876 }
00877 
00878 // static
00879 void LLPanelLogin::setAlwaysRefresh(bool refresh)
00880 {
00881         if (LLStartUp::getStartupState() >= STATE_LOGIN_CLEANUP) return;
00882 
00883         LLWebBrowserCtrl* web_browser = sInstance->getChild<LLWebBrowserCtrl>("login_html");
00884 
00885         if (web_browser)
00886         {
00887                 web_browser->setAlwaysRefresh(refresh);
00888         }
00889 }
00890 
00891 
00892 
00893 void LLPanelLogin::loadLoginPage()
00894 {
00895         if (!sInstance) return;
00896         
00897         std::ostringstream oStr;
00898 
00899         std::string login_page = gSavedSettings.getString("LoginPage");
00900         if (login_page.empty())
00901         {
00902                 login_page = sInstance->getString( "real_url" );
00903         }
00904         oStr << login_page;
00905         
00906         // Use the right delimeter depending on how LLURI parses the URL
00907         LLURI login_page_uri = LLURI(login_page);
00908         std::string first_query_delimiter = "&";
00909         if (login_page_uri.queryMap().size() == 0)
00910         {
00911                 first_query_delimiter = "?";
00912         }
00913 
00914         // Language
00915         LLString language(gSavedSettings.getString("Language"));
00916         if(language == "default")
00917         {
00918                 language = gSavedSettings.getString("SystemLanguage");
00919         }
00920         oStr << first_query_delimiter<<"lang=" << language;
00921         
00922         // First Login?
00923         if (gSavedSettings.getBOOL("FirstLoginThisInstall"))
00924         {
00925                 oStr << "&firstlogin=TRUE";
00926         }
00927 
00928         // Channel and Version
00929         LLString version = llformat("%d.%d.%d (%d)",
00930                                                 LL_VERSION_MAJOR, LL_VERSION_MINOR, LL_VERSION_PATCH, LL_VIEWER_BUILD);
00931 
00932         char* curl_channel = curl_escape(gSavedSettings.getString("VersionChannelName").c_str(), 0);
00933         char* curl_version = curl_escape(version.c_str(), 0);
00934 
00935         oStr << "&channel=" << curl_channel;
00936         oStr << "&version=" << curl_version;
00937 
00938         curl_free(curl_channel);
00939         curl_free(curl_version);
00940 
00941         // Grid
00942         LLString grid;
00943         S32 grid_index;
00944         getServer( grid, grid_index );
00945         if( grid_index != (S32)GRID_INFO_OTHER )
00946         {
00947                 grid = gGridInfo[grid_index].mLabel;
00948         }
00949 
00950         if(gGridChoice != (EGridInfo)grid_index)
00951         {
00952                 LLAppViewer::instance()->resetURIs();
00953                 gGridChoice = (EGridInfo)grid_index;
00954                 gSavedSettings.setString("GridChoice", gGridInfo[gGridChoice].mLabel);
00955                 gViewerWindow->setMenuBackgroundColor(false, 
00956                         !LLAppViewer::instance()->isInProductionGrid());
00957                 gLoginMenuBarView->setBackgroundColor(gMenuBarView->getBackgroundColor());
00958         }
00959     
00960         char* curl_grid = curl_escape(grid.c_str(), 0);
00961         oStr << "&grid=" << curl_grid;
00962         curl_free(curl_grid);
00963 
00964 #if USE_VIEWER_AUTH
00965         LLURLSimString::sInstance.parse();
00966 
00967         LLString location;
00968         LLString region;
00969         LLString password;
00970         
00971         if (LLURLSimString::parse())
00972         {
00973                 std::ostringstream oRegionStr;
00974                 location = "specify";
00975                 oRegionStr << LLURLSimString::sInstance.mSimName << "/" << LLURLSimString::sInstance.mX << "/"
00976                          << LLURLSimString::sInstance.mY << "/"
00977                          << LLURLSimString::sInstance.mZ;
00978                 region = oRegionStr.str();
00979         }
00980         else
00981         {
00982                 if (gSavedSettings.getBOOL("LoginLastLocation"))
00983                 {
00984                         location = "last";
00985                 }
00986                 else
00987                 {
00988                         location = "home";
00989                 }
00990         }
00991         
00992         LLString firstname, lastname;
00993 
00994     if(gSavedSettings.getLLSD("UserLoginInfo").size() == 3)
00995     {
00996         LLSD cmd_line_login = gSavedSettings.getLLSD("UserLoginInfo");
00997                 firstname = cmd_line_login[0].asString();
00998                 lastname = cmd_line_login[1].asString();
00999         password = cmd_line_login[2].asString();
01000     }
01001         
01002         if (firstname.empty())
01003         {
01004                 firstname = gSavedSettings.getString("FirstName");
01005         }
01006         
01007         if (lastname.empty())
01008         {
01009                 lastname = gSavedSettings.getString("LastName");
01010         }
01011         
01012         char* curl_region = curl_escape(region.c_str(), 0);
01013 
01014         oStr <<"firstname=" << firstname <<
01015                 "&lastname=" << lastname << "&location=" << location << "&region=" << curl_region;
01016         
01017         curl_free(curl_region);
01018 
01019         if (!password.empty())
01020         {
01021                 oStr << "&password=" << password;
01022         }
01023         else if (!(password = load_password_from_disk()).empty())
01024         {
01025                 oStr << "&password=$1$" << password;
01026         }
01027         if (gAutoLogin)
01028         {
01029                 oStr << "&auto_login=TRUE";
01030         }
01031         if (gSavedSettings.getBOOL("ShowStartLocation"))
01032         {
01033                 oStr << "&show_start_location=TRUE";
01034         }       
01035         if (gSavedSettings.getBOOL("RememberPassword"))
01036         {
01037                 oStr << "&remember_password=TRUE";
01038         }       
01039 #ifndef LL_RELEASE_FOR_DOWNLOAD
01040         oStr << "&show_grid=TRUE";
01041 #else
01042         if (gSavedSettings.getBOOL("ForceShowGrid"))
01043                 oStr << "&show_grid=TRUE";
01044 #endif
01045 #endif
01046         
01047         LLWebBrowserCtrl* web_browser = sInstance->getChild<LLWebBrowserCtrl>("login_html");
01048         
01049         // navigate to the "real" page 
01050         web_browser->navigateTo( oStr.str() );
01051 }
01052 
01053 void LLPanelLogin::onNavigateComplete( const EventType& eventIn )
01054 {
01055         LLWebBrowserCtrl* web_browser = sInstance->getChild<LLWebBrowserCtrl>("login_html");
01056         if (web_browser)
01057         {
01058                 // *HACK HACK HACK HACK!
01059                 /* Stuff a Tab key into the browser now so that the first field will
01060                 ** get the focus!  The embedded javascript on the page that properly
01061                 ** sets the initial focus in a real web browser is not working inside
01062                 ** the viewer, so this is an UGLY HACK WORKAROUND for now.
01063                 */
01064                 // Commented out as it's not reliable
01065                 //web_browser->handleKey(KEY_TAB, MASK_NONE, false);
01066         }
01067 }
01068 
01069 //---------------------------------------------------------------------------
01070 // Protected methods
01071 //---------------------------------------------------------------------------
01072 
01073 // static
01074 void LLPanelLogin::onClickConnect(void *)
01075 {
01076         if (sInstance && sInstance->mCallback)
01077         {
01078                 // tell the responder we're not here anymore
01079                 if ( gResponsePtr )
01080                         gResponsePtr->setParent( 0 );
01081 
01082                 // JC - Make sure the fields all get committed.
01083                 sInstance->setFocus(FALSE);
01084 
01085                 LLString first = sInstance->childGetText("first_name_edit");
01086                 LLString last  = sInstance->childGetText("last_name_edit");
01087                 if (!first.empty() && !last.empty())
01088                 {
01089                         // has both first and last name typed
01090 
01091                         // store off custom server entry, if currently selected
01092                         LLComboBox* combo = sInstance->getChild<LLComboBox>("server_combo");
01093                         S32 selected_server = combo->getValue();
01094                         if (selected_server == GRID_INFO_NONE)
01095                         {
01096                                 LLString custom_server = combo->getValue().asString();
01097                                 gSavedSettings.setString("CustomServer", custom_server);
01098                         }
01099                         sInstance->mCallback(0, sInstance->mCallbackData);
01100                 }
01101                 else
01102                 {
01103                         // empty first or last name
01104                         // same as clicking new account
01105                         onClickNewAccount(NULL);
01106                 }
01107         }
01108 }
01109 
01110 
01111 // static
01112 void LLPanelLogin::newAccountAlertCallback(S32 option, void*)
01113 {
01114         if (0 == option)
01115         {
01116                 llinfos << "Going to account creation URL" << llendl;
01117                 LLWeb::loadURL( CREATE_ACCOUNT_URL );
01118         }
01119         else
01120         {
01121                 sInstance->setFocus(TRUE);
01122         }
01123 }
01124 
01125 
01126 // static
01127 void LLPanelLogin::onClickNewAccount(void*)
01128 {
01129         if (gHideLinks)
01130         {
01131                 gViewerWindow->alertXml("MustHaveAccountToLogInNoLinks");
01132         }
01133         else
01134         {
01135                 gViewerWindow->alertXml("MustHaveAccountToLogIn",
01136                                                                 LLPanelLogin::newAccountAlertCallback);
01137         }
01138 }
01139 
01140 
01141 // static
01142 void LLPanelLogin::onClickQuit(void*)
01143 {
01144         if (sInstance && sInstance->mCallback)
01145         {
01146                 // tell the responder we're not here anymore
01147                 if ( gResponsePtr )
01148                         gResponsePtr->setParent( 0 );
01149 
01150                 sInstance->mCallback(1, sInstance->mCallbackData);
01151         }
01152 }
01153 
01154 
01155 // static
01156 void LLPanelLogin::onClickVersion(void*)
01157 {
01158         LLFloaterAbout::show(NULL);
01159 }
01160 
01161 void LLPanelLogin::onClickForgotPassword(void*)
01162 {
01163         if (sInstance )
01164         {
01165                 LLWeb::loadURL(sInstance->getString( "forgot_password_url" ));
01166         }
01167 }
01168 
01169 
01170 // static
01171 void LLPanelLogin::onPassKey(LLLineEditor* caller, void* user_data)
01172 {
01173         if (gKeyboard->getKeyDown(KEY_CAPSLOCK) && sCapslockDidNotification == FALSE)
01174         {
01175                 LLNotifyBox::showXml("CapsKeyOn");
01176                 sCapslockDidNotification = TRUE;
01177         }
01178 }
01179 
01180 // static
01181 void LLPanelLogin::onSelectServer(LLUICtrl*, void*)
01182 {
01183         // grid changed so show new splash screen (possibly)
01184         loadLoginPage();
01185 }

Generated on Fri May 16 08:33:54 2008 for SecondLife by  doxygen 1.5.5