Is there a built in way to tell if a customer has created a password ?
No. There is no built in way to find this. The best approach would to log such an information in my opinion is:
- Create an attribute for customer, let's say
is_customer_reset_password
.
- Update this attribute value to 1 in customer reset password post action.
Is there a built in way to tell if a customer has never logged in ?
Again answer is no. But Magento provides an easy work around for this. For this, you can use below helper method:
/**
* Use to check whether a customer logged in website ever !
*
* @param Mage_Customer_Model_Customer $customer
* @return boolean
*/
public function hasCustomerEverLoggedIn(Mage_Customer_Model_Customer $customer)
{
$customerLog = Mage::getModel('log/customer')
->loadByCustomer($customer->getId());
$date = $customerLog->getLoginAtTimestamp();
if ($date) {
return true;
}
return false;
}
Now pass your customer model to this helper method and you can easily find it out.
You can also find last login date of customer like this.
/**
* Use to check whether a customer logged in website ever !
*
* @param Mage_Customer_Model_Customer $customer
* @return mixed
*/
public function getLastLoginDate(Mage_Customer_Model_Customer $customer)
{
$customerLog = Mage::getModel('log/customer')
->loadByCustomer($customer->getId());
$date = $customerLog->getLoginAtTimestamp();
if ($date) {
return Mage::helper('core')->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
}
return Mage::helper('customer')->__('Never');
}
In both these examples, we are using Mage_Log
module which actually logs customer activities. So having a look into this core module might help you.
[This answer is a part of #mageStackDay5. It is an event conducted by Magento Community members as part of increasing the question-answer ratio. For more information http://www.magestackday.com/]