How to create forgot password link in typo3


 
Create custom forgot password link in typo3. for that you have to simply add below code in your file.

Following code should do the trick.

$user['uid'] = $GLOBALS['TSFE']->fe_user->user['uid'];

$hours = intval($this->conf['forgotLinkHashValidTime']) > 0 ? intval($this->conf['forgotLinkHashValidTime']) : 24;
$validEnd = time() + 3600 * $hours;
$validEndString = date($this->conf['dateFormat'], $validEnd);
$hash = md5(GeneralUtility::generateRandomBytes(64));
$randHash = $validEnd . '|' . $hash;
$randHashDB = $validEnd . '|' . md5($hash);

// Write hash to DB
$res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid=' . $user['uid'], array('felogin_forgotHash' => $randHashDB));

// Create hashlink to user
$this->conf['linkPrefix'] = -1;
$isAbsRelPrefix = !empty($GLOBALS['TSFE']->absRefPrefix);
$isBaseURL = !empty($GLOBALS['TSFE']->baseUrl);
$isFeloginBaseURL = !empty($this->conf['feloginBaseURL']);


$configurations['additionalParams'] = '&tx_felogin_pi1[user]='.$user['uid'].'&tx_felogin_pi1[forgothash]='.$randHash;
$configurations['returnLast'] = 'url'; // get it as URL
$configurations['parameter'] = $GLOBALS['TSFE']->id;
$link = $this->cObject->typolink(NULL, $configurations);


// Prefix link if necessary
if ($isFeloginBaseURL) {
	// First priority, use specific base URL
	// "absRefPrefix" must be removed first, otherwise URL will be prepended twice
	if (!empty($GLOBALS['TSFE']->absRefPrefix)) {
		$link = substr($link, strlen($GLOBALS['TSFE']->absRefPrefix));
	}
	$link = $this->conf['feloginBaseURL'] . $link;
} elseif ($isAbsRelPrefix) {
	// Second priority
	// absRefPrefix must not necessarily contain a hostname and URL scheme, so add it if needed
	$link = GeneralUtility::locationHeaderUrl($link);
} elseif ($isBaseURL) {
	// Third priority
	// Add the global base URL to the link
	$link = $GLOBALS['TSFE']->baseUrlWrap($link);
} else {
	// No prefix is set, return the error
	return "Error: there is no prefix for the link. Please set one of the following in your typoscript template: plugin.tx_felogin_pi1.feloginBaseURL = http://yourdomain/, config.baseURL = http://yourdomain/, config.absRelPrefix = http://yourdomain/";
}

Note : $user['uid'] : this will be user id of user.

You will get forgot password link in “$link”.

I hope it will work for you. 🙂

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s