/** * Confirms an e-mail, if the user must change thier password then changes it */ public function confirmEmailAction() { $code = $this->dispatcher->getParam('code'); /** @var \Talon\Models\Users\EmailConfirmations $confirmation */ $confirmation = EmailConfirmations::findFirstByCode($code); if (!$confirmation) { return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index')); } if ($confirmation->confirmed !== 0) { return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'login')); } $confirmation->confirmed = 1; $confirmation->user->active = 1; $confirmation->user->validated = 1; /** * Change the confirmation to 'confirmed' and update the user to 'active' */ if (!$confirmation->save()) { foreach ($confirmation->getMessages() as $message) { $this->flashSession->error($message); } return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index')); } $this->flashSession->success('The email was successfully confirmed. Please login.'); return $this->redirect('session', 'login'); }
/** * Before create the user assign a password */ public function beforeValidationOnCreate() { // Timestamp the confirmation $this->created = new RawValue('now()'); // Generate a random confirmation code $this->code = preg_replace('/[^a-zA-Z0-9]/', '', base64_encode(openssl_random_pseudo_bytes(24))); // Set status to non-confirmed $this->confirmed = 0; echo $this->usersId; // disable all other email confirmations $emailConfirmations = EmailConfirmations::find(array('usersId = ?1', 'bind' => array(1 => $this->usersId))); /** @var EmailConfirmations $emailConfirmation */ foreach ($emailConfirmations as $emailConfirmation) { $emailConfirmation->delete(); } }
public function sendConfirmation() { $emailConfirmation = new EmailConfirmations(); $emailConfirmation->usersId = $this->id; if (!$emailConfirmation->save()) { foreach ($emailConfirmation->getMessages() as $message) { $this->appendMessage($message); } return false; } return true; }