diff options
| -rw-r--r-- | phpBB/includes/ucp/ucp_login_link.php | 140 | 
1 files changed, 79 insertions, 61 deletions
diff --git a/phpBB/includes/ucp/ucp_login_link.php b/phpBB/includes/ucp/ucp_login_link.php index c99f162f1a..18d07fb520 100644 --- a/phpBB/includes/ucp/ucp_login_link.php +++ b/phpBB/includes/ucp/ucp_login_link.php @@ -27,10 +27,7 @@ class ucp_login_link  	function main($id, $mode)  	{ -		global $auth, $config, $phpbb_container, $request, $template, $user; - -		$auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']); -		$auth_provider = $phpbb_container->get($auth_provider); +		global $config, $phpbb_container, $request, $template, $user;  		// Initialize necessary variables  		$login_error = null; @@ -53,83 +50,45 @@ class ucp_login_link  			$login_link_error = $user->lang[$result];  		} +		// Use the auth_provider requested even if different from configured +		$auth_provider = 'auth_provider.' . (array_key_exists('auth_provider', $data)) ? $data['auth_provider'] : $config['auth_method']; +		$auth_provider = $phpbb_container->get($auth_provider); +  		// Perform link action if there is no error  		if (!$login_link_error)  		{  			if ($request->is_set_post('login'))  			{ -				$login_username = $request->variable('login_username', '', false, phpbb_request_interface::POST); -				$login_password = $request->untrimmed_variable('password', '', true, phpbb_request_interface::POST); - -				$result = $auth->login($login_username, $login_password); +				// We only care if there is or is not an error +				$login_error = $this->perform_login_action(); -				if ($result['status'] != LOGIN_SUCCESS) +				if (!$login_error)  				{ -					// Handle all errors first -					if ($result['status'] == LOGIN_BREAK) -					{ -						trigger_error($result['error_msg']); -					} +					// The user is now logged in, attempt to link the user to the external account +					$result = $auth_provider->link_account($data); -					switch ($result['status']) +					if ($result)  					{ -						case LOGIN_ERROR_ATTEMPTS: - -							$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']); -							$captcha->init(CONFIRM_LOGIN); - -							$template->assign_vars(array( -								'CAPTCHA_TEMPLATE'			=> $captcha->get_template(), -							)); - -							$login_error = $user->lang[$result['error_msg']]; -						break; - -						case LOGIN_ERROR_PASSWORD_CONVERT: -							$login_error = sprintf( -								$user->lang[$result['error_msg']], -								($config['email_enable']) ? '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') . '">' : '', -								($config['email_enable']) ? '</a>' : '', -								($config['board_contact']) ? '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">' : '', -								($config['board_contact']) ? '</a>' : '' -							); -						break; - -						// Username, password, etc... -						default: -							$login_error = $user->lang[$result['error_msg']]; - -							// Assign admin contact to some error messages -							if ($result['error_msg'] == 'LOGIN_ERROR_USERNAME' || $result['error_msg'] == 'LOGIN_ERROR_PASSWORD') -							{ -								$login_error = (!$config['board_contact']) ? sprintf($user->lang[$result['error_msg']], '', '') : sprintf($user->lang[$result['error_msg']], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'); -							} - -						break; +						$login_link_error = $user->lang[$result]; +					} else { +						// Perform a redirect as the account has been linked  					} -				} else { -					// The user is now logged in, attempt to link the user to the external account -					$auth_provider->link_account($data);  				}  			}  		} -		// Common template elements +		$register_link = redirect('ucp.php?mode=register', true); +  		$template->assign_vars(array( +			// Common template elements  			'LOGIN_LINK_ERROR'		=> $login_link_error,  			'PASSWORD_CREDENTIAL'	=> 'login_password',  			'USERNAME_CREDENTIAL'	=> 'login_username', -		)); -		// Registration template -		$register_link = 'ucp.php?mode=register'; - -		$template->assign_vars(array( -			'REGISTER_LINK'	=>	redirect($register_link, true), -		)); +			// Registration elements +			'REGISTER_LINK'	=>	$register_link, -		// Link to existing account template -		$template->assign_vars(array( +			// Login elements  			'LOGIN_ERROR'		=> $login_error,  			'LOGIN_USERNAME'	=> $login_username,  		)); @@ -156,4 +115,63 @@ class ucp_login_link  		return $login_link_data;  	} + +	protected function perform_login_action() +	{ +		global $auth, $config, $request, $template, $user; +		$login_username = $request->variable('login_username', '', false, phpbb_request_interface::POST); +		$login_password = $request->untrimmed_variable('password', '', true, phpbb_request_interface::POST); + +		$result = $auth->login($login_username, $login_password); + +		$login_error = null; + +		if ($result['status'] != LOGIN_SUCCESS) +		{ +			// Handle all errors first +			if ($result['status'] == LOGIN_BREAK) +			{ +				trigger_error($result['error_msg']); +			} + +			switch ($result['status']) +			{ +				case LOGIN_ERROR_ATTEMPTS: + +					$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']); +					$captcha->init(CONFIRM_LOGIN); + +					$template->assign_vars(array( +						'CAPTCHA_TEMPLATE'			=> $captcha->get_template(), +					)); + +					$login_error = $user->lang[$result['error_msg']]; +				break; + +				case LOGIN_ERROR_PASSWORD_CONVERT: +					$login_error = sprintf( +						$user->lang[$result['error_msg']], +						($config['email_enable']) ? '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') . '">' : '', +						($config['email_enable']) ? '</a>' : '', +						($config['board_contact']) ? '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">' : '', +						($config['board_contact']) ? '</a>' : '' +					); +				break; + +				// Username, password, etc... +				default: +					$login_error = $user->lang[$result['error_msg']]; + +					// Assign admin contact to some error messages +					if ($result['error_msg'] == 'LOGIN_ERROR_USERNAME' || $result['error_msg'] == 'LOGIN_ERROR_PASSWORD') +					{ +						$login_error = (!$config['board_contact']) ? sprintf($user->lang[$result['error_msg']], '', '') : sprintf($user->lang[$result['error_msg']], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'); +					} + +				break; +			} +		} + +		return $login_error; +	}  }  | 
