PageRenderTime 22ms CodeModel.GetById 2ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 29#include "llloginhandler.h"
 30
 31// viewer includes
 32#include "llsecapi.h"
 33#include "lllogininstance.h"		// to check if logged in yet
 34#include "llpanellogin.h"
 35#include "llstartup.h"				// getStartupState()
 36#include "llslurl.h"
 37#include "llviewercontrol.h"		// gSavedSettings
 38#include "llviewernetwork.h"		// EGridInfo
 39#include "llviewerwindow.h"			// getWindow()
 40
 41// library includes
 42#include "llmd5.h"
 43#include "llweb.h"
 44#include "llwindow.h"
 45
 46
 47// Must have instance to auto-register with LLCommandDispatcher
 48LLLoginHandler gLoginHandler;
 49
 50
 51//parses the input url and returns true if afterwards
 52//a web-login-key, firstname and lastname  is set
 53bool LLLoginHandler::parseDirectLogin(std::string url)
 54{
 55	LLURI uri(url);
 56	parse(uri.queryMap());
 57
 58	// NOTE: Need to add direct login as per identity evolution
 59	return true;
 60}
 61
 62void LLLoginHandler::parse(const LLSD& queryMap)
 63{
 64	
 65	if (queryMap.has("grid"))
 66	{
 67	  LLGridManager::getInstance()->setGridChoice(queryMap["grid"].asString());
 68	}
 69	
 70	
 71	std::string startLocation = queryMap["location"].asString();
 72	
 73	if (startLocation == "specify")
 74	{
 75	  LLStartUp::setStartSLURL(LLSLURL(LLGridManager::getInstance()->getGridLoginID(),
 76					   queryMap["region"].asString()));
 77	}
 78	else if (startLocation == "home")
 79	{
 80	  LLStartUp::setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_HOME));
 81	}
 82	else if (startLocation == "last")
 83	{
 84	  LLStartUp::setStartSLURL(LLSLURL(LLSLURL::SIM_LOCATION_LAST));
 85	}
 86}
 87
 88bool LLLoginHandler::handle(const LLSD& tokens,
 89							const LLSD& query_map,
 90							LLMediaCtrl* web)
 91{
 92	// do nothing if we are already logged in
 93	if (LLLoginInstance::getInstance()->authSuccess())
 94	{
 95		LL_WARNS_ONCE("SLURL") << "Already logged in! Ignoring login SLapp." << LL_ENDL;
 96		return true;
 97	}
 98
 99	if (tokens.size() == 1
100		&& tokens[0].asString() == "show")
101	{
102		// We're using reg-in-client, so show the XUI login widgets
103		LLPanelLogin::showLoginWidgets();
104		return true;
105	}
106
107	if (tokens.size() == 1
108		&& tokens[0].asString() == "reg")
109	{
110		LLWindow* window = gViewerWindow->getWindow();
111		window->incBusyCount();
112		window->setCursor(UI_CURSOR_ARROW);
113
114		// Do this first, as it may be slow and we want to keep something
115		// on the user's screen as long as possible
116		LLWeb::loadURLExternal( "http://join.eniac15.lindenlab.com/" );
117
118		window->decBusyCount();
119		window->setCursor(UI_CURSOR_ARROW);
120
121		// Then hide the window
122		window->minimize();
123		return true;
124	}
125
126	// Make sure window is visible
127	LLWindow* window = gViewerWindow->getWindow();
128	if (window->getMinimized())
129	{
130		window->restore();
131	}
132
133	parse(query_map);
134	
135	//if we haven't initialized stuff yet, this is 
136	//coming in from the GURL handler, just parse
137	if (STATE_FIRST == LLStartUp::getStartupState())
138	{
139		return true;
140	}
141	
142	if  (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP)  //on splash page         
143	{
144	  // as the login page may change from grid to grid, as well as
145	  // things like username/password/etc, we simply refresh the
146	  // login page to make sure everything is set up correctly
147	  LLPanelLogin::loadLoginPage();
148	  LLStartUp::setStartupState( STATE_LOGIN_CLEANUP );
149	}
150	return true;
151}
152
153
154
155//  Initialize the credentials                                                                                              
156// If the passed in URL contains login info, parse                                                                          
157// that into a credential and web login key.  Otherwise                                                                     
158// check the command line.  If the command line                                                                             
159// does not contain any login creds, load the last saved                                                                    
160// ones from the protected credential store.                                                                                
161// This always returns with a credential structure set in the                                                               
162// login handler                                                                                                            
163LLPointer<LLCredential> LLLoginHandler::initializeLoginInfo()                                         
164{                                                                                                                           
165	LLPointer<LLCredential> result = NULL;                                                                               
166	// so try to load it from the UserLoginInfo                                                                          
167	result = loadSavedUserLoginInfo();                                                                                   
168	if (result.isNull())                                                                                                 
169	{                                                                                                                    
170		result =  gSecAPIHandler->loadCredential(LLGridManager::getInstance()->getGrid());                       
171	}                                                                                                                    
172	
173	return result;                                                                                                       
174} 
175
176
177LLPointer<LLCredential> LLLoginHandler::loadSavedUserLoginInfo()
178{
179  // load the saved user login info into a LLCredential.
180  // perhaps this should be moved.
181	LLSD cmd_line_login = gSavedSettings.getLLSD("UserLoginInfo");
182	if (cmd_line_login.size() == 3) 
183	{
184	
185		LLMD5 pass((unsigned char*)cmd_line_login[2].asString().c_str());
186		char md5pass[33];               /* Flawfinder: ignore */
187		pass.hex_digest(md5pass);
188		LLSD identifier = LLSD::emptyMap();
189		identifier["type"] = "agent";
190		identifier["first_name"] = cmd_line_login[0];
191		identifier["last_name"] = cmd_line_login[1];
192		
193		LLSD authenticator = LLSD::emptyMap();
194		authenticator["type"] = "hash";
195		authenticator["algorithm"] = "md5";
196		authenticator["secret"] = md5pass;
197		// yuck, we'll fix this with mani's changes.
198		gSavedSettings.setBOOL("AutoLogin", TRUE);
199		return gSecAPIHandler->createCredential(LLGridManager::getInstance()->getGrid(), 
200													   identifier, authenticator);
201	}
202	return NULL;
203}