Gc\User\Model::sendForgotPasswordEmail PHP Method

sendForgotPasswordEmail() public method

Send new password
public sendForgotPasswordEmail ( string $email ) : boolean
$email string Email address
return boolean
    public function sendForgotPasswordEmail($email)
    {
        $row = $this->fetchRow($this->select(array('email' => $email)));
        if (!empty($row)) {
            $user = self::fromArray((array) $row);
            $passwordKey = sha1(uniqid());
            $user->setRetrievePasswordKey($passwordKey);
            $user->setRetrieveUpdatedAt(new Expression('NOW()'));
            $user->save();
            $serviceManager = Registry::get('Application')->getServiceManager();
            $message = $serviceManager->get('MvcTranslator')->translate('To reset your password follow this link but be careful ' . 'you only have one hour before the link expires:');
            $message .= '<br>';
            $message .= Registry::get('Application')->getMvcEvent()->getRouter()->assemble(array('id' => $user->getId(), 'key' => $passwordKey), array('force_canonical' => true, 'name' => 'config/user/forgot-password-key'));
            $mail = new Mail('utf-8', $message, $serviceManager->get('CoreConfig')->getValue('mail_from'), $user->getEmail());
            $mail->send();
            return true;
        }
        return false;
    }

Usage Example

示例#1
0
 /**
  * Test
  *
  * @return void
  */
 public function testSendForgotPasswordWithEmail()
 {
     $this->assertTrue($this->object->sendForgotPasswordEmail('*****@*****.**'));
 }
All Usage Examples Of Gc\User\Model::sendForgotPasswordEmail