template() if you pass an Email * instance * * @return array email send result */ protected function _sendEmail(EntityInterface $user, $subject, Email $email = null) { $firstName = isset($user['first_name'])? $user['first_name'] . ', ' : ''; $emailInstance = $this->_getEmailInstance($email) ->to($user['email']) ->subject($firstName . $subject) ->viewVars($user->toArray()); if (empty($email)) { $emailInstance->template('CakeDC/Users.validation'); } return $emailInstance->send(); } /** * Get or initialize the email instance. Used for mocking. * * @param Email $email if email provided, we'll use the instance instead of creating a new one * @return Email */ protected function _getEmailInstance(Email $email = null) { if ($email === null) { $email = new Email('default'); $email->emailFormat('both'); } return $email; } /** * DRY for update active and token based on validateEmail flag * * @param EntityInterface $user User to be updated. * @param type $validateEmail email user to validate. * @param type $tokenExpiration token to be updated. * @return EntityInterface */ protected function _updateActive(EntityInterface $user, $validateEmail, $tokenExpiration) { $emailValidated = $user['validated']; if (!$emailValidated && $validateEmail) { $user['active'] = false; $user->updateToken($tokenExpiration); } else { $user['active'] = true; $user['activation_date'] = new Time(); } return $user; } /** * Remove user token for validation * * @param User $user user object. * @return EntityInterface */ protected function _removeValidationToken(EntityInterface $user) { $user->token = null; $user->token_expires = null; $result = $this->_table->save($user); return $result; } }