2 /***************************************************************
5 * (c) 2007-2009 Steffen Kamper <info@sk-typo3.de>
6 * Based on Newloginbox (c) 2002-2004 Kasper Skaarhoj <kasper@typo3.com>
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
26 * The code was adapted from newloginbox, see manual for detailed description
27 ***************************************************************/
29 * Plugin 'Website User Login' for the 'felogin' extension.
31 * @author Steffen Kamper <info@sk-typo3.de>
33 * @subpackage tx_felogin
35 class tx_felogin_pi1
extends tslib_pibase
{
36 var $prefixId = 'tx_felogin_pi1'; // Same as class name
37 var $scriptRelPath = 'pi1/class.tx_felogin_pi1.php'; // Path to this script relative to the extension dir.
38 var $extKey = 'felogin'; // The extension key.
39 public $pi_checkCHash = false
;
40 public $pi_USER_INT_obj = true
;
42 protected $userIsLoggedIn; // Is user logged in?
43 protected $template; // holds the template for FE rendering
44 protected $uploadDir; // upload dir, used for flexform template files
45 protected $redirectUrl; // URL for the redirect
46 protected $noRedirect = false
; // flag for disable the redirect
47 protected $logintype; // logintype (given as GPvar), possible: login, logout
50 * The main method of the plugin
52 * @param string $content: The PlugIn content
53 * @param array $conf: The PlugIn configuration
55 * @return string The content that is displayed on the website
57 public function main($content,$conf) {
59 // Loading TypoScript array into object variable:
61 $this->uploadDir
= 'uploads/tx_felogin/';
63 // Loading default pivars
64 $this->pi_setPiVarDefaults();
66 // Loading language-labels
69 // Init FlexForm configuration for plugin:
70 $this->pi_initPIflexForm();
71 $this->mergeflexFormValuesIntoConf();
75 if ($this->conf
['storagePid']) {
76 if (intval($this->conf
['recursive'])) {
77 $this->spid
= $this->pi_getPidList($this->conf
['storagePid'], intval($this->conf
['recursive']));
79 $this->spid
= $this->conf
['storagePid'];
82 $pids = $GLOBALS['TSFE']->getStorageSiterootPids();
83 $this->spid
= $pids['_STORAGE_PID'];
87 $this->logintype
= t3lib_div
::_GP('logintype');
88 $this->referer
= t3lib_div
::_GP('referer');
89 $this->noRedirect
= ($this->piVars
['noredirect'] ||
$this->conf
['redirectDisable']);
91 // if config.typolinkLinkAccessRestrictedPages is set, the var is return_url
92 $returnUrl = t3lib_div
::_GP('return_url');
94 $this->redirectUrl
= $returnUrl;
96 $this->redirectUrl
= t3lib_div
::_GP('redirect_url');
100 $templateFile = $this->conf
['templateFile'] ?
$this->conf
['templateFile'] : 'EXT:felogin/template.html';
101 $this->template
= $this->cObj
->fileResource($templateFile);
103 // Is user logged in?
104 $this->userIsLoggedIn
= $GLOBALS['TSFE']->loginUser
;
107 if ($this->conf
['redirectMode'] && !$this->conf
['redirectDisable'] && !$this->noRedirect
) {
108 $redirectUrl = $this->processRedirect();
109 if (count($redirectUrl)) {
110 $this->redirectUrl
= $this->conf
['redirectFirstMethod'] ?
array_shift($redirectUrl) : array_pop($redirectUrl);
112 $this->redirectUrl
= '';
118 if ($this->piVars
['forgot']) {
119 $content .= $this->showForgot();
120 } elseif ($this->piVars
['forgothash']) {
121 $content .= $this->changePassword();
123 if($this->userIsLoggedIn
&& !$this->logintype
) {
124 $content .= $this->showLogout();
126 $content .= $this->showLogin();
132 // Process the redirect
133 if (($this->logintype
=== 'login' ||
$this->logintype
=== 'logout') && $this->redirectUrl
&& !$this->noRedirect
) {
134 if (!$GLOBALS['TSFE']->fe_user
->cookieId
) {
135 $content .= '<p style="color:red; font-weight:bold;">' . $this->pi_getLL('cookie_warning', '', 1) . '</p>';
137 t3lib_utility_Http
::redirect($this->redirectUrl
);
140 return $this->conf
['wrapContentInBaseClass'] ?
$this->pi_wrapInBaseClass($content) : $content;
145 * Shows the forgot password form
147 * @return string content
149 protected function showForgot() {
150 $subpart = $this->cObj
->getSubpart($this->template
, '###TEMPLATE_FORGOT###');
151 $subpartArray = $linkpartArray = array();
152 $postData = t3lib_div
::_POST($this->prefixId
);
154 if ($postData['forgot_email']) {
156 // get hashes for compare
157 $postedHash = $postData['forgot_hash'];
158 $hashData = $GLOBALS['TSFE']->fe_user
->getKey('ses', 'forgot_hash');
161 if ($postedHash === $hashData['forgot_hash']) {
164 // look for user record
165 $data = $GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars
['forgot_email'], 'fe_users');
166 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
167 'uid, username, password, email',
169 '(email=' . $data .' OR username=' . $data . ') AND pid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($this->spid
).') '.$this->cObj
->enableFields('fe_users')
172 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
173 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
177 // generate an email with the hashed link
178 $error = $this->generateAndSendHash($row);
182 $markerArray['###STATUS_MESSAGE###'] = $this->cObj
->stdWrap($error, $this->conf
['forgotMessage_stdWrap.']);
184 $markerArray['###STATUS_MESSAGE###'] = $this->cObj
->stdWrap($this->pi_getLL('ll_forgot_reset_message_emailSent', '', 1), $this->conf
['forgotMessage_stdWrap.']);
186 $subpartArray['###FORGOT_FORM###'] = '';
191 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('forgot_reset_message', $this->conf
['forgotMessage_stdWrap.']);
192 $markerArray['###BACKLINK_LOGIN###'] = '';
195 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('forgot_reset_message', $this->conf
['forgotMessage_stdWrap.']);
196 $markerArray['###BACKLINK_LOGIN###'] = '';
199 $markerArray['###BACKLINK_LOGIN###'] = $this->getPageLink($this->pi_getLL('ll_forgot_header_backToLogin', '', 1), array());
200 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('forgot_header', $this->conf
['forgotHeader_stdWrap.']);
202 $markerArray['###LEGEND###'] = $this->pi_getLL('reset_password', '', 1);
203 $markerArray['###ACTION_URI###'] = $this->getPageLink('', array($this->prefixId
. '[forgot]'=>1), true
);
204 $markerArray['###EMAIL_LABEL###'] = $this->pi_getLL('your_email', '', 1);
205 $markerArray['###FORGOT_PASSWORD_ENTEREMAIL###'] = $this->pi_getLL('forgot_password_enterEmail', '', 1);
206 $markerArray['###FORGOT_EMAIL###'] = $this->prefixId
.'[forgot_email]';
207 $markerArray['###SEND_PASSWORD###'] = $this->pi_getLL('reset_password', '', 1);
209 $markerArray['###DATA_LABEL###'] = $this->pi_getLL('ll_enter_your_data', '', 1);
213 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
216 $hash = md5($this->generatePassword(3));
217 $markerArray['###FORGOTHASH###'] = $hash;
218 // set hash in feuser session
219 $GLOBALS['TSFE']->fe_user
->setKey('ses', 'forgot_hash', array('forgot_hash' => $hash));
222 return $this->cObj
->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
226 * This function checks the hash from link and checks the validity. If it's valid it shows the form for
227 * changing the password and process the change of password after submit, if not valid it returns the error message
229 * @return string The content.
231 protected function changePassword() {
233 $subpartArray = $linkpartArray = array();
236 $minLength = intval($this->conf
['newPasswordMinLength']) ?
intval($this->conf
['newPasswordMinLength']) : 6;
238 $subpart = $this->cObj
->getSubpart($this->template
, '###TEMPLATE_CHANGEPASSWORD###');
240 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('change_password_header', $this->conf
['changePasswordHeader_stdWrap.']);
241 $markerArray['###STATUS_MESSAGE###'] = sprintf($this->getDisplayText('change_password_message', $this->conf
['changePasswordMessage_stdWrap.']), $minLength);
243 $markerArray['###BACKLINK_LOGIN###'] = '';
244 $uid = $this->piVars
['user'];
245 $piHash = $this->piVars
['forgothash'];
247 $hash = explode('|', $piHash);
248 if (intval($uid) == 0) {
249 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('change_password_notvalid_message', $this->conf
['changePasswordMessage_stdWrap.']);
250 $subpartArray['###CHANGEPASSWORD_FORM###'] = '';
252 $user = $this->pi_getRecord('fe_users', intval($uid));
253 $userHash = $user['felogin_forgotHash'];
254 $compareHash = explode('|', $userHash);
256 if (!$compareHash ||
!$compareHash[1] ||
$compareHash[0] < time() ||
$hash[0] != $compareHash[0] ||
md5($hash[1]) != $compareHash[1]) {
257 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('change_password_notvalid_message',$this->conf
['changePasswordMessage_stdWrap.']);
258 $subpartArray['###CHANGEPASSWORD_FORM###'] = '';
260 // all is fine, continue with new password
261 $postData = t3lib_div
::_POST($this->prefixId
);
263 if ($postData['changepasswordsubmit']) {
264 if (strlen($postData['password1']) < $minLength) {
265 $markerArray['###STATUS_MESSAGE###'] = sprintf($this->getDisplayText('change_password_tooshort_message', $this->conf
['changePasswordMessage_stdWrap.']), $minLength);
266 } elseif ($postData['password1'] != $postData['password2']) {
267 $markerArray['###STATUS_MESSAGE###'] = sprintf($this->getDisplayText('change_password_notequal_message', $this->conf
['changePasswordMessage_stdWrap.']), $minLength);
269 $newPass = $postData['password1'];
271 if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed']) {
274 'newPassword' => $newPass,
276 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed'] as $_funcRef) {
278 t3lib_div
::callUserFunction($_funcRef, $_params, $this);
281 $newPass = $_params['newPassword'];
284 // save new password and clear DB-hash
285 $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
287 'uid=' . $user['uid'],
288 array('password' => $newPass, 'felogin_forgotHash' => '')
290 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('change_password_done_message', $this->conf
['changePasswordMessage_stdWrap.']);
292 $subpartArray['###CHANGEPASSWORD_FORM###'] = '';
293 $markerArray['###BACKLINK_LOGIN###'] = $this->getPageLink($this->pi_getLL('ll_forgot_header_backToLogin', '', 1), array());
298 // Change password form
299 $markerArray['###ACTION_URI###'] = $this->pi_getPageLink($GLOBALS['TSFE']->id
, '', array(
300 $this->prefixId
. '[user]' => $user['uid'],
301 $this->prefixId
. '[forgothash]' => $piHash
303 $markerArray['###LEGEND###'] = $this->pi_getLL('change_password', '', 1);
304 $markerArray['###NEWPASSWORD1_LABEL###'] = $this->pi_getLL('newpassword_label1', '', 1);
305 $markerArray['###NEWPASSWORD2_LABEL###'] = $this->pi_getLL('newpassword_label2', '', 1);
306 $markerArray['###NEWPASSWORD1###'] = $this->prefixId
. '[password1]';
307 $markerArray['###NEWPASSWORD2###'] = $this->prefixId
. '[password2]';
308 $markerArray['###STORAGE_PID###'] = $this->spid
;
309 $markerArray['###SEND_PASSWORD###'] = $this->pi_getLL('change_password', '', 1);
310 $markerArray['###FORGOTHASH###'] = $piHash;
315 return $this->cObj
->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
319 * generates a hashed link and send it with email
321 * @param array $user contains user data
322 * @return string Empty string with success, error message with no success
324 protected function generateAndSendHash($user) {
325 $hours = intval($this->conf
['forgotLinkHashValidTime']) > 0 ?
intval($this->conf
['forgotLinkHashValidTime']) : 24;
326 $validEnd = time() +
3600 * $hours;
327 $validEndString = date($this->conf
['dateFormat'], $validEnd);
330 $randHash = $validEnd . '|' . $hash;
331 $randHashDB = $validEnd . '|' . md5($hash);
334 $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid=' . $user['uid'], array('felogin_forgotHash' => $randHashDB));
336 // send hashlink to user
337 $this->conf
['linkPrefix'] = -1;
338 $isAbsRelPrefix = !empty($GLOBALS['TSFE']->absRefPrefix
);
339 $isBaseURL = !empty($GLOBALS['TSFE']->baseUrl
);
340 $isFeloginBaseURL = !empty($this->conf
['feloginBaseURL']);
342 if ($isFeloginBaseURL) {
344 $this->conf
['linkPrefix'] = $this->conf
['feloginBaseURL'];
348 $this->conf
['linkPrefix'] = $GLOBALS['TSFE']->baseUrl
;
352 if ($this->conf
['linkPrefix'] == -1 && !$isAbsRelPrefix) {
353 // no preix is set, return the error
354 return $this->pi_getLL('ll_change_password_nolinkprefix_message');
357 $link = ($isAbsRelPrefix ?
'' : $this->conf
['linkPrefix']) . $this->pi_getPageLink($GLOBALS['TSFE']->id
, '', array(
358 $this->prefixId
. '[user]' => $user['uid'],
359 $this->prefixId
. '[forgothash]' => $randHash
362 $msg = sprintf($this->pi_getLL('ll_forgot_validate_reset_password', '', 0), $user['username'], $link, $validEndString);
364 // no RDCT - Links for security reasons
365 $oldSetting = $GLOBALS['TSFE']->config
['config']['notification_email_urlmode'];
366 $GLOBALS['TSFE']->config
['config']['notification_email_urlmode'] = 0;
368 $this->cObj
->sendNotifyEmail($msg, $user['email'], '', $this->conf
['email_from'], $this->conf
['email_fromName'], $this->conf
['replyTo']);
370 $GLOBALS['TSFE']->config
['config']['notification_email_urlmode'] = $oldSetting;
378 * @return string The content.
380 protected function showLogout() {
381 $subpart = $this->cObj
->getSubpart($this->template
, '###TEMPLATE_LOGOUT###');
382 $subpartArray = $linkpartArray = array();
384 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('status_header',$this->conf
['logoutHeader_stdWrap.']);
385 $markerArray['###STATUS_MESSAGE###']=$this->getDisplayText('status_message',$this->conf
['logoutMessage_stdWrap.']);$this->cObj
->stdWrap($this->flexFormValue('message','s_status'),$this->conf
['logoutMessage_stdWrap.']);
387 $markerArray['###LEGEND###'] = $this->pi_getLL('logout', '', 1);
388 $markerArray['###ACTION_URI###'] = $this->getPageLink('',array(),true
);
389 $markerArray['###LOGOUT_LABEL###'] = $this->pi_getLL('logout', '', 1);
390 $markerArray['###NAME###'] = htmlspecialchars($GLOBALS['TSFE']->fe_user
->user
['name']);
391 $markerArray['###STORAGE_PID###'] = $this->spid
;
392 $markerArray['###USERNAME###'] = htmlspecialchars($GLOBALS['TSFE']->fe_user
->user
['username']);
393 $markerArray['###USERNAME_LABEL###'] = $this->pi_getLL('username', '', 1);
394 $markerArray['###NOREDIRECT###'] = $this->noRedirect ?
'1' : '0';
395 $markerArray['###PREFIXID###'] = $this->prefixId
;
396 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
398 if ($this->redirectUrl
) {
399 // use redirectUrl for action tag because of possible access restricted pages
400 $markerArray['###ACTION_URI###'] = htmlspecialchars($this->redirectUrl
);
401 $this->redirectUrl
= '';
403 return $this->cObj
->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
409 * @return string content
411 protected function showLogin() {
412 $subpart = $this->cObj
->getSubpart($this->template
, '###TEMPLATE_LOGIN###');
413 $subpartArray = $linkpartArray = array();
417 $markerArray['###LEGEND###'] = $this->pi_getLL('oLabel_header_welcome', '', 1);
419 if($this->logintype
=== 'login') {
420 if($this->userIsLoggedIn
) {
422 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('success_header',$this->conf
['successHeader_stdWrap.']);
423 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('success_message', $this->conf
['successMessage_stdWrap.']);
424 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
425 $subpartArray['###LOGIN_FORM###'] = '';
427 // Hook for general actions after after login has been confirmed (by Thomas Danzl <thomas@danzl.org>)
428 if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_confirmed']) {
430 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_confirmed'] as $_funcRef) {
432 t3lib_div
::callUserFunction($_funcRef, $_params, $this);
439 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('error_header',$this->conf
['errorHeader_stdWrap.']);
440 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('error_message',$this->conf
['errorMessage_stdWrap.']);
441 $gpRedirectUrl = t3lib_div
::_GP('redirect_url');
444 if($this->logintype
=== 'logout') {
445 // login form after logout
446 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('logout_header',$this->conf
['welcomeHeader_stdWrap.']);
447 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('logout_message',$this->conf
['welcomeMessage_stdWrap.']);
450 $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('welcome_header',$this->conf
['welcomeHeader_stdWrap.']);
451 $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('welcome_message',$this->conf
['welcomeMessage_stdWrap.']);
456 // Hook (used by kb_md5fepw extension by Kraft Bernhard <kraftb@gmx.net>)
457 // This hook allows to call User JS functions.
458 // The methods should also set the required JS functions to get included
461 $onSubmitAr = array();
462 $extraHiddenAr = array();
464 // check for referer redirect method. if present, save referer in form field
465 if (t3lib_div
::inList($this->conf
['redirectMode'], 'referer') || t3lib_div
::inList($this->conf
['redirectMode'], 'refererDomains')) {
466 $referer = $this->referer ?
$this->referer
: t3lib_div
::getIndpEnv('HTTP_REFERER');
468 $extraHiddenAr[] = '<input type="hidden" name="referer" value="' . rawurlencode($referer) . '" />';
472 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['loginFormOnSubmitFuncs'])) {
474 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['loginFormOnSubmitFuncs'] as $funcRef) {
475 list($onSub, $hid) = t3lib_div
::callUserFunction($funcRef, $_params, $this);
476 $onSubmitAr[] = $onSub;
477 $extraHiddenAr[] = $hid;
480 if (count($onSubmitAr)) {
481 $onSubmit = implode('; ', $onSubmitAr).'; return true;';
483 if (count($extraHiddenAr)) {
484 $extraHidden = implode(chr(10), $extraHiddenAr);
487 if (!$gpRedirectUrl && $this->redirectUrl
&& $this->logintype
=== 'login') {
488 $gpRedirectUrl = $this->redirectUrl
;
492 $markerArray['###ACTION_URI###'] = $this->getPageLink('',array(),true
);
493 $markerArray['###EXTRA_HIDDEN###'] = $extraHidden; // used by kb_md5fepw extension...
494 $markerArray['###LEGEND###'] = $this->pi_getLL('login', '', 1);
495 $markerArray['###LOGIN_LABEL###'] = $this->pi_getLL('login', '', 1);
496 $markerArray['###ON_SUBMIT###'] = $onSubmit; // used by kb_md5fepw extension...
497 $markerArray['###PASSWORD_LABEL###'] = $this->pi_getLL('password', '', 1);
498 $markerArray['###STORAGE_PID###'] = $this->spid
;
499 $markerArray['###USERNAME_LABEL###'] = $this->pi_getLL('username', '', 1);
500 $markerArray['###REDIRECT_URL###'] = htmlspecialchars($gpRedirectUrl);
501 $markerArray['###NOREDIRECT###'] = $this->noRedirect ?
'1' : '0';
502 $markerArray['###PREFIXID###'] = $this->prefixId
;
503 $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
505 if ($this->flexFormValue('showForgotPassword','sDEF') ||
$this->conf
['showForgotPasswordLink']) {
506 $linkpartArray['###FORGOT_PASSWORD_LINK###'] = explode('|',$this->getPageLink('|',array($this->prefixId
.'[forgot]'=>1)));
507 $markerArray['###FORGOT_PASSWORD###'] = $this->pi_getLL('ll_forgot_header', '', 1);
509 $subpartArray['###FORGOTP_VALID###'] = '';
513 // Permanent Login is only possible if permalogin is not deactivated (-1) and lifetime is greater than 0
514 if ($this->conf
['showPermaLogin'] && t3lib_div
::inList('0,1,2', $GLOBALS['TYPO3_CONF_VARS']['FE']['permalogin']) && $GLOBALS['TYPO3_CONF_VARS']['FE']['lifetime'] > 0) {
515 $markerArray['###PERMALOGIN###'] = $this->pi_getLL('permalogin', '', 1);
516 if($GLOBALS['TYPO3_CONF_VARS']['FE']['permalogin'] == 1) {
517 $markerArray['###PERMALOGIN_HIDDENFIELD_ATTRIBUTES###'] = 'disabled="disabled"';
518 $markerArray['###PERMALOGIN_CHECKBOX_ATTRIBUTES###'] = 'checked="checked"';
520 $markerArray['###PERMALOGIN_HIDDENFIELD_ATTRIBUTES###'] = '';
521 $markerArray['###PERMALOGIN_CHECKBOX_ATTRIBUTES###'] = '';
524 $subpartArray['###PERMALOGIN_VALID###'] = '';
526 return $this->cObj
->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
530 * Process redirect methods. The function searches for a redirect url using all configured methods.
532 * @return string redirect url
534 protected function processRedirect() {
535 $redirect_url = array();
536 if ($this->conf
['redirectMode']) {
537 $redirectMethods = t3lib_div
::trimExplode(',', $this->conf
['redirectMode'], TRUE
);
538 foreach ($redirectMethods as $redirMethod) {
539 if ($GLOBALS['TSFE']->loginUser
&& $this->logintype
=== 'login') {
540 // logintype is needed because the login-page wouldn't be accessible anymore after a login (would always redirect)
541 switch ($redirMethod) {
542 case 'groupLogin': // taken from dkd_redirect_at_login written by Ingmar Schlecht; database-field changed
543 $groupData = $GLOBALS['TSFE']->fe_user
->groupData
;
544 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
545 'felogin_redirectPid',
546 $GLOBALS['TSFE']->fe_user
->usergroup_table
,
547 'felogin_redirectPid!="" AND uid IN (' . implode(',', $groupData['uid']) . ')'
549 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
550 $redirect_url[] = $this->pi_getPageLink($row[0], array(), TRUE
); // take the first group with a redirect page
554 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
555 'felogin_redirectPid',
556 $GLOBALS['TSFE']->fe_user
->user_table
,
557 $GLOBALS['TSFE']->fe_user
->userid_column
. '=' . $GLOBALS['TSFE']->fe_user
->user
['uid'] . ' AND felogin_redirectPid!=""'
559 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
560 $redirect_url[] = $this->pi_getPageLink($row[0], array(), TRUE
);
564 if ($this->conf
['redirectPageLogin']) {
565 $redirect_url[] = $this->pi_getPageLink(intval($this->conf
['redirectPageLogin']), array(), TRUE
);
569 $redirect_url[] = $this->redirectUrl
;
572 // avoid forced logout, when trying to login immediatly after a logout
573 $redirect_url[] = preg_replace('/[&?]logintype=[a-z]+/', '', $this->referer
);
575 case 'refererDomains':
577 // Feature to redirect to the page where the user came from (HTTP_REFERER).
578 // Allowed domains to redirect to, can be configured with plugin.tx_felogin_pi1.domains
579 // Thanks to plan2.net / Martin Kutschker for implementing this feature.
580 if ($this->conf
['domains']) {
581 $url = $this->referer
;
582 // is referring url allowed to redirect?
584 if (preg_match('/^http://([[:alnum:]._-]+)//', $url, $match)) {
585 $redirect_domain = $match[1];
587 foreach(split(',', $this->conf
['domains']) as $d) {
588 if (preg_match('/(^|\.)/'.$d.'$', $redirect_domain)) {
598 // Avoid forced logout, when trying to login immediatly after a logout
600 $redirect_url[] = preg_replace('/[&?]logintype=[a-z]+/', '', $url);
605 } else if ($this->logintype
=== 'login') { // after login-error
606 switch ($redirMethod) {
608 if ($this->conf
['redirectPageLoginError']) {
609 $redirect_url[] = $this->pi_getPageLink(intval($this->conf
['redirectPageLoginError']), array(), TRUE
);
613 } elseif (($this->logintype
== '') && ($redirMethod == 'login') && $this->conf
['redirectPageLogin']) {
614 // if login and page not accessible
615 $this->cObj
->typolink('', array(
616 'parameter' => $this->conf
['redirectPageLogin'],
617 'linkAccessRestrictedPages' => TRUE
,
619 $redirect_url[] = $this->cObj
->lastTypoLinkUrl
;
621 } elseif (($this->logintype
== '') && ($redirMethod == 'logout') && $this->conf
['redirectPageLogout'] && $GLOBALS['TSFE']->loginUser
) {
622 // if logout and page not accessible
623 $redirect_url[] = $this->pi_getPageLink(intval($this->conf
['redirectPageLogout']), array(), TRUE
);
625 } elseif ($this->logintype
=== 'logout') { // after logout
627 // Hook for general actions after after logout has been confirmed
628 if ($this->logintype
=== 'logout' && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['logout_confirmed']) {
630 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['logout_confirmed'] as $_funcRef) {
632 t3lib_div
::callUserFunction($_funcRef, $_params, $this);
637 switch ($redirMethod) {
639 if ($this->conf
['redirectPageLogout']) {
640 $redirect_url[] = $this->pi_getPageLink(intval($this->conf
['redirectPageLogout']), array(), TRUE
);
644 } else { // not logged in
645 // Placeholder for maybe future options
646 switch ($redirMethod) {
648 // preserve the get/post value
649 $redirect_url[] = $this->redirectUrl
;
656 // remove empty values
657 if (count($redirect_url)) {
658 return t3lib_div
::trimExplode(',', implode(',', $redirect_url), TRUE
);
665 * Reads flexform configuration and merge it with $this->conf
669 protected function mergeflexFormValuesIntoConf() {
671 if ($this->flexFormValue('showForgotPassword', 'sDEF')) {
672 $flex['showForgotPassword'] = $this->flexFormValue('showForgotPassword','sDEF');
675 if ($this->flexFormValue('showPermaLogin', 'sDEF')) {
676 $flex['showPermaLogin'] = $this->flexFormValue('showPermaLogin', 'sDEF');
679 if ($this->flexFormValue('pages', 'sDEF')) {
680 $flex['pages'] = $this->flexFormValue('pages', 'sDEF');
683 if ($this->flexFormValue('recursive', 'sDEF')) {
684 $flex['recursive'] = $this->flexFormValue('recursive', 'sDEF');
687 if ($this->flexFormValue('templateFile', 'sDEF')) {
688 $flex['templateFile'] = $this->uploadDir
. $this->flexFormValue('templateFile', 'sDEF');
691 if ($this->flexFormValue('redirectMode', 's_redirect')) {
692 $flex['redirectMode'] = $this->flexFormValue('redirectMode', 's_redirect');
695 if ($this->flexFormValue('redirectFirstMethod', 's_redirect')) {
696 $flex['redirectFirstMethod'] = $this->flexFormValue('redirectFirstMethod', 's_redirect');
699 if ($this->flexFormValue('redirectDisable', 's_redirect')) {
700 $flex['redirectDisable'] = $this->flexFormValue('redirectDisable', 's_redirect');
703 if ($this->flexFormValue('redirectPageLogin', 's_redirect')) {
704 $flex['redirectPageLogin'] = $this->flexFormValue('redirectPageLogin', 's_redirect');
707 if ($this->flexFormValue('redirectPageLoginError', 's_redirect')) {
708 $flex['redirectPageLoginError'] = $this->flexFormValue('redirectPageLoginError','s_redirect');
711 if ($this->flexFormValue('redirectPageLogout', 's_redirect')) {
712 $flex['redirectPageLogout'] = $this->flexFormValue('redirectPageLogout', 's_redirect');
715 $pid = $flex['pages'] ?
$this->pi_getPidList($flex['pages'], $flex['recursive']) : 0;
717 $flex['storagePid'] = $pid;
720 $this->conf
= array_merge($this->conf
, $flex);
724 * Loads a variable from the flexform
726 * @param string name of variable
727 * @param string name of sheet
728 * @return string value of var
730 protected function flexFormValue($var, $sheet) {
731 return $this->pi_getFFvalue($this->cObj
->data
['pi_flexform'], $var,$sheet);
735 * Generate link with typolink function
737 * @param string linktext
738 * @param array link vars
739 * @param boolean true: returns only url false (default) returns the link)
741 * @return string link or url
743 protected function getPageLink($label, $piVars,$returnUrl = false
) {
744 $additionalParams = '';
746 if (count($piVars)) {
747 foreach($piVars as $key=>$val) {
748 $additionalParams .= '&' . $key . '=' . $val;
751 // should GETvars be preserved?
752 if ($this->conf
['preserveGETvars']) {
753 $additionalParams .= $this->getPreserveGetVars();
756 $this->conf
['linkConfig.']['parameter'] = $GLOBALS['TSFE']->id
;
757 if ($additionalParams) {
758 $this->conf
['linkConfig.']['additionalParams'] = $additionalParams;
762 return htmlspecialchars($this->cObj
->typolink_url($this->conf
['linkConfig.']));
764 return $this->cObj
->typolink($label,$this->conf
['linkConfig.']);
769 * Is used by TS-setting preserveGETvars
770 * possible values are "all" or a commaseperated list of GET-vars
771 * they are used as additionalParams for link generation
773 * @return string additionalParams-string
775 protected function getPreserveGetVars() {
778 $preserveVars =! ($this->conf
['preserveGETvars'] ||
$this->conf
['preserveGETvars']=='all' ?
array() : implode(',', (array)$this->conf
['preserveGETvars']));
779 $getVars = t3lib_div
::_GET();
781 foreach ($getVars as $key => $val) {
782 if (stristr($key,$this->prefixId
) === false
) {
783 if (is_array($val)) {
784 foreach ($val as $key1 => $val1) {
785 if ($this->conf
['preserveGETvars'] == 'all' ||
in_array($key . '[' . $key1 .']', $preserveVars)) {
786 $params .= '&' . $key . '[' . $key1 . ']=' . $val1;
790 if (!in_array($key, array('id','no_cache','logintype','redirect_url','cHash'))) {
791 $params .= '&' . $key . '=' . $val;
800 * Is used by forgot password - function with md5 option.
802 * @author Bernhard Kraft
804 * @param int length of new password
805 * @return string new password
807 protected function generatePassword($len) {
814 $pass .= chr($char - 10 +
97);
821 * Returns the header / message value from flexform if present, else from locallang.xml
823 * @param string label name
824 * @param string TS stdWrap array
825 * @return string label text
827 protected function getDisplayText($label, $stdWrapArray=array()) {
828 $text = $this->flexFormValue($label, 's_messages') ?
$this->cObj
->stdWrap($this->flexFormValue($label, 's_messages'), $stdWrapArray) : $this->cObj
->stdWrap($this->pi_getLL('ll_'.$label, '', 1), $stdWrapArray);
829 $replace = $this->getUserFieldMarkers();
830 return strtr($text, $replace);
834 * Returns Array of markers filled with user fields
836 * @return array marker array
838 protected function getUserFieldMarkers() {
840 // replace markers with fe_user data
841 if ($GLOBALS['TSFE']->fe_user
->user
) {
842 // all fields of fe_user will be replaced, scheme is ###FEUSER_FIELDNAME###
843 foreach ($GLOBALS['TSFE']->fe_user
->user
as $field => $value) {
844 $marker['###FEUSER_' . t3lib_div
::strtoupper($field) . '###'] = $this->cObj
->stdWrap($value, $this->conf
['userfields.'][$field . '.']);
846 // add ###USER### for compatibility
847 $marker['###USER###'] = $marker['###FEUSER_USERNAME###'];
855 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/felogin/pi1/class.tx_felogin_pi1.php']) {
856 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/felogin/pi1/class.tx_felogin_pi1.php']);