_validateResetPasswordLinkToken
in the Account Controller:
$customerToken = $customer->getRpToken();
if (strcmp($customerToken, $resetPasswordLinkToken) != 0 || $customer->isResetPasswordLinkTokenExpired()) {
throw Mage::exception('Mage_Core', $this->_getHelper('customer')->__('Your password reset link has expired.'));
}
Which in turn calls: isResetPasswordLinkTokenExpired
/**
* Check if current reset password link token is expired
*
* @return boolean
*/
public function isResetPasswordLinkTokenExpired()
{
$resetPasswordLinkToken = $this->getRpToken();
$resetPasswordLinkTokenCreatedAt = $this->getRpTokenCreatedAt();
if (empty($resetPasswordLinkToken) || empty($resetPasswordLinkTokenCreatedAt)) {
return true;
}
$tokenExpirationPeriod = Mage::helper('customer')->getResetPasswordLinkExpirationPeriod();
$currentDate = Varien_Date::now();
$currentTimestamp = Varien_Date::toTimestamp($currentDate);
$tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt);
if ($tokenTimestamp > $currentTimestamp) {
return true;
}
$dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
if ($dayDifference >= $tokenExpirationPeriod) {
return true;
}
return false;
}
SUGGESTIONS
Double check server time and Magento time zones.
It may be wise to batch the old plaintext passwords and update them to a more standard Magento password to be safest as well.
EDIT
Instead of reinventing the wheel a quick google search turned up a possible candidate to reset the passwords. Source: http://www.christopherhogan.com/2012/02/01/script-to-reset-all-customer-passwords-in-magento/
<?php
/************************
* / '_ __/_ _/_
* ()()/(-( /( ()(/(-
* _/
* since 2007
*
* Created by Foundco
* All rights reserved unless otherwise specified under contract.
* http://www.foundco.com/
* @author Christopher Hogan <mailing address removed>
* @copyright 2012 and beyond.
******************************/
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
if (!file_exists($mageFilename)) {
echo $mageFilename." was not found";
exit;
}
require_once $mageFilename;
Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app();
$passwordLength = 10;
/****
If you are just resetting one customer by customer_id:
****/
//$customer_id = 10;
//$customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('entity_id', array('eq' => $customer_id));
/****
If you are resetting all customers:
****/
$customer_id = 10;
$customers = Mage::getModel('customer/customer')->getCollection();
/****
Now loop through the customers and create the passwords
****/
foreach ($customers as $customer){
// $customer->generatePassword($passwordLength)
// $customer->sendNewAccountEmail();
$password = strtoupper(substr( $customer->getEmail(), 0, 3)).rand(111,999);
$customer->setPassword($password)->save();
$line_data = $customer->getEmail(). "\t". $customer->getPassword();
$line[] = $line_data;
echo $line_data."\n";
}
$content = implode("\n", $line);
// store all the passwords to a file:
file_put_contents('./accounts.csv', $content);
echo "COMPLETE!";
?>
Try this
Step1: trigger an event on basic of customer_save_before
<global>
<events>
<customer_save_before>
<observers>
<stockalert>
<type>singleton</type>
<class>magento37890/observer</class>
<method>checkDisplay</method>
</stockalert>
</observers>
</customer_save_before>
</events>
</global>
Step2:
In before event
give you can get customer id
if customer is old
,then checking current value and past value match or not
.
If not match then checking this value exit in Rest of collection
. If exit then send a flag (false)
and
throw error using throw Mage::exception
which prevent data save
.....
if($flagofmy==false){
throw Mage::exception(
'Mage_Customer', Mage::helper('customer')->__('This customer lastname already exists'),
Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
);
}
full Logic
<?php
class Stackexchange_Magento37890_Model_Observer
{
public function checkDisplay(Varien_Event_Observer $observer){
$flagofmy=true;
//eeeeee
$customer=$observer->getEvent()->getCustomer();
Mage::log('My log entry'.$customer->getId(), null, 'Magento37890.log');
/* if customer is old customer */
if($customer->getId()){
if($customer->getOrigData('lastname')!=$customer->getData('lastname')){
Mage::log($customer->getData('lastname').'My log entry'.$customer->getId(), null, 'Magento37890.log');
$flagofmy=$this->HasLastName($customer->getData('lastname'));
if($flagofmy==false){
throw Mage::exception(
'Mage_Customer', Mage::helper('customer')->__('This customer lastname already exists'),
Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
);
}
}else{
Mage::log($customer->getData('lastname').' Step A _1'.$customer->getId(), null, 'Magento37890.log');
}
}else{
/* New Customer */
$flagofmy=$this->NewHasLastName($customer->getData('lastname'));
throw Mage::exception(
'Mage_Customer', Mage::helper('customer')->__('This customer lastname already exists'),
Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
);
}
}
protected function HasLastName($lastname){
$customer_check = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('lastname')
->addAttributeToFilter('lastname',$lastname);
if(count($customer_check)>0){
return false;
}
return true;
}
}
Note: I have done basic of lastname field juts need to change field name to display_name
Best Answer
Thanks to Fabian Blechschmidt, I came up with the following that works for me (using the event
customer_save_before
):