For instance, here is my registration action. After a successful registration, it triggers the "Register" event. The problem is, the SystemEmails plugin needs to have the user's information, which at present, isn't possible.
Code: Select all
/**
* Register Action
*/
public function registerAction() {
$post = array();
$errors = array();
if ($this->isPost()) {
$post = $this->getPost();
$rules = with($this->usrTab->getRules())
->add(new ImpSoft_Rule_FieldAvailable(array('table' => $this->usrTab, 'column' => 'username')), 'username', 'Sorry, that username is already taken')
->add(new ImpSoft_Rule_FieldAvailable(array('table' => $this->usrTab, 'column' => 'email')), 'email', 'Sorry, that e-mail is already taken. Perhaps you already have an account?');
if ($rules->validate($post)) {
try {
$this->usrTab->registerMember(array(
'username' => $post['username'],
'password' => $post['password'],
'email' => $post['email'],
'role' => 'member',
'is_active' => 0
));
$this->getPluginManager()->trigger('Register');
$this->flash('Thank you for signing up! We have sent you an e-mail with an activation link. Once you click that link, your account will be active.');
$this->goToRoute('home');
} catch (Zend_Db_Exception $e) {
// cannot create the user at this time... bummer!
$this->flash('Sorry, we can not allow you to register at this time.');
$this->goToRoute('register');
}
} else {
$errors = $rules->getErrors();
}
}
$this->view->post = $post;
$this->view->errors = $errors;
}Code: Select all
<?php
class ImpSoft_Plugin_SystemEmails extends ImpSoft_Plugin_Abstract {
/**
* @var $swift Swift object
*/
protected $swift;
protected $from;
public function __construct(Swift $swift, $from) {
$this->from = $from;
$this->swift = $swift;
}
public function onRegister() {
$message = new Swift_Message("Welcome!", "Welcome to the Is It Legit wonderness. Good luck.");
$recipient = ""; // this is the contextual information I need...
if ($this->swift->send($message, $this->from, $recipient));
}
}