TYPO3 CMS  TYPO3_6-2
Wizard.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Openid;
3 
19 
25 class Wizard extends OpenidService {
31  protected $claimedId;
32 
39 
46 
52  public function main() {
53  $p = GeneralUtility::_GP('P');
54  if (isset($p['itemName'])) {
55  $this->parentFormItemName = $p['itemName'];
56  }
57  if (isset($p['fieldChangeFunc']['TBE_EDITOR_fieldChanged'])) {
58  $this->parentFormFieldChangeFunc = $p['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
59  }
60 
61  if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_openid_mode') === 'finish'
62  && $this->openIDResponse === NULL
63  ) {
64  $this->includePHPOpenIDLibrary();
65  $openIdConsumer = $this->getOpenIDConsumer();
66  $this->openIDResponse = $openIdConsumer->complete($this->getReturnUrl());
67  $this->handleResponse();
68  $this->renderHtml();
69  return;
70  } elseif (GeneralUtility::_POST('openid_url') != '') {
71  $openIDIdentifier = GeneralUtility::_POST('openid_url');
72  $this->sendOpenIDRequest($openIDIdentifier);
73 
74  // When sendOpenIDRequest() returns, there was an error
75  $flashMessageService = GeneralUtility::makeInstance(
76  'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'
77  );
78  $flashMessage = GeneralUtility::makeInstance(
79  'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
80  sprintf(
81  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:error.setup'),
82  htmlspecialchars($openIDIdentifier)
83  ),
84  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.error'),
85  \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
86  );
87  $flashMessageService->getMessageQueueByIdentifier()->enqueue($flashMessage);
88  }
89  $this->renderHtml();
90  }
91 
97  protected function getSelfUrl() {
98  return GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir .
99  $GLOBALS['MCONF']['_'];
100  }
101 
107  protected function getReturnUrl() {
108  return $this->getSelfURL() .
109  '&tx_openid_mode=finish' .
110  '&P[itemName]=' . urlencode($this->parentFormItemName) .
111  '&P[fieldChangeFunc][TBE_EDITOR_fieldChanged]]=' . urlencode($this->parentFormFieldChangeFunc);
112  }
113 
121  protected function handleResponse() {
123  $flashMessageService = GeneralUtility::makeInstance(
124  'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'
125  );
126  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
127 
128  if (!$this->openIDResponse instanceof \Auth_OpenID_ConsumerResponse) {
129  $flashMessage = GeneralUtility::makeInstance(
130  'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
131  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:error.no-response'),
132  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.error'),
133  \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
134  );
135  } elseif ($this->openIDResponse->status == Auth_OpenID_SUCCESS) {
136  // all fine
137  $this->claimedId = $this->getSignedParameter('openid_claimed_id');
138  $flashMessage = GeneralUtility::makeInstance(
139  'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
140  sprintf(
141  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:youropenid'),
142  htmlspecialchars($this->claimedId)
143  ),
144  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.success'),
145  \TYPO3\CMS\Core\Messaging\FlashMessage::OK
146  );
147  } elseif ($this->openIDResponse->status == Auth_OpenID_CANCEL) {
148  $flashMessage = GeneralUtility::makeInstance(
149  'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
150  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:error.cancelled'),
151  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.error'),
152  \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
153  );
154  } else {
155  // another failure. show error message and form again
156  $flashMessage = GeneralUtility::makeInstance(
157  'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
158  sprintf(
159  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:error.general'),
160  htmlspecialchars($this->openIDResponse->status),
161  htmlspecialchars($this->openIDResponse->message)
162  ),
163  $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.error'),
165  );
166  }
167 
168  $defaultFlashMessageQueue->enqueue($flashMessage);
169  }
170 
176  protected function renderHtml() {
177  // use FLUID standalone view for wizard content
178  $view = GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
179  $view->setTemplatePathAndFilename(
180  \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('openid') .
181  'Resources/Private/Templates/Wizard/Content.html'
182  );
183 
185  $flashMessageService = GeneralUtility::makeInstance(
186  'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'
187  );
188  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
189  $messages = array();
190  foreach ($defaultFlashMessageQueue->getAllMessagesAndFlush() as $message) {
191  $messages[] = $message->render();
192  }
193  $view->assign('messages', $messages);
194  $view->assign('formAction', $this->getSelfURL());
195  $view->assign('claimedId', $this->claimedId);
196  $view->assign('parentFormItemName', $this->parentFormItemName);
197  $view->assign('parentFormItemNameNoHr', strtr($this->parentFormItemName, array('_hr' => '')));
198  $view->assign('parentFormFieldChangeFunc', $this->parentFormFieldChangeFunc);
199  $view->assign('showForm', TRUE);
200  if (isset($_REQUEST['openid_url'])) {
201  $view->assign('openid_url', $_REQUEST['openid_url']);
202  }
203 
204  header('HTTP/1.0 200 OK');
205  echo $view->render();
206  }
207 }
208 ?>
const Auth_OpenID_SUCCESS
Definition: Consumer.php:180
sendOpenIDRequest($openIDIdentifier)
const Auth_OpenID_CANCEL
Definition: Consumer.php:185
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]