// get userid, resetkey, and set to expire in 1 day $user = $users->getFirst(); $userid = $user->get('userid'); $resetkey = randomID(); $expire = date('Y-m-d H:i:s', time() + 86400); // create an entry in the password reset table $reset = Model_UserReset::Create(); $reset->set('userid', $userid); $reset->set('resetkey', $resetkey); $reset->set('expire', $expire); $reset->save(); // construct e-mail body $mm = new Pagemill($pm->root()->fork()); $mm->setVariable('username', $user->get('username')); $mm->setVariable('reseturl', sprintf('http://%s%s/password?userid=%d&resetkey=%s', $_SERVER['HTTP_HOST'], TYPEF_WEB_DIR, $userid, $resetkey)); $body = str_replace('&', '&', $mm->writeString('<pm:include template="/users/reset.eml" />', true)); // e-mail the user so they can reset their password $mailer = new Mailer(); $mailer->Configure(); $mailer->IsHTML(true); $mailer->AddAddress($_POST['email']); $mailer->Subject = 'Request to Reset Password for ' . TYPEF_TITLE; $mailer->Body = $body; $mailer->Send(); $pm->setVariable('reset_email_sent', true); Typeframe::Log('Request to reset password for ' . $_POST['email']); } else { $pm->setVariable('reset_email_failed', true); } } // set template (controller is at root, but template lives in users directory
public function output(Pagemill_Data $data, Pagemill_Stream $stream, $content = null) { if (!$this->insidePlugin()) { $content = self::Cache(); $name = $this->getAttribute('name'); $type = $this->getAttribute('type'); if ($type == 'html') { // Parse short URL attributes $urled = @$content[$name]; $urled = preg_replace('/(<[^>]*? href=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); $urled = preg_replace('/(<[^>]*? src=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); @($content[$name] = $urled); } if ($type == 'model') { if (!empty($content[$name])) { $model = $content[$name]; if ((string) $model != '') { $model = explode(':', $model); if (class_exists($model[0])) { $record = $model[0]::Get($model[1]); $content[$name] = $record; } } } else { $content[$name] = null; } } if ($this->getAttribute('scope') == 'global') { Typeframe::Pagemill()->set($name, @$content[$name]); } else { $data->set($name, @$content[$name]); } } //$inner = $this->inner($data); if (count($this->children()) > 0) { foreach ($this->children() as $child) { $child->process($data, $stream); } } else { $output = ''; if ($this->getAttribute('noop')) { $output = ''; } else { if ($type == 'html') { $pm = new Pagemill($data); $output = $pm->writeString('<pm:codeblock elements="*" attributes="*">@{' . $name . '}@</pm:codeblock>', true); } else { if ($type == 'image') { // Only display something if something is filled in, ie: no broken images. if (@$content[$name] && is_readable(TYPEF_DIR . '/files/public/content/' . @$content[$name])) { // Allow any other attribute to transparently pass to the image. $atts = ''; foreach ($this->attributes() as $k => $v) { switch ($k) { case 'name': case 'label': case 'type': case 'src': break; default: $atts .= " {$k}=\"{$v}\""; } } $output = '<img src="' . TYPEF_WEB_DIR . '/files/public/content/' . $content[$name] . '"' . $atts . '/>'; } else { $output = ''; } } else { if ($type == 'link') { if (!$content[$name] && @$this->getAttribute('ignoreblank') == true) { return ''; } $linktitle = @$this->getAttribute('linktitle') ? $this->getAttribute('linktitle') : 'Click Here'; $linkstyle = @$this->getAttribute('linkstyle') ? $this->getAttribute('linkstyle') : ''; $output = '<a href="' . $content[$name] . '" style="' . $linkstyle . '">' . $linktitle . '</a>'; } else { if ($type == 'checkbox' || $type == 'select') { // Checkbox and select types are primarily for configurable template logic and do not have default output. $output = ''; } else { $output = $content[$name]; } } } } } $stream->puts($output); } }
} } } if (count($sendTo)) { $replyTo = array(); if ($mailform['replyto']) { foreach ($submission as $field) { if ($field['type'] == 'email') { $replyTo[] = $field['value']; } } } $mm = new Pagemill(); $mm->setVariable('submission', $submission); $mm->setVariable('referrer', $log['referrer']); $body = $mm->writeString('<pm:include template="/mailform/submission.eml" />', true); $mail = new Mailer(); $mail->Configure(); $mail->IsHTML(true); foreach ($sendTo as $s) { $mail->AddAddress($s['email'], $s['name']); } foreach ($replyTo as $r) { $mail->AddReplyTo($r); } $attachmentSize = 0; foreach ($submission as $field) { if ($field['type'] == 'file' || $field['type'] == 'image') { $fullname = TYPEF_DIR . '/files/public/mailform/' . $field['value']; $attachmentSize += filesize($fullname); if ($attachmentSize <= MAILFORM_MAX_ATTACHMENT_SIZE) {
$pm->setVariable('typef_require_confirmation', true); // get userid, confirmkey, and set to expire in 3 days $userid = $user->get('userid'); $confirmkey = randomID(); $expire = date('Y-m-d H:i:s', time() + 259200); // create an entry in the user confirmation table $user_confirm = Model_UserConfirm::Create(); $user_confirm->set('confirmkey', $confirmkey); $user_confirm->set('userid', $userid); $user_confirm->set('expire', $expire); $user_confirm->save(); // construct e-mail body $mm = new Pagemill($pm->root()->fork()); $mm->setVariable('username', $user->get('username')); $mm->setVariable('confirmurl', sprintf('http://%s%s/confirm?userid=%d&confirmkey=%s', $_SERVER['HTTP_HOST'], TYPEF_WEB_DIR, $userid, $confirmkey)); $body = str_replace('&', '&', $mm->writeString('<pm:include template="/users/register/confirmation.eml" />', true)); // e-mail the user so they can confirm their registration $mailer = new Mailer(); $mailer->Configure(); $mailer->IsHTML(true); $mailer->AddAddress($_POST['email']); $mailer->Subject = 'Your Account Confirmation from ' . TYPEF_TITLE; $mailer->Body = $body; $mailer->Send(); } else { // if confirmation is not required, log the user in immediately Typeframe::User()->login($_POST['username'], $_POST['password']); Typeframe::Redirect('Registration complete. Welcome!', TYPEF_WEB_DIR . '/', 1); return; } // registratino is complete