/** * @return string */ public function ServiceChange() { $oAccount = $this->oActions->GetAccount(); if ($oAccount && $this->oActions->GetCapa(false, \RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS, $oAccount)) { $oAccountToLogin = null; $sEmail = empty($this->aPaths[2]) ? '' : \urldecode(\trim($this->aPaths[2])); if (!empty($sEmail)) { $sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail); $aAccounts = $this->oActions->GetAccounts($oAccount); if (isset($aAccounts[$sEmail])) { $oAccountToLogin = $this->oActions->GetAccountFromCustomToken($aAccounts[$sEmail], false, false); } } if ($oAccountToLogin) { $this->oActions->AuthToken($oAccountToLogin); } } $this->oActions->Location('./'); return ''; }
/** * @return string */ public function ServiceChange() { if ($this->Config()->Get('webmail', 'allow_additional_accounts', true)) { $oAccountToLogin = null; $sEmail = empty($this->aPaths[2]) ? '' : \urldecode(\trim($this->aPaths[2])); if (!empty($sEmail)) { $sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail); $oAccount = $this->oActions->GetAccount(); if ($oAccount) { $aAccounts = $this->oActions->GetAccounts($oAccount); if (isset($aAccounts[$sEmail])) { $oAccountToLogin = $this->oActions->GetAccountFromCustomToken($aAccounts[$sEmail], false, false); } } } if ($oAccountToLogin) { $this->oActions->AuthProcess($oAccountToLogin); } } $this->oActions->Location('./'); return ''; }
/** * @return string */ public function TwitterPopupService() { $sResult = ''; $sLoginUrl = ''; $sSocialName = ''; $bLogin = false; $iErrorCode = \RainLoop\Notifications::UnknownError; $sRedirectUrl = $this->oHttp->GetFullUrl() . '?SocialTwitter'; if (0 < strlen($this->oActions->GetSpecAuthToken())) { $sRedirectUrl .= '&rlah=' . $this->oActions->GetSpecAuthToken(); } else { if ($this->oHttp->HasQuery('rlah')) { $this->oActions->SetSpecAuthToken($this->oHttp->GetQuery('rlah', '')); $sRedirectUrl .= '&rlah=' . $this->oActions->GetSpecAuthToken(); } } try { $oTwitter = $this->TwitterConnector(); if ($oTwitter) { $sSessionKey = \implode('_', array('twitter', \md5($oTwitter->config['consumer_secret']), \md5(\RainLoop\Utils::GetConnectionToken()), 'AuthSessionData')); $oAccount = $this->oActions->GetAccount(); if ($oAccount) { if (isset($_REQUEST['oauth_verifier'])) { $sAuth = $this->oActions->Cacher()->Get($sSessionKey); $oAuth = $sAuth ? \json_decode($sAuth, true) : null; if ($oAuth && !empty($oAuth['oauth_token']) && !empty($oAuth['oauth_token_secret'])) { $oTwitter->config['user_token'] = $oAuth['oauth_token']; $oTwitter->config['user_secret'] = $oAuth['oauth_token_secret']; $iCode = $oTwitter->request('POST', $oTwitter->url('oauth/access_token', ''), array('oauth_callback' => $sRedirectUrl, 'oauth_verifier' => $_REQUEST['oauth_verifier'])); if (200 === $iCode && isset($oTwitter->response['response'])) { $this->oActions->Logger()->WriteDump($oTwitter->response['response']); $aAccessToken = $oTwitter->extract_params($oTwitter->response['response']); $this->oActions->Logger()->WriteDump($aAccessToken); if ($aAccessToken && isset($aAccessToken['oauth_token']) && !empty($aAccessToken['user_id'])) { $oTwitter->config['user_token'] = $aAccessToken['oauth_token']; $oTwitter->config['user_secret'] = $aAccessToken['oauth_token_secret']; $sSocialName = !empty($aAccessToken['screen_name']) ? '@' . $aAccessToken['screen_name'] : $aAccessToken['user_id']; $sSocialName = \trim($sSocialName); $aUserData = array('Email' => $oAccount->Email(), 'Password' => $oAccount->Password()); $oSettings = $this->oActions->SettingsProvider()->Load($oAccount); $oSettings->SetConf('TwitterAccessToken', \RainLoop\Utils::EncodeKeyValues($aAccessToken)); $oSettings->SetConf('TwitterSocialName', $sSocialName); $this->oActions->SettingsProvider()->Save($oAccount, $oSettings); $this->oActions->StorageProvider()->Put(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, $this->TwitterUserLoginStorageKey($oTwitter, $aAccessToken['user_id']), \RainLoop\Utils::EncodeKeyValues($aUserData)); $iErrorCode = 0; } } } } else { $aParams = array('oauth_callback' => $sRedirectUrl, 'x_auth_access_type' => 'read'); $iCode = $oTwitter->request('POST', $oTwitter->url('oauth/request_token', ''), $aParams); if (200 === $iCode && isset($oTwitter->response['response'])) { $oAuth = $oTwitter->extract_params($oTwitter->response['response']); if (!empty($oAuth['oauth_token'])) { $this->oActions->Cacher()->Set($sSessionKey, \json_encode($oAuth)); $sLoginUrl = $oTwitter->url('oauth/authenticate', '') . '?oauth_token=' . $oAuth['oauth_token']; } } } } else { $bLogin = true; if (isset($_REQUEST['oauth_verifier'])) { $sAuth = $this->oActions->Cacher()->Get($sSessionKey); $oAuth = $sAuth ? \json_decode($sAuth, true) : null; if ($oAuth && !empty($oAuth['oauth_token']) && !empty($oAuth['oauth_token_secret'])) { $oTwitter->config['user_token'] = $oAuth['oauth_token']; $oTwitter->config['user_secret'] = $oAuth['oauth_token_secret']; $iCode = $oTwitter->request('POST', $oTwitter->url('oauth/access_token', ''), array('oauth_callback' => $sRedirectUrl, 'oauth_verifier' => $_REQUEST['oauth_verifier'])); if (200 === $iCode && isset($oTwitter->response['response'])) { $aAccessToken = $oTwitter->extract_params($oTwitter->response['response']); if ($aAccessToken && isset($aAccessToken['oauth_token']) && !empty($aAccessToken['user_id'])) { $sUserData = $this->oActions->StorageProvider()->Get(null, \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY, $this->TwitterUserLoginStorageKey($oTwitter, $aAccessToken['user_id'])); $aUserData = \RainLoop\Utils::DecodeKeyValues($sUserData); if ($aUserData && \is_array($aUserData) && !empty($aUserData['Email']) && isset($aUserData['Password'])) { $oAccount = $this->oActions->LoginProcess($aUserData['Email'], $aUserData['Password']); if ($oAccount instanceof \RainLoop\Account) { $this->oActions->AuthProcess($oAccount); $iErrorCode = 0; } } else { $iErrorCode = \RainLoop\Notifications::SocialTwitterLoginAccessDisable; } $this->oActions->Cacher()->Delete($sSessionKey); } } } } else { $aParams = array('oauth_callback' => $sRedirectUrl, 'x_auth_access_type' => 'read'); $iCode = $oTwitter->request('POST', $oTwitter->url('oauth/request_token', ''), $aParams); if (200 === $iCode && isset($oTwitter->response['response'])) { $oAuth = $oTwitter->extract_params($oTwitter->response['response']); if (!empty($oAuth['oauth_token'])) { $this->oActions->Cacher()->Set($sSessionKey, \json_encode($oAuth)); $sLoginUrl = $oTwitter->url('oauth/authenticate', '') . '?oauth_token=' . $oAuth['oauth_token']; } } } } } } catch (\Exception $oException) { $this->oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); } if ($sLoginUrl) { $this->oActions->Location($sLoginUrl); } else { @\header('Content-Type: text/html; charset=utf-8'); $sCallBackType = $bLogin ? '_login' : ''; $sConnectionFunc = 'rl_' . \md5(\RainLoop\Utils::GetConnectionToken()) . '_twitter' . $sCallBackType . '_service'; $sResult = '<script type="text/javascript" data-cfasync="false">opener && opener.' . $sConnectionFunc . ' && opener.' . $sConnectionFunc . '(' . $iErrorCode . '); self && self.close && self.close();</script>'; } return $sResult; }