/indra/newview/llloginhandler.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 203 lines · 117 code · 31 blank · 55 comment · 25 complexity · d7ff2f77472da191f1ed1b309add9be2 MD5 · raw file

  1. /**
  2. * @file llloginhandler.cpp
  3. * @brief Handles filling in the login panel information from a SLURL
  4. * such as secondlife:///app/login?first=Bob&last=Dobbs
  5. *
  6. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "llviewerprecompiledheaders.h"
  28. #include "llloginhandler.h"
  29. // viewer includes
  30. #include "llsecapi.h"
  31. #include "lllogininstance.h" // to check if logged in yet
  32. #include "llpanellogin.h"
  33. #include "llstartup.h" // getStartupState()
  34. #include "llslurl.h"
  35. #include "llviewercontrol.h" // gSavedSettings
  36. #include "llviewernetwork.h" // EGridInfo
  37. #include "llviewerwindow.h" // getWindow()
  38. // library includes
  39. #include "llmd5.h"
  40. #include "llweb.h"
  41. #include "llwindow.h"
  42. // Must have instance to auto-register with LLCommandDispatcher
  43. LLLoginHandler gLoginHandler;
  44. //parses the input url and returns true if afterwards
  45. //a web-login-key, firstname and lastname is set
  46. bool LLLoginHandler::parseDirectLogin(std::string url)
  47. {
  48. LLURI uri(url);
  49. parse(uri.queryMap());
  50. // NOTE: Need to add direct login as per identity evolution
  51. return true;
  52. }
  53. void LLLoginHandler::parse(const LLSD& queryMap)
  54. {
  55. if (queryMap.has("grid"))
  56. {
  57. LLGridManager::getInstance()->setGridChoice(queryMap["grid"].asString());
  58. }
  59. std::string startLocation = queryMap["location"].asString();
  60. if (startLocation == "specify")
  61. {
  62. LLStartUp::setStartSLURL(LLSLURL(LLGridManager::getInstance()->getGridLoginID(),
  63. queryMap["region"].asString()));
  64. }
  65. else if (startLocation == "home")
  66. {
  67. LLStartUp::setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_HOME));
  68. }
  69. else if (startLocation == "last")
  70. {
  71. LLStartUp::setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_LAST));
  72. }
  73. }
  74. bool LLLoginHandler::handle(const LLSD& tokens,
  75. const LLSD& query_map,
  76. LLMediaCtrl* web)
  77. {
  78. // do nothing if we are already logged in
  79. if (LLLoginInstance::getInstance()->authSuccess())
  80. {
  81. LL_WARNS_ONCE("SLURL") << "Already logged in! Ignoring login SLapp." << LL_ENDL;
  82. return true;
  83. }
  84. if (tokens.size() == 1
  85. && tokens[0].asString() == "show")
  86. {
  87. // We're using reg-in-client, so show the XUI login widgets
  88. LLPanelLogin::showLoginWidgets();
  89. return true;
  90. }
  91. if (tokens.size() == 1
  92. && tokens[0].asString() == "reg")
  93. {
  94. LLWindow* window = gViewerWindow->getWindow();
  95. window->incBusyCount();
  96. window->setCursor(UI_CURSOR_ARROW);
  97. // Do this first, as it may be slow and we want to keep something
  98. // on the user's screen as long as possible
  99. LLWeb::loadURLExternal( "http://join.eniac15.lindenlab.com/" );
  100. window->decBusyCount();
  101. window->setCursor(UI_CURSOR_ARROW);
  102. // Then hide the window
  103. window->minimize();
  104. return true;
  105. }
  106. // Make sure window is visible
  107. LLWindow* window = gViewerWindow->getWindow();
  108. if (window->getMinimized())
  109. {
  110. window->restore();
  111. }
  112. parse(query_map);
  113. //if we haven't initialized stuff yet, this is
  114. //coming in from the GURL handler, just parse
  115. if (STATE_FIRST == LLStartUp::getStartupState())
  116. {
  117. return true;
  118. }
  119. if (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP) //on splash page
  120. {
  121. // as the login page may change from grid to grid, as well as
  122. // things like username/password/etc, we simply refresh the
  123. // login page to make sure everything is set up correctly
  124. LLPanelLogin::loadLoginPage();
  125. LLStartUp::setStartupState( STATE_LOGIN_CLEANUP );
  126. }
  127. return true;
  128. }
  129. // Initialize the credentials
  130. // If the passed in URL contains login info, parse
  131. // that into a credential and web login key. Otherwise
  132. // check the command line. If the command line
  133. // does not contain any login creds, load the last saved
  134. // ones from the protected credential store.
  135. // This always returns with a credential structure set in the
  136. // login handler
  137. LLPointer<LLCredential> LLLoginHandler::initializeLoginInfo()
  138. {
  139. LLPointer<LLCredential> result = NULL;
  140. // so try to load it from the UserLoginInfo
  141. result = loadSavedUserLoginInfo();
  142. if (result.isNull())
  143. {
  144. result = gSecAPIHandler->loadCredential(LLGridManager::getInstance()->getGrid());
  145. }
  146. return result;
  147. }
  148. LLPointer<LLCredential> LLLoginHandler::loadSavedUserLoginInfo()
  149. {
  150. // load the saved user login info into a LLCredential.
  151. // perhaps this should be moved.
  152. LLSD cmd_line_login = gSavedSettings.getLLSD("UserLoginInfo");
  153. if (cmd_line_login.size() == 3)
  154. {
  155. LLMD5 pass((unsigned char*)cmd_line_login[2].asString().c_str());
  156. char md5pass[33]; /* Flawfinder: ignore */
  157. pass.hex_digest(md5pass);
  158. LLSD identifier = LLSD::emptyMap();
  159. identifier["type"] = "agent";
  160. identifier["first_name"] = cmd_line_login[0];
  161. identifier["last_name"] = cmd_line_login[1];
  162. LLSD authenticator = LLSD::emptyMap();
  163. authenticator["type"] = "hash";
  164. authenticator["algorithm"] = "md5";
  165. authenticator["secret"] = md5pass;
  166. // yuck, we'll fix this with mani's changes.
  167. gSavedSettings.setBOOL("AutoLogin", TRUE);
  168. return gSecAPIHandler->createCredential(LLGridManager::getInstance()->getGrid(),
  169. identifier, authenticator);
  170. }
  171. return NULL;
  172. }